Good Day Everyone,
this is about another division by zero issue. It does happen to me with various instruments (NDX, DAX etc.) only within the 1M time frame.
I checked other forum posts and tried a few things: -volume is > 0, -only execute in a selected time frame, -tried the min and max function
Here is part of the code (I think it happens with “mySTOLong = STOCHASTIc…”, if I set it the mySTOLong value to 0 it does work).
And of course every time it stops i see that close = open and open = high and high = low….
Any idea or comment is highly appreciated!
Thx Oliver
mySTOnLong = 1
mySTOkLong = 6
mySTOsmootherLong = 4
mySTOlookPeriodsLong = 11
mySTOoverBoughtLimitLong = 90
mySTOoverSoldLimitLong = 49
LongTime = time>=090000 and time<170000
if longtime and NOT ONMARKET then
// STOCHASTIC CONDITION
//
mySTOLong = STOCHASTIc[mySTOnLong,mySTOkLong](close)
//mySTOLong = 0 // STOCHASTIc[mySTOnLong,mySTOkLong](close)
mySTOsmoothedLong = AVERAGE[mySTOsmootherLong](mySTOLong)
mySTOcrossOverLong = SUMMATION[mySTOlookPeriodsLong]((mySTOLong CROSSES OVER mySTOsmoothedLong) AND (mySTOLong < mySTOoverSoldLimitLong))
mySTOnotOverBoughtLong = (mySTOLong < mySTOoverBoughtLimitLong) AND (mySTOsmoothedLong < mySTOoverBoughtLimitLong)
mySTOconditionLong = mySTOcrossOverLong AND mySTOnotOverBoughtLong
ENDIF
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