I have Range Bars 6 chart and I know where the close should end for the last bar - 2 possible positions:
RBLongClose = Low[0] + Bars.Period.Value * TickSize
RBShortClose = High[0] - Bars.Period.Value * TickSize
I would like to see EMA or TEMA value at this possible positions. I thought I can create IDataSeries variable which holds the Close values on historical bars and RBLongClose for the last bar (and similar for short). Than I tried to do EMA calculations on my IDataSeries variable and had it displayed in the chart. It doesn't work right and I can understand why
See my atteched pics. Everything looks good, but only on the "first" last bar after pressing F5. The farther bar is drawn after reloading the worse result. Im setting Close[1] for my IDataSeries[1] when new bar started drawing.
See my code:
protected override void OnBarUpdate()
{
if (CurrentBar<Period+1) return;
double closeLongValue = Bars.Instrument.MasterInstrument.Round2TickSize( Low[0] + ((Bars.Period.Value) * Bars.Instrument.MasterInstrument.TickSize) );
double closeShortValue = Bars.Instrument.MasterInstrument.Round2TickSize( High[0] - ((Bars.Period.Value) * Bars.Instrument.MasterInstrument.TickSize) );
// just when CurrentBar has changed
if (CurrBar!=CurrentBar) {
CurrBar = CurrentBar;
// just on the last bar
if (CurrentBar>=Bars.Count-1) {
CloseLong.Set(1,Close[1]);
CloseShort.Set(1,Close[1]);
CloseLong.Set(0,Close[0]); // for sure
CloseShort.Set(0,Close[0]); // for sure
Print(Close[1]+" - "+CloseLong[1]+" : "+CloseShort[1]);
EMALo.Set(1,EMA(CloseLong,14)[1]);
EMALo.Set(0,EMA(CloseLong,14)[0]); // for sure
EMASh.Set(1,EMA(CloseShort,14)[1]);
EMASh.Set(0,EMA(CloseShort,14)[0]); // for sure
}
}
if (Historical) {
CloseLong.Set(Close[0]);
CloseShort.Set(Close[0]);
} else {
CloseLong.Set(closeLongValue);
CloseShort.Set(closeShortValue);
}
EMALo.Set(EMA(CloseLong,14)[0]);
EMASh.Set(EMA(CloseShort,14)[0]);
.
.
.
CloseLong, CloseShort, EMALo, EMASh are IDataSeries.
CloseLong and CloseShort should hold historical Closes, only on the last bar it should have closeLongValue / closeShortValue values.
There is a line: Print(Close[1]+" - "+CloseLong[1]+" : "+CloseShort[1]);
It shows the same values.
I need is especially for TEMA calculations.
Thanks for your help.
Comment