Division zero error

Viewing 15 posts - 1 through 15 (of 35 total)
  • Author
    Posts
  • #212306 quote
    deleted23092025
    Participant
    New

    Hi,

    My systems stops with this error “The trading system was stopped due to a division by zero in one of its sub-functions during the evaluation of the last candlestick. You can add protections to your code to prevent divisions by 0 then backtest the system to check the correction.”

    Backtest also looks fine.

    Nothing is divided by zero. Can it be something else?

    #212307 quote
    Nicolas
    Keymaster
    Master

    You have to check any value that are used in each of the division. Do you have some? In the backtest or in indicators that are called?

    #212315 quote
    deleted23092025
    Participant
    New

    I have checked all values in each division noone is 0. I call for all the indicators.

    I run the algo wihtout calling the indicators and that works fine. But the other version when i Call each indicator with exact same numbers I get the error. Even though backtests are exact same.

    There is one tiny different, which I dont think matters? The one wihtout calling has DEFPARAM preloadbars = 5000 and the calling one has DEFPARAM preloadbars = 10000

    #212394 quote
    Nicolas
    Keymaster
    Master

    There are many reasons why a division by zero can occur, in order to be more precise I need to get into the code 🙂

    #212421 quote
    deleted23092025
    Participant
    New

    But how come the error only occurs on the system with call function?

    #212422 quote
    deleted23092025
    Participant
    New

    ”sub-functions during the evaluation of the last candlestick.”

     

    What does sub-functions mean? Does it refer to indicator, trailing stop, preloadbars or something else? As I mentioned none of the divisions are 0.

    #212473 quote
    PeterSt
    Participant
    Master

    As I mentioned none of the divisions are 0.

    , You won’t know that because internally all sorts of other commands are executed (think like 10 commands get in place of one command you wrote). So it requires imagination of what is implied.

    I would say that a sub function is something you would explicitly Call. But you are correct in thinking that it could be anything. PRT development likes to give their own “names” to existing phenomena. But also think of the translation to English. In French it could have been “Sub Routines”. That is a normally existing phenomenon and now it will be about some routine you call indeed. Can be an indicator – can be any code you have written/gotten in .itf form – and call.

    If you are not going to show the code and also the code(s) of what is called, then here it stops. Even with code these things are some times tough to solve or work around.


    It is not a bad idea to think that this could be a PRT bug. But in any event, take care that you have sufficient DefParam PreLoadBars pre-loaded. For this, observe all your functions like Average and all, and envision how many bars they would require to do their work in full.

    thanked this post
    #212505 quote
    Nicolas
    Keymaster
    Master

    If you are using Volumes or try to make division during calm hours, then a lack of values could be the cause..

    #212507 quote
    deleted23092025
    Participant
    New

    Alright thanks guys. One more question, if I have the EXACT same algo running wihtout call functions and one with call function. Can the call function strategy get repeatidly errors and the other one dont, even though all indicator is the same? Both show same backtest. And both ran on demo accounts on different accounts.

    #212522 quote
    Nicolas
    Keymaster
    Master

    A track with the CALL is to use fixed rather than variable parameters in your call, i.e. the indicator must not have external parameters, if it is possible to do so opposite your strategy, I suggest you give it a try. If you don't want to share the code on the forum, it is possible to create a support ticket that could go deeper and find a solution to your problem.

    thanked this post
    #212724 quote
    deleted23092025
    Participant
    New

    Ok, I fixed the differnce between the 2 codes but now the problem still ocurred on both = division 0. If backtest does not show the problem, how could I even try this?

    #212725 quote
    deleted23092025
    Participant
    New

    Should I just put .0001 on every other variable and try to find it this way (will take weeks). Or is there another way to solve this on my own?

    #212726 quote
    deleted23092025
    Participant
    New

    Im not sure but maybe below occur division 0? But how can I try this and be sure?

    lengthRSI = 3 
    lengthStoch = 3
    smoothK = 5
    smoothD = 2 
    myRSI = RSI[lengthRSI](close)
    MinRSI = lowest[lengthStoch](myrsi)
    MaxRSI = highest[lengthStoch](myrsi)
    StochRSI = (myRSI-MinRSI) / (MaxRSI-MinRSI)
    K = average[smoothK](stochrsi)*100
    D = average[smoothD](K)
    cl = K>D
    #212734 quote
    GraHal
    Participant
    Master

    Try adding this line of code at end of your code and check – after backtest – if value was ever 0?

    GRAPH (MaxRSI-MinRSI)
    thanked this post
    #212735 quote
    deleted23092025
    Participant
    New

    Thanks Grahal! Will do it now with realcode and find the issue.

Viewing 15 posts - 1 through 15 (of 35 total)
  • You must be logged in to reply to this topic.

Division zero error


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 34 replies,
has 4 voices, and was last updated by GraHal
2 years, 10 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 03/28/2023
Status: Active
Attachments: No files
Logo Logo
Loading...