Division by zero error
Forums › ProRealTime English forum › ProOrder support › Division by zero error
- This topic has 18 replies, 6 voices, and was last updated 6 years ago by Daniel_H.
-
-
01/10/2018 at 3:07 PM #58857
Hello,
I’ve started my automated trading strategy and it works well in backtesting mode, however in real life it is on for a couple of minutes, then disables and an error message tells me there has been a division by zero.
I’ve checked and rechecked the variables, doesn’t seem there is an error from me (might be mistaken since the code is over 4 pages and contains 40 entry conditions). Would you have a solution to resolve this issue? I’m looking for something like in excel, ignore if error phrase to be added to each of the 40 entry conditions.
Thank you so much in advance,
Kind regards.
01/10/2018 at 3:10 PM #5885801/10/2018 at 3:12 PM #58860At some point somewhere your code is trying to divide by a value of zero. You’ll need to go through the code and look at all the division sums and try to work out which variable or indicator return is causing the zero and then put some code in to ensure a value of zero is never returned. There is no other way really. Something is returning a zero and you just need to narrow down what it is with methodical working through of the code. Maybe sharing the code would make it easier in case someone else on here fancies having a look for you for anything obvious.
1 user thanked author for this post.
01/10/2018 at 4:13 PM #58872P.S. it usually happens when the market is not open physically (CFD only) and some candlesticks are very small or inexistent.
You’ve answered your own question there.
1 user thanked author for this post.
01/10/2018 at 6:04 PM #5889401/10/2018 at 6:34 PM #5890701/12/2018 at 11:36 AM #5916301/12/2018 at 11:58 AM #59168Thank you all guys, I’ve added <> 0 condition to all of my variables, now it works!
Well that is one way to do it! A bit untidy and slight overkill but sometimes whatever works is the way to do it!
01/12/2018 at 3:54 PM #5920101/12/2018 at 4:13 PM #59208Wow … 40 entry conditions … is it successful? Guess you will know now you sorted the divide by zero error? If you want to share the code I’m sure we’d all like to see?
I hadn’t spotted that – 40 conditions! Wow – if I write a strategy with 5 conditions I find it opens one trade a year. How do you satisfy 40 conditions and still get trades to open – even if only half are for entry and half for exit!? I want to see that code now – my interest is piqued!
01/12/2018 at 4:31 PM #59216Well, it is 20 conditions to go long and 20 conditions to go short. Since I’m using a mix of 5-6 indicators, it doesn’t seem too excessive to me 40 entry points 😉 but my hands hurt with all these corrections made manually 🙁
I cannot share the code here, sorry. Maybe if it turns to be profitable in the mid term, I will open a hedge fund :DDD
01/12/2018 at 4:32 PM #5921701/12/2018 at 4:55 PM #5922506/29/2018 at 9:19 PM #74871Vonasi and Nicolas,
this problem seems to be related to the problem I had with how the IF statements are handled by PRT. That is that PRT do everything at once at the end of a candle. I found this thread when I had the same zero-problem.
This is how I planned on fixing the problem. First the error:
123bearcandlesize = open - closebearwicksize = close - lowbearcandlevswick = bearcandlesize / bearwicksizeThen the planned solution that doesn’t work (but I think should work – I used times 10 this time but could be 100 or 1000 or something else mathematically correct that’s needed):
123bearcandlesize = (open - close) * 10bearwicksize = (close - low) * 10bearcandlevswick = bearcandlesize / bearwicksizeThis time nothing should be divided by zero (and aren’t zero when looking with the GRAPH-function), but since PRT doesn’t do anything until the end of the candle, bearcandlesize and bearwicksize isn’t multiplied by 10 yet (which would increase as example 0.12 to 1.2).
How I know that the multiplication doesn’t work? I have a system I’m testing and without the division I get 25 trades (11 wins and 14 losses), when I use the division I guess all zero-division trades are removed and the result is only 14 trades (5 wins and 9 losses).
The way to get around this, but doesn’t help the trading system (because we need the calculation to be done at this candle), is this (which does the calculation of the previous candle instead):
123bearcandlesize = (open - close) * 10bearwicksize = (close - low) * 10bearcandlevswick = bearcandlesize[1] / bearwicksize[1]This time the result is once again 25 trades (11 wins and 14 losses), which means the division doesn’t cut all (or some of the) zero-trades anymore.
Do you see a resolution to this that I doesn’t see?
Sincerely,
Daniel.06/29/2018 at 9:59 PM #74873At the candle close the values for open close and low are fixed and the code is then read. The only way you can have a division by zero is if the close and low are the same value or open and close are the same value.
Multiplying zero by ten still gives you zero so I do not understand why you are doing this.
In your last piece of code you are looking at the candle values for the candle before the one that has just closed – I have no idea why you are doing this either as it could still have a zero value for close – low or open – close.
You could do this to ensure no zero value is calculated:
123bearcandlesize = max((open - close), 0.000000001)bearwicksize = max((close - low), 0.000000001)bearcandlevswick = bearcandlesize / bearwicksizeNote : It is normally preferred that you start a new topic with a new coding problem rather than add on to an old topic.
1 user thanked author for this post.
-
AuthorPosts
Find exclusive trading pro-tools on