Symbol_CurrentBar Not Working Properly  [SOLVED]

Questions about MultiCharts and user contributed studies.
McGeorge
Posts: 26
Joined: 22 Jun 2018
Has thanked: 8 times
Been thanked: 1 time

Symbol_CurrentBar Not Working Properly

Postby McGeorge » 17 Sep 2018

Hi there,

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;
Outcome: (Only the first ten lines are quoted)
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;
Outcome: (Only the first ten lines are quoted)
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

User avatar
TJ
Posts: 7354
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 993 times
Been thanked: 2100 times

Re: Symbol_CurrentBar Not Working Properly

Postby TJ » 17 Sep 2018

What is your chart resolution?

What is your MaxBarsBack?

User avatar
TJ
Posts: 7354
Joined: 29 Aug 2006
Location: Global Citizen
Has thanked: 993 times
Been thanked: 2100 times

Re: Symbol_CurrentBar Not Working Properly

Postby TJ » 17 Sep 2018

Try this:

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 = ", 19000000+Date, "-", Time, ", ii = ", ii, ", MBB=", MaxBarsBack);
ii = ii + 1;


McGeorge
Posts: 26
Joined: 22 Jun 2018
Has thanked: 8 times
Been thanked: 1 time

Re: Symbol_CurrentBar Not Working Properly

Postby McGeorge » 17 Sep 2018

Try this:

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 = ", 19000000+Date, "-", Time, ", ii = ", ii, ", MBB=", MaxBarsBack);
ii = ii + 1;

Hi TJ,

I used 1 Min and 5 Min and they both generated similar error. I tried your codes same error happened (see below). Interestingly, I tried CurrentBar instead of Symbol_CurrentBar and similar error happened.

Outcome: (Only first 10 rows are displayed)
BarNum = 1.00, Date/time = 20180530.00- 919.00, ii = 1.00, MBB= 0.00
BarNum = 7.00, Date/time = 20180530.00- 949.00, ii = 1.00, MBB= 6.00
BarNum = 8.00, Date/time = 20180530.00- 954.00, ii = 2.00, MBB= 6.00
BarNum = 9.00, Date/time = 20180530.00- 959.00, ii = 3.00, MBB= 6.00
BarNum = 10.00, Date/time = 20180530.00-1004.00, ii = 4.00, MBB= 6.00
BarNum = 11.00, Date/time = 20180530.00-1009.00, ii = 5.00, MBB= 6.00
BarNum = 12.00, Date/time = 20180530.00-1014.00, ii = 6.00, MBB= 6.00
BarNum = 13.00, Date/time = 20180530.00-1019.00, ii = 7.00, MBB= 6.00
BarNum = 14.00, Date/time = 20180530.00-1024.00, ii = 8.00, MBB= 6.00
BarNum = 15.00, Date/time = 20180530.00-1029.00, ii = 9.00, MBB= 6.00


Any idea what happened?

Thanks,
McGeorge

McGeorge
Posts: 26
Joined: 22 Jun 2018
Has thanked: 8 times
Been thanked: 1 time

Re: Symbol_CurrentBar Not Working Properly  [SOLVED]

Postby McGeorge » 18 Sep 2018

Hi there,

I found out how to fix the problem myself. It was a coding issue. The Date and Time keywords need to be changed to Symbol_Date and Symbol_Time to synchronize bar numbering between the two systems.

McGeorge


Return to “MultiCharts”