code question  [SOLVED]

Questions about MultiCharts and user contributed studies.
waveslider
Posts: 223
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

code question

Postby waveslider » 29 Jul 2015

Here is simple code that is applied to an intraday chart with 81 bars in a day.

value1=XAverage(c,100);
value2=value1[81];
if barstatus(1)=2 then print(date," ",time," ",value1," ",value2);

Value2 should show what value1 was 81 bars ago, the same time of day. According to the printout, instead it is showing what Value1 was 94 bars ago.

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

Re: a very concerning bug

Postby TJ » 29 Jul 2015

Here is simple code that is applied to an intraday chart with 81 bars in a day.
value1=XAverage(c,100);
value2=value1[81];
if barstatus(1)=2 then print(date," ",time," ",value1," ",value2);
Value2 should show what value1 was 81 bars ago, the same time of day. According to the printout, instead it is showing what Value1 was 94 bars ago.

You should review your result again, I doubt there is a bug for a rudimental operation like this.


What is your chart resolution?
Please post your complete code as well as your output.

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

Re: a very concerning bug  [SOLVED]

Postby TJ » 29 Jul 2015

hint:

Always always always avoid using generic variable names. ie value1, condition1, etc.,

Variable names are free... they can save you lots of headache in debug time.

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

Re: a very concerning bug

Postby TJ » 29 Jul 2015

ps.

[FAQ] How to Post Codes (that people can read)
viewtopic.php?f=16&t=11713

waveslider
Posts: 223
Joined: 16 Oct 2011
Has thanked: 66 times
Been thanked: 20 times

Re: a very concerning bug

Postby waveslider » 29 Jul 2015

Thanks - you completely nailed it - it was using the "value1" that did it...
I did this out of laziness, and don't typically use "value1", but never will again - is this common knowledge?


Return to “MultiCharts”