Saving Current Bar
Posted: Jun 11 2024
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.
Thanks.
MultiCharts
https://www.multicharts.com/discussion/
https://www.multicharts.com/discussion/viewtopic.php?t=54362
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]
Code: Select all
Vars: Bar5BarsAgoIndex(0);
Bar5BarsAgoIndex = BarNumber -5;
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= "";