{
nom.Set(Close[0] - MIN(Low, PeriodK)[0]);
den.Set(MAX(High, PeriodK)[0] - MIN(Low, PeriodK)[0]);
if (den[0].Compare(0, 0.000000000001) == 0)
fastK.Set(CurrentBar == 0 ? 50 : fastK[1]);
else
fastK.Set(Math.Min(100, Math.Max(0, 100 * nom[0] / den[0])));
// Slow %K == Fast %D
K.Set(SMA(fastK, Smooth)[0]);
D.Set(SMA(K, PeriodD)[0]);
}
Hi,
I'm a NinjaTrader newbie and am looking at the code of the Stochastic indicator
shown above.One line which I don't understand is:
if (den[0].Compare(0, 0.000000000001) == 0)
My understanding is that den[0] is calculated as the highest high minus the lowest low value of
the last PeriodK. (Putting it in the data series as the most recent value)
I'm not understanding what the compare is doing and I was unable to find it in the
NinjaScript language help.
Also for the line below, I thought that 100 * nom[0] / den[0] would always be positive, so I'm
not sure why it is compared with 0, to find the max.
fastK.Set(Math.Min(100, Math.Max(0, 100 * nom[0] / den[0])));
Thank you,
Ken
Comment