Division by zero error

Forums ProRealTime English forum ProOrder support Division by zero error

Viewing 15 posts - 1 through 15 (of 19 total)
  • #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.

    #58858

    P.S. it usually happens when the market is not open physically (CFD only) and some candlesticks are very small or inexistent.

    1 user thanked author for this post.
    #58860

    At 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.
    #58872

    P.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.
    #58894

    Only do division if the divisor variable is superior to 0, it usually avoid this kind of error.

    1 user thanked author for this post.
    #58907
    Leo

    Have you check you variables in the fist candle. Try to define those with the function “once”

    1 user thanked author for this post.
    #59163

    Thank you all guys,

    I’ve added <> 0 condition to all of my variables, now it works!

    #59168

    Thank 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!

    #59201

    Wow … 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? 🙂

    #59208

    Wow … 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!

    #59216

    Well, 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

    #59217

    successful for a couple of days, however since the code is heavy, i think it will be pain in the ass re-adjusting it to market conditions…

    #59225

    Does it Walk Forward Test well? The quantity of indicators and conditions could be a recipe for curve fitting.

    #74871

    Vonasi 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:

    Then 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):

    This 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):

    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.

    #74873

    At 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:

     

    Note : 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.
Viewing 15 posts - 1 through 15 (of 19 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login