Supposedly, the keyword Symbol_CurrentBar allows coding to reference bars before MaxBarsBack. However, the outcome is not consistent with no apparent reason. Below are two sets of codes showing inconsistent outcome.
1st Set of Code:
Code: Select all
Variables:
ii (1);
Print ("BarNum = ", Symbol_CurrentBar, ", Date/time = ", Date, "-", Time, ", ii = ", ii);
ii = ii + 1;
BarNum = 1.00, Date/time = 1180530.00- 919.00, ii = 1.00
BarNum = 2.00, Date/time = 1180530.00- 924.00, ii = 2.00
BarNum = 3.00, Date/time = 1180530.00- 929.00, ii = 3.00
BarNum = 4.00, Date/time = 1180530.00- 934.00, ii = 4.00
BarNum = 5.00, Date/time = 1180530.00- 939.00, ii = 5.00
BarNum = 6.00, Date/time = 1180530.00- 944.00, ii = 6.00
BarNum = 7.00, Date/time = 1180530.00- 949.00, ii = 7.00
BarNum = 8.00, Date/time = 1180530.00- 954.00, ii = 8.00
BarNum = 9.00, Date/time = 1180530.00- 959.00, ii = 9.00
BarNum = 10.00, Date/time = 1180530.00-1004.00, ii = 10.00
2nd Set of Code:
Code: Select all
Variables:
ii (1);
If Symbol_CurrentBar <> 1 Then Begin
If Date [1] <> Date [0] Then Begin
Print ("===============================================================");
End;
End;
Print ("BarNum = ", Symbol_CurrentBar, ", Date/time = ", Date, "-", Time, ", ii = ", ii);
ii = ii + 1;
BarNum = 1.00, Date/time = 1180530.00- 919.00, ii = 1.00
BarNum = 7.00, Date/time = 1180530.00- 949.00, ii = 1.00
BarNum = 8.00, Date/time = 1180530.00- 954.00, ii = 2.00
BarNum = 9.00, Date/time = 1180530.00- 959.00, ii = 3.00
BarNum = 10.00, Date/time = 1180530.00-1004.00, ii = 4.00
BarNum = 11.00, Date/time = 1180530.00-1009.00, ii = 5.00
BarNum = 12.00, Date/time = 1180530.00-1014.00, ii = 6.00
BarNum = 13.00, Date/time = 1180530.00-1019.00, ii = 7.00
BarNum = 14.00, Date/time = 1180530.00-1024.00, ii = 8.00
BarNum = 15.00, Date/time = 1180530.00-1029.00, ii = 9.00
The outcome of the 1st set of code is correct. However, the outcome of the 2nd set of code is wrong, where bar number 2 to 6 were not processed and the ii value from bar number 7 onwards were wrong. These errors are marked in red font.
As the codes are simple and straightforward, I do not think there is any problem with the coding. It appears that when Symbol_CurrentBar is used more than once within the same bar, code processing is messed up and misses out a number of early bars.
I cannot use CurrentBar or BarNumber instead because they have the MaxBarsBack restriction, which makes it unable to reference bars before it.
Could you please advise how to fix the Symbol_CurrentBar problem?
Thanks,
McGeorge