My code has been repeatedly stopping with ‘divide by zero’ errors. I have been reluctant to post it and ask for help as it contains someone else’s intellectual property, but after a lot of time I think that I’ve managed to isolate the lines causing the problem. I would very much appreciate help with why these cause a problem, and how to work round it. If I comment out the following lines then the code runs:
ADXLongOK = ADX[6] > 5
ADXShortOK = ADX[1.3] > 15
These variables are combined with many others into conditions for trade entries.
Try using an integer numeber of periods for the short ADX.
Check all divisions in your code, are they made with a variable not initialized (with no value)?
robertogozzi – that fixed it. Thank you.
For anyone who does what I did….I came up with these ADX values through optimisation. Although I wasn’t familiar with ADX, I now realise that these are strange values. With ADX[1.4], the code running on the 5m minute chart was stopped every 5 minutes. To correct it, I made an integer, but rounded down, so ended up with ADX[1]. This time, the code lasted longer than 5 minutes, but eventually was stopped. When I changed it to ADX[2], it ran consistently without failing.