Currentbar on Indicator doesnt match currentbar on series  [SOLVED]

Questions about MultiCharts and user contributed studies.
tony95
Posts: 20
Joined: 10 Sep 2012
Has thanked: 4 times
Been thanked: 2 times

Currentbar on Indicator doesnt match currentbar on series

Postby tony95 » 10 Sep 2012

Currentbar on my custom chalkin osc indicator doesn't match currentbar on series. Why don't these numbers match?

Example:

Code: Select all

if LastBarOnChart then
begin
FileDelete(filepath);
FileAppend( filepath , NumToStr(currentbar,0) + "," + NumToStr(Date,0) + "," + NumToStr(time_s,0) );
end;
So, when I check the currentbar from the file then it is about 20 bars behind the series bar when I mouse over it on the chart. Why are these values different and how do I get the currentbar from the series when coding an indicator.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Currentbar on Indicator doesnt match currentbar on serie

Postby TJ » 10 Sep 2012

Currentbar on my custom chalkin osc indicator doesn't match currentbar on series. Why don't these numbers match?

Example:

Code: Select all

if LastBarOnChart then
begin
FileDelete(filepath);
FileAppend( filepath , NumToStr(currentbar,0) + "," + NumToStr(Date,0) + "," + NumToStr(time_s,0) );
end;
So, when I check the currentbar from the file then it is about 20 bars behind the series bar when I mouse over it on the chart. Why are these values different and how do I get the currentbar from the series when coding an indicator.
What is your MultiCharts version?
What is your chart resolution?

tony95
Posts: 20
Joined: 10 Sep 2012
Has thanked: 4 times
Been thanked: 2 times

Re: Currentbar on Indicator doesnt match currentbar on serie

Postby tony95 » 10 Sep 2012

MC64 8.0
100tick
MBT
EURUSD FX

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Currentbar on Indicator doesnt match currentbar on serie

Postby TJ » 10 Sep 2012

What do you mean by "20 bars behind the series bar when I mouse over it on the chart."?

tony95
Posts: 20
Joined: 10 Sep 2012
Has thanked: 4 times
Been thanked: 2 times

Re: Currentbar on Indicator doesnt match currentbar on serie

Postby tony95 » 10 Sep 2012

When you move your mouse over a bar on a chart you will see information about that bar. The barnumber is one of those pieces of information. It should match what was output to the file in my code example. The barnumber in the file is about 20 bars behind the chart, but I expect them to be equal.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Currentbar on Indicator doesnt match currentbar on serie

Postby TJ » 10 Sep 2012

When you move your mouse over a bar on a chart you will see information about that bar. The barnumber is one of those pieces of information. It should match what was output to the file in my code example. The barnumber in the file is about 20 bars behind the chart, but I expect them to be equal.
did you reload the chart or re-apply an indicator (any indicator)?

tony95
Posts: 20
Joined: 10 Sep 2012
Has thanked: 4 times
Been thanked: 2 times

Re: Currentbar on Indicator doesnt match currentbar on serie

Postby tony95 » 10 Sep 2012

Yeah, I know that the plot on the indicator is shorter than the plot on the series. Maybe this has something to do with it?

tony95
Posts: 20
Joined: 10 Sep 2012
Has thanked: 4 times
Been thanked: 2 times

Re: Currentbar on Indicator doesnt match currentbar on serie

Postby tony95 » 10 Sep 2012

Yeah, the plot on the indicator starts 21 bars after the data series. Is there a way to tell the indicator to get the current bar of a specific series or indicator?

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Currentbar on Indicator doesnt match currentbar on serie

Postby TJ » 10 Sep 2012

Yeah, the plot on the indicator starts 21 bars after the data series. Is there a way to tell the indicator to get the current bar of a specific series or indicator?
I am not sure if I understand what you are looking for.

User avatar
TJ
Posts: 7740
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 1033 times
Been thanked: 2221 times

Re: Currentbar on Indicator doesnt match currentbar on serie

Postby TJ » 10 Sep 2012


User avatar
JoshM
Posts: 2195
Joined: 20 May 2011
Location: The Netherlands
Has thanked: 1544 times
Been thanked: 1565 times
Contact:

Re: Currentbar on Indicator doesnt match currentbar on serie  [SOLVED]

Postby JoshM » 13 Sep 2012

When you move your mouse over a bar on a chart you will see information about that bar. The barnumber is one of those pieces of information. It should match what was output to the file in my code example. The barnumber in the file is about 20 bars behind the chart, but I expect them to be equal.
The CurrentBar PowerLanguage reserved word used in an indicator or signal starts counting after the MaxBarsBack amount of bars have passed. In other words, if you have the MaxBarsBack set to 20, the indicator starts calculating on chart bar number 21, but this will be the first bar for the indicator (so CurrentBar = 1).

If I recall correctly:

Code: Select all

Bar number of chart = MaxBarsBack + CurrentBar - 1

cnbiz850
Posts: 33
Joined: 15 Oct 2012
Has thanked: 1 time
Been thanked: 1 time

Re: Currentbar on Indicator doesnt match currentbar on serie

Postby cnbiz850 » 06 Nov 2012

If I recall correctly:

Code: Select all

Bar number of chart = MaxBarsBack + CurrentBar - 1
Version 7.4 has this problem, too. This makes the code and the chart not to match each other and makes debugging much harder. I hope this can be taken as a bug.

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Currentbar on Indicator doesnt match currentbar on serie

Postby Henry MultiСharts » 06 Nov 2012

Version 7.4 has this problem, too. This makes the code and the chart not to match each other and makes debugging much harder. I hope this can be taken as a bug.
That is not a bug, that is expected behavior. Please see JoshM above post for explanation.

Here is how to make indicator and signal calculation results the same

cnbiz850
Posts: 33
Joined: 15 Oct 2012
Has thanked: 1 time
Been thanked: 1 time

Re: Currentbar on Indicator doesnt match currentbar on serie

Postby cnbiz850 » 06 Nov 2012

That is not a bug, that is expected behavior. Please see JoshM above post for explanation.
Well, this might be an expected behavior with the description, but it is certainly not intuitive and not user friendly. Why can't MaxBarsBack be figured in currentbar in the code so that currentbar indicates the REAL currentbar on the chart where the mouse is, thereafter a lot of user confusions can be reduced and all the unnecessary explanations can be saved?

User avatar
Henry MultiСharts
Posts: 9165
Joined: 25 Aug 2011
Has thanked: 1264 times
Been thanked: 2957 times

Re: Currentbar on Indicator doesnt match currentbar on serie

Postby Henry MultiСharts » 09 Nov 2012

Why can't MaxBarsBack be figured in currentbar in the code so that currentbar indicates the REAL currentbar on the chart where the mouse is
These is a Symbol_CurrentBar reserved word for that.


Return to “MultiCharts”