help with division by 0 error

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #168284 quote
    Mishap
    Participant
    Junior
    DEFPARAM CumulateOrders = TRUE // Cumulating positions deactivated
    DEFPARAM preloadbars = 1000
    
    //Trigger to enter position (all other criteria must be met)
    
    //current time frame
    rsi1 = RSI[8](close)
    rsi2 = RSI[1](close)
    c1 = (rsi2 CROSSES over rsi1)
    //c2 = (close >= MA2)
    Timeframe (2 minutes)
    //base moving average indicator percentages 3 candle look back
    Ind1 = Average[15] (close[3])
    Ind2 = Average[20] (close[3])
    Ind3 = Average[25] (close[3])
    Ind4 = Average[30] (close[3])
    
    
    //moving average candle indicator percentages
    Ind5 = Average[15] (close)
    Ind6 = Average[20] (close)
    Ind7 = Average[25] (close)
    Ind8 = Average[30] (close)
    
    //get distance from averages in percentage relative to one above or below
    DistPer1 = abs(Ind1-Ind2)*100/Ind1
    DistPer2 = abs(Ind2-Ind3)*100/Ind2
    DistPer3 = abs(Ind3-Ind4)*100/Ind3
    DistPer4 = abs(Ind5-Ind6)*100/Ind5
    DistPer5 = abs(Ind6-Ind7)*100/Ind6
    DistPer6 = abs(Ind7-Ind8)*100/Ind7
    
    c3 = DistPer4-DistPer1
    c4 = DistPer5-DistPer2
    c5 = DistPer6-DistPer3
    
    IF Ind5 > Ind6 AND Ind6 > Ind7 AND Ind7 > Ind8 THEN
    UpTrend = 1
    ELSE
    UpTrend = 0
    ENDIF
    
    Per1 = .001
    Per2 = .002
    Per3 = .003
    
    // Conditions to enter long positions
    IF c1 AND c3 >= Per1 AND c4 >= Per2 AND c5 >= Per3 AND UpTrend THEN
    BUY 1 CONTRACTS AT MARKET
    ENDIF
    
    
    
    
    

    Hi Guys,

    Im hoping someone can point me in the right direction with where my code is causing division by 0 error. i think its in the “DistPer” section of the code. essentially im trying to get 3 different averages from 3 candles back & compare to the current average. if there is an increase in percentage as at the “Per” value. it keeps throwing the div by 0 error which i cant seem to clear.

    I have reviewed other threads around div by 0 error but haven’t found a workable solution as yet.

    any help is appreciated.

    cheers

    #168289 quote
    robertogozzi
    Moderator
    Master

    Post your topic in the correct forum:
    _ ProRealTime Platform Support: only platform related issues.
    _ ProOrder: only strategy topics.
    _ ProBuilder: only indicator topics.
    _ ProScreener: only screener topics
    _ General Discussion: any other topics.
    _ Welcome New Members: for new forum members to introduce themselves.

    Thank you 🙂

    #168290 quote
    robertogozzi
    Moderator
    Master

    Don’t you need

    DistPerN = abs(Ind4-Ind3)*100/Ind4

    ?

    Try using GRAPH to monitor the variables involved in division:

    GRAPH Ind1
    GRAPH Ind2
    GRAPH Ind3
    GRAPH Ind4
    GRAPH Ind5
    GRAPH Ind6
    GRAPH Ind7

    or this version:

    GRAPH Ind1 = 0
    GRAPH Ind2 = 0
    GRAPH Ind3 = 0
    GRAPH Ind4 = 0
    GRAPH Ind5 = 0
    GRAPH Ind6 = 0
    GRAPH Ind7 = 0
    #168310 quote
    Jean-Christophe
    Participant
    Master

    Hello Mishap, the division by 0 error is due to

    RSI[1](close)

    I had exactly the same error when running a strategy live and I searched during a long time before finding the solution.

    Try to use at least

    RSI[2](close)

    as the parameter must be an integer greater than 1

    GraHal thanked this post
    #200609 quote
    thomas_price
    Participant
    Junior

    Hello Mishap, the division by 0 error is due to

    I had exactly the same error when running a strategy live and I searched during a long time before finding the solution.

    Try to use at least

    as the parameter must be an integer greater than 1

    is it true ? someone else has the same issue with [1] previous value ?

    🙂

    #200619 quote
    JC_Bywan
    Moderator
    Master

    Hi, you shouldn’t read [1] in RSI[1](close) as a previous value here, but as the RSI period.

    For  [1] to be a previous value, it would have to be at the end: RSI[period](close)[1]

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

help with division by 0 error


ProOrder: Automated Strategies & Backtesting

New Reply
Author
author-avatar
Mishap @mishap Participant
Summary

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

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