division by 0 error

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #153213 quote
    Mishap
    Participant
    Junior
    RateOfChangeA = ROC[3](close)
    RateOfChangeB = ROC[3](close[3])
    Change = RateOfChangeA/RateOfChangeB
    
    RETURN change

    hi guys,

    I have read through the forums & found that this issue exists in several scenarios, i understand that the divisor cannot divide by 0 but neither of these should be throwing a 0.

    does anyone know what would cause this error with the code above, the code worked well without these lines but now that i have added them it stops the strategy from working.

    thanks in advance & apologies if this has been answered. the threads i read never actually had a fix just several ideas that seemed impractical.

    #153214 quote
    Mishap
    Participant
    Junior

    i think i found the issue. its in the RateOfChangeB ROC[3](close[3]) i changed to RateOfChangeB ROC[3](close[2]). lets see if this throws the error

    #153215 quote
    Nicolas
    Keymaster
    Master

    Why do you think that this is this code that is throwing this error please? Are you using a CALL to get the value of “change”?

    #153217 quote
    Mishap
    Participant
    Junior

    Hi Nicolas, the strategy was working fine & running without the addition of the ROC function. This is what makes me think it’s this piece of code.

    I am still quite new to coding & strategy development so I am unsure exactly what a call is. I am assuming that a call is used when I want to use the parameter “change”.

    “Change” is used further in the code when sending buy or sell signal.

    apologies for code below doing this on mobile & having issues with editor.

    IF Change >= 9 THEN

    BUY X at market

    ENDIF

    #153218 quote
    Mishap
    Participant
    Junior

    Side note changing the variable didn’t help

    #153221 quote
    Nicolas
    Keymaster
    Master

    Try to replace your code with:

    RateOfChangeA = ROC[3](close)
    RateOfChangeB = ROC[3](close[3])
    Change = RateOfChangeA/max(ticksize,RateOfChangeB)
    
    RETURN change

    It will ensure that the divisor is at least minimal size of a tick.

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

division by 0 error


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Mishap @mishap Participant
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by Nicolas
5 years, 2 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 12/10/2020
Status: Active
Attachments: No files
Logo Logo
Loading...