Because of "Print(smaUp[0]);" the indicator changes values. Which is, nonsense..
Whats going on?
protected override void OnBarUpdate()
{
Print("--------");
Print(CurrentBar);
Print(smaUp[0]); // this line changes the graphic and the values to negative
if (CurrentBar == 0)
{
down[0] = 0;
up[0] = 0;
if (Period < 3)
Avg[0] = 50;
return;
}
double input0 = Input[0];
double input1 = Input[1];
down[0] = Math.Max(input1 - input0, 0);
up[0] = Math.Max(input0 - input1, 0);
Print(smaUp[0]); // this line doesn't change a thing
if (CurrentBar + 1 < Period)
{
if (CurrentBar + 1 == Period - 1)
Avg[0] = 50;
return;
}
if ((CurrentBar + 1) == Period)
{
// First averages
avgDown[0] = smaDown[0];
avgUp[0] = smaUp[0];
}
else
{
// Rest of averages are smoothed
avgDown[0] = (avgDown[1] * constant3 + down[0]) / Period;
avgUp[0] = (avgUp[1] * constant3 + up[0]) / Period;
}
double avgDown0 = avgDown[0];
double value0 = avgDown0 == 0 ? 100 : 100 - 100 / (1 + avgUp[0] / avgDown0);
Default[0] = value0;
Avg[0] = constant1 * value0 + constant2 * Avg[1];
}

Comment