Saving Current Bar

Questions about MultiCharts and user contributed studies.
Eric1704
Posts: 38
Joined: Nov 29 2022
Has thanked: 16 times

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.

User avatar
TJ
Posts: 7774
Joined: Aug 29 2006
Location: Global Citizen
Has thanked: 1036 times
Been thanked: 2233 times

Jun 12 2024

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.

Eric1704
Posts: 38
Joined: Nov 29 2022
Has thanked: 16 times

Jun 12 2024

There is no description here to save the CurrentBar index value. Does MultiCharts save the bar numbers?
Thanks.

User avatar
TJ
Posts: 7774
Joined: Aug 29 2006
Location: Global Citizen
Has thanked: 1036 times
Been thanked: 2233 times

Jun 12 2024

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:

Code: Select all

Value1 = BarNumber; Plot1(Value1, "BarNum");
Assigns the BarNumber to Value1 when Condition1 is true, and assigns the number of bars since Condition1 occurred to Value2:

Code: Select all

if Condition1 then Value1 = BarNumber; if BarNumber > Value1 then Value2 = CurrentBar – Value1;[/quote]

Eric1704
Posts: 38
Joined: Nov 29 2022
Has thanked: 16 times

Jun 12 2024

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?

Code: Select all

Vars: Bar5BarsAgoIndex(0); Bar5BarsAgoIndex = BarNumber -5;
Will CurrentBar - 5 also work in this case?

Thanks.

User avatar
TJ
Posts: 7774
Joined: Aug 29 2006
Location: Global Citizen
Has thanked: 1036 times
Been thanked: 2233 times

Jun 13 2024

I am not sure.
You can give that a try.

Eric1704
Posts: 38
Joined: Nov 29 2022
Has thanked: 16 times

Jun 13 2024

Thanks TJ. And in MultiCharts Signals are calculated on the first tick of the new bar, correct? So BarNumber-1 will be the index of the bar that just closed?
Thanks.

OZ Trade
Posts: 47
Joined: Nov 08 2013
Has thanked: 11 times
Been thanked: 21 times

Jun 14 2024

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

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= "";
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.

Eric1704
Posts: 38
Joined: Nov 29 2022
Has thanked: 16 times

Jun 15 2024

Is there a Output Window in MC to see values like NT? I learn faster when you explain it better here than in the PL dictionary. Plus am new to MC. So a candle loses nothing while lighting another candle.