Hi,
it might be because with mySTOnLong=1, this means the stochastic calculation is made with a division of high-low, and that would indeed be worth zero when high=low.
Maybe an if statement checking high vs low for mySTOnLong=1, or >1 on its own (although it might happen again with mySTOnLong=2 if 2 consecutive candles with twice same high=low, but not as frequently, a more general condition could be written if that’s the case):
if (mySTOnLong=1 and high<>low) or mySTOnLong>1 then
mySTOLong = STOCHASTIc[mySTOnLong,mySTOkLong](close)
else
mySTOLong = // choose what default value to give when high=low and stochastic cannot be calculated over a span of mySTOnLong=1
endif
1 user thanked author for this post.