I'm doing a simple check for the value of 4 EMA lines and I'm getting some unexpected values. I'm hoping someone smarter than I am can guide me in the right direction.
in State.SetDefaults I have:
EMA1Period = 12; EMA2Period = 22; EMA3Period = 60; EMA4Period = 210;
in State.DataLoaded I have
EMA1 = EMA(Closes[0], Convert.ToInt32(EMA1Period)); EMA2 = EMA(Closes[0], Convert.ToInt32(EMA2Period)); EMA3 = EMA(Closes[0], Convert.ToInt32(EMA3Period)); EMA4 = EMA(Closes[0], Convert.ToInt32(EMA4Period));
OnBarUpdate() I'm doing this:
if ((EMA1[1] > EMA2[1])
&& (EMA2[1] > EMA3[1])
&& (EMA3[1] > EMA4[1]))
{
roundedEMA1 = Instrument.MasterInstrument.RoundToTickSize(EMA1[1]);
roundedEMA2 = Instrument.MasterInstrument.RoundToTickSize(EMA2[1]);
roundedEMA3 = Instrument.MasterInstrument.RoundToTickSize(EMA3[1]);
roundedEMA4 = Instrument.MasterInstrument.RoundToTickSize(EMA4[1]);
Print("");
Print("EMA1[1]: " + EMA1[1]);
Print("roundedEMA1: " + roundedEMA1);
Print("EMA2[1]: " + EMA2[1]);
Print("roundedEMA2: " + roundedEMA2);
Print("EMA3[1]: " + EMA3[1]);
Print("roundedEMA3: " + roundedEMA3);
Print("EMA4[1]: " + EMA4[1]);
Print("roundedEMA4: " + roundedEMA4);
}
roundedEMA1, roundedEMA2, roundedEMA3 and roundedEMA4 have been set as the type double.
The print I'm getting is:
EMA1[1]: 3988.67903240544 roundedEMA1: 3988.75 EMA2[1]: 3983.36452234448 roundedEMA2: 3983.25 EMA3[1]: 3974.44215648095 roundedEMA3: 3974.5 EMA4[1]: 3970.64331144022 roundedEMA4: 3970.75
EMA1 Rounding UP
EMA2: Rounding Down
EMA3: Rounding UP
EMA4: Rounding Up
Aren't all 4 supposed to Round UP? What's up with EMA2?

Comment