Can Multi Charts store the value(index) of the Current Bar? I am trying to get a sequence of certain events and need to make sure each follows the other and not random.
Thanks.
Saving Current Bar
- TJ
- Posts: 7774
- Joined: Aug 29 2006
- Location: Global Citizen
- Has thanked: 1036 times
- Been thanked: 2233 times
If there is a will, there is a way.
You need to articulate your idea with step-by-step descriptions, flowcharts, diagrams, examples and mock-up illustrations.
You need to articulate your idea with step-by-step descriptions, flowcharts, diagrams, examples and mock-up illustrations.
- TJ
- Posts: 7774
- Joined: Aug 29 2006
- Location: Global Citizen
- Has thanked: 1036 times
- Been thanked: 2233 times
BarNumber is a function
BarNumber (Function)
The BarNumber series function assigns a reference number to each bar after MaxBarsBack is satisfied.
Syntax
BarNumber
Returns (Integer)
A positive numeric reference value for each bar on the chart.
Parameters
None
Remarks
MaxBarsBack is the minimum number of referenced historical bars required at the beginning of a chart to begin calculating trading strategies, analysis techniques, and functions. For example, a 10-bar moving average would require a MaxBarsBack setting of 9 to calculate, which is 9 historical bars and the current bar.
Since BarNumber is based on MaxBarsBack, if there are 500 bars in a chart, with a MaxBarsBack setting of 50, the next bar after the 50th bar on the chart moving left to right, will be BarNumber = 1. The last bar on the chart (most recent) will be BarNumber = 451.
BarNumber is often used to identify a particular bar or number of bars because of some special occurrence or situation that you want to test or factor into your analysis.
The BarNumber function is similar to the reserved word CurrentBar. However, CurrentBar does not allow previous bar references: BarNumber[5](of five bars ago) is correct, however, Currentbar[5] is incorrect and does not work.
Examples
Assigns the BarNumber for each bar to Value1, then plots Value1:
Assigns the BarNumber to Value1 when Condition1 is true, and assigns the number of bars since Condition1 occurred to Value2:Code: Select all
Value1 = BarNumber; Plot1(Value1, "BarNum");
Code: Select all
if Condition1 then Value1 = BarNumber; if BarNumber > Value1 then Value2 = CurrentBar – Value1;[/quote]
Thanks TJ. So is BarNumber the index assigned to bar that just closed or bar that is forming? And signals are calculated on the first tick of a new bar?
So say if I want to save the bar number for Bar[5] if it is highest among the last six bars Bar[0], Bar[1], Bar[2], Bar[3] and Bar[4] then is the following snippet correct?
Will CurrentBar - 5 also work in this case?
Thanks.
So say if I want to save the bar number for Bar[5] if it is highest among the last six bars Bar[0], Bar[1], Bar[2], Bar[3] and Bar[4] then is the following snippet correct?
Code: Select all
Vars: Bar5BarsAgoIndex(0);
Bar5BarsAgoIndex = BarNumber -5;
Thanks.
- TJ
- Posts: 7774
- Joined: Aug 29 2006
- Location: Global Citizen
- Has thanked: 1036 times
- Been thanked: 2233 times
I am not sure.
You can give that a try.
You can give that a try.
Dude you need to read and experiment more before asking.. use the Help & Dictionary sections of the PL Editor and use the online Wiki
To experiment with code use the plot and output window functionality of PL
This code should answer your question though.. ensure it is set to data1 (same as instrument) and 'update on every tick' then use it with playback mode
Yes you can refer to OHLC and dates etc. of other bars using statements like Date[5] or Close [5] etc. Use the output window to check results.
Cheers
OZ
P.S. You can use either 'BarNumber' or 'CurrentBar' to achieve this.. I prefer "CurrentBar" because it has blue writing AKA its a built in function.
To experiment with code use the plot and output window functionality of PL
This code should answer your question though.. ensure it is set to data1 (same as instrument) and 'update on every tick' then use it with playback mode
Yes you can refer to OHLC and dates etc. of other bars using statements like Date[5] or Close [5] etc. Use the output window to check results.
Cheers
OZ
Code: Select all
[ProcessMouseEvents= True]
If MouseClickPrice <> 0 then recalculate;
Vars: NL("");
Value1 = strlen(numtostr(IntPortion(currentbar),0));
Value2= (GetAppInfo(aiHighestDispValue)-GetAppInfo(aiLowestDispValue))/50;
For Value3= 1 to Value1 begin
text_new_bn(currentbar, Low-Value2, NL+ rightstr(leftstr(numtostr(IntPortion(currentbar),0), Value3),1));
NL= NL + NewLine + NewLine;
End;
NL= "";