I need to plot 2 lines for same day's high and low prices, where the line needs to extend from the latest bar back to the first bar of the day.
I used a loop and Plot [x] keyword to modify the plot value of the past bars. The x value is calculated by subtracting the bar number of the first bar of the day from the current bar. The outcome is that the first 95 bars do not show any plot value. For a 5-minute chart, it means the first day does not have any plot and the second day has 19 bars without plot. The missing plots also cause the plot lines to show incorrect high and low prices for the second day. However, all plot lines look fine from third day onwards. I guess the missing part is due to the MaxBarsBack restriction but the number of bars with missing plot is too big and is unacceptable. The MaxBarsBack setting is "auto-detect" but even if I changed it to zero, the outcome was the same.
To fill up the gap and allow the plots to touch the very first bar, I tried to modify keywords like CurrentBar, Date, High, Low, etc., to Symbol_CurrentBar, Symbol_Date, Symbol_High, Symbol_Low, etc.. The outcome was even worse, where no plot is displayed and the chart status line keeps showing "calculating".
Below are my codes and the outcome displayed in Output window. The output is so weird that it cannot be deciphered. However, If I removed all plot codings, the output looks very normal.
Coding using CurrentBar keyword:
Code: Select all
Variables:
ii (1),
DayHigh (0),
DayLow (0),
DayFirstBar (0);
If CurrentBar = 1 Or Date [1] <> Date [0] Then Begin
Print ("=======================================================");
DayHigh = High [0];
DayLow = Low [0];
DayFirstBar = CurrentBar;
End;
If High [0] > DayHigh Then DayHigh = High [0];
If Low [0] < DayLow Then DayLow = Low [0];
Print ( "BarNum = ", CurrentBar, ", Date/Time = ", Date, "-", Time,
", DayHigh = ", DayHigh, ", DayLow = ", DayLow, ", DayFirstBar = ", DayFirstBar );
For ii = 0 To CurrentBar - DayFirstBar Begin
Plot1 [ii] (DayHigh, "DayHigh");
Plot2 [ii] (DayLow, "DayLow");
End;
=======================================================
BarNum = 1.00, Date/Time = 1180530.00- 919.00, DayHigh = 30082.00, DayLow = 29983.00, DayFirstBar = 1.00
=======================================================
BarNum = 1.00, Date/Time = 1180530.00- 949.00, DayHigh = 30048.00, DayLow = 29976.00, DayFirstBar = 1.00
BarNum = 2.00, Date/Time = 1180530.00- 954.00, DayHigh = 30048.00, DayLow = 29972.00, DayFirstBar = 1.00
BarNum = 3.00, Date/Time = 1180530.00- 959.00, DayHigh = 30048.00, DayLow = 29972.00, DayFirstBar = 1.00
BarNum = 4.00, Date/Time = 1180530.00-1004.00, DayHigh = 30048.00, DayLow = 29972.00, DayFirstBar = 1.00
BarNum = 5.00, Date/Time = 1180530.00-1009.00, DayHigh = 30048.00, DayLow = 29869.00, DayFirstBar = 1.00
BarNum = 6.00, Date/Time = 1180530.00-1014.00, DayHigh = 30048.00, DayLow = 29858.00, DayFirstBar = 1.00
BarNum = 7.00, Date/Time = 1180530.00-1019.00, DayHigh = 30048.00, DayLow = 29855.00, DayFirstBar = 1.00
BarNum = 8.00, Date/Time = 1180530.00-1024.00, DayHigh = 30048.00, DayLow = 29824.00, DayFirstBar = 1.00
=======================================================
BarNum = 1.00, Date/Time = 1180530.00-1019.00, DayHigh = 29894.00, DayLow = 29855.00, DayFirstBar = 1.00
BarNum = 2.00, Date/Time = 1180530.00-1024.00, DayHigh = 29894.00, DayLow = 29824.00, DayFirstBar = 1.00
BarNum = 3.00, Date/Time = 1180530.00-1029.00, DayHigh = 29894.00, DayLow = 29794.00, DayFirstBar = 1.00
Coding using Symbol_CurrentBar keyword:
Code: Select all
Variables:
ii (1),
DayHigh (0),
DayLow (0),
DayFirstBar (0);
If Symbol_CurrentBar = 1 Or Symbol_Date [1] <> Symbol_Date [0] Then Begin
Print ("=======================================================");
DayHigh = Symbol_High [0];
DayLow = Symbol_Low [0];
DayFirstBar = Symbol_CurrentBar;
End;
If Symbol_High [0] > DayHigh Then DayHigh = Symbol_High [0];
If Symbol_Low [0] < DayLow Then DayLow = Symbol_Low [0];
Print ( "BarNum = ", Symbol_CurrentBar, ", Date/Time = ", Symbol_Date, "-", Symbol_Time,
", DayHigh = ", DayHigh, ", DayLow = ", DayLow, ", DayFirstBar = ", DayFirstBar );
For ii = 0 To Symbol_CurrentBar - DayFirstBar Begin
Plot1 [ii] (DayHigh, "DayHigh");
Plot2 [ii] (DayLow, "DayLow");
End;
=======================================================
BarNum = 1.00, Date/Time = 1180530.00- 919.00, DayHigh = 30082.00, DayLow = 29983.00, DayFirstBar = 1.00
BarNum = 2.00, Date/Time = 1180530.00- 924.00, DayHigh = 30082.00, DayLow = 29947.00, DayFirstBar = 1.00
BarNum = 7.00, Date/Time = 1180530.00- 949.00, DayHigh = 30048.00, DayLow = 0.00, DayFirstBar = 0.00
BarNum = 13.00, Date/Time = 1180530.00-1019.00, DayHigh = 29894.00, DayLow = 0.00, DayFirstBar = 0.00
BarNum = 22.00, Date/Time = 1180530.00-1104.00, DayHigh = 29886.00, DayLow = 0.00, DayFirstBar = 0.00
BarNum = 36.00, Date/Time = 1180530.00-1314.00, DayHigh = 29918.00, DayLow = 0.00, DayFirstBar = 0.00
BarNum = 59.00, Date/Time = 1180530.00-1509.00, DayHigh = 29865.00, DayLow = 0.00, DayFirstBar = 0.00
BarNum = 96.00, Date/Time = 1180531.00-1059.00, DayHigh = 30095.00, DayLow = 0.00, DayFirstBar = 0.00
BarNum = 156.00, Date/Time = 1180601.00- 944.00, DayHigh = 30430.00, DayLow = 0.00, DayFirstBar = 0.00
I also attached the screenshots of the charts.
Please advise what I can do to plot the charts properly.
Thanks,
McGeorge