I might be very thick this morning, but looking at the SMA indicator code I found that both Math.Min calls are unnecessary.
protected override void OnBarUpdate()
{
Print("OBU currentbar: "+CurrentBar);
if (CurrentBar == 0)
Value.Set(Input[0]);
else
{
double last = Value[1] * Math.Min(CurrentBar, Period);
if (CurrentBar >= Period)
Value.Set((last + Input[0] - Input[Period]) / Math.Min(CurrentBar, Period));
else
Value.Set((last + Input[0]) / (Math.Min(CurrentBar, Period) + 1));
}
}
protected override void OnBarUpdate()
{
Print("OBU currentbar: "+CurrentBar);
if (CurrentBar == 0)
Value.Set(Input[0]);
else
{
double last = Value[1] * Math.Min(CurrentBar, Period);
if (CurrentBar >= Period)
Value.Set((last + Input[0] - Input[Period]) / Period);
else
Value.Set((last + Input[0]) / (CurrentBar + 1));
}
}
PS.- I'm not trying to be critical, I ask this because I need to modify the SMA indicator and this got me confused...


Comment