hello!
i have found a condition i want to use in a strategy on the 1 min TF that is causing the error “division by zero”
and here it is
c2 = (abs(close-open) / range <= 0.1) and close < open
anyone know a way how to solve this?
“range” is equal to zero because a candle is missing. You could probably get rid of this error by using this sort of code:
c2 = (abs(close-open) / max(range,pipsize) <= 0.1) and close < open
I had a similar problem where I was trying to calculate a dynamic position size and was getting a divide by zero error when the current price was equal to a variable I called “Entry”.
I fixed it like this:
PositionSize = abs(round(Maxrisk/((close+0.00001) - Entry)))
It’s not pretty but it works.
By always adding that tiny .00001 to the current close it ensures the two things are never equal and therefore no chance of division by 0.
Hope that helps.