division by zero error but im not dividing anything

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #189098 quote
    MishapMishap
    Participant
    Junior

    Hi guys as the title suggests i keep getting the division by zero error but im not dividing anything. can anyone see an issue with the attached? i scratching my head. the code at the bottom is a custom indicator is this causing the issue?

    
    // Definition of code parameters
    DEFPARAM CumulateOrders = true // Cumulating positions deactivated
    // The system will cancel all pending orders and close all positions at 0:00. No new ones will be allowed until after the "FLATBEFORE" time.
    DEFPARAM FLATBEFORE = 100000
    // Cancel all pending orders and close all positions at the "FLATAFTER" time
    DEFPARAM FLATAFTER = 060000
    
    // Prevents the system from placing new orders on specified days of the week
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    
    if not onmarket then
    c1 =1
    c5 = 1
    endif
    // Conditions to enter long positions
    indicator1 = CALL "trend/no trend"
    c1 = indicator1
    
    indicator2 = RSI[1](close)
    c2 = (indicator2 < 30)
    indicator3 = MACDline[12,26,9](close)
    indicator4 = ExponentialAverage[9](MACDline[12,26,9](close))
    c3 = (indicator3 CROSSES OVER indicator4)
    
    
    IF (c1=0 AND c2 AND c3) and not daysForbiddenEntry THEN
    BUY 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit long positions
    indicator5 = MACDline[12,26,9](close)
    indicator6 = ExponentialAverage[9](MACDline[12,26,9](close))
    c4 = (indicator5 CROSSES UNDER indicator6)
    indicator13 = CALL "trend/no trend"
    c9 = (indicator13 = 1)
    
    IF c4 and c9 THEN
    SELL AT MARKET
    ENDIF
    
    // Conditions to enter short positions
    indicator7 = CALL "trend/no trend"
    c5 = indicator7
    indicator8 = RSI[1](close)
    c6 = (indicator8 >= 60)
    indicator9 = MACDline[12,26,9](close)
    indicator10 = ExponentialAverage[9](MACDline[12,26,9](close))
    c7 = (indicator9 CROSSES UNDER indicator10)
    
    IF (c5 AND c6 AND c7) AND not daysForbiddenEntry THEN
    SELLSHORT 1 CONTRACT AT MARKET
    ENDIF
    
    // Conditions to exit short positions
    indicator11 = MACDline[12,26,9](close)
    indicator12 = ExponentialAverage[9](MACDline[12,26,9](close))
    c8 = (indicator11 CROSSES OVER indicator12)
    indicator14 = CALL "trend/no trend"
    c10 = (indicator14 = 1)
    
    IF c8 and c10 THEN
    EXITSHORT AT MARKET
    ENDIF
    
    // Stops and targets
    SET TARGET PPROFIT 15
    SET STOP pLOSS 10
    
    
    
    //-------------------------------------------------------------------------
    // Function : trend/no trend
    //-------------------------------------------------------------------------
    // period da ottimizzare
    AA = 50
    t=(LinearRegressionSlope[AA](close)-0)*SQRT(AA-2)/(STE[AA](close)/STD[AA](Barindex))
    if t>1.96 then
    beta=1
    endif
    
    if t<-1.96 then
    beta=-1
    endif
    
    if t-1.96 then
    beta=0
    endif
    
    return beta
    
    #189099 quote
    PeterStPeterSt
    Participant
    Master

    Hi there,

    I should at least change line 85

    if t-1.96 then

    to

    if t=1.96 then

    You’d want that anyway and maybe it even helps. 🙂

    #189100 quote
    robertogozzirobertogozzi
    Moderator
    Legend

    The issue could be due to the indicator “trend/no trend”.

    Check any division in there.

    #189101 quote
    JSJS
    Participant
    Master

    Hi @Mishap

    t=(LinearRegressionSlope[AA](close)0)*SQRT(AA2)/(STE[AA](close)/STD[AA](Barindex))

    When BarIndex = 0 then STD[AA](BarIndex) is zero (devision by zero)

    Remarks:

    (Close)-0) ???

    Standarddeviation of the BarIndex???

    CumulateOrders is not deactivated because = true

    #189109 quote
    NicolasNicolas
    Keymaster
    Legend

    Weird code, but ok 🙂

    The problem is located in your indicator, make sure you have sufficient history in order to calculate the standard deviation of the barindex (!??) 😆

    //-------------------------------------------------------------------------
    // Function : trend/no trend
    //-------------------------------------------------------------------------
    // period da ottimizzare
    AA = 50
    if barindex>AA then 
     t=(LinearRegressionSlope[AA](close)-0)*SQRT(AA-2)/(STE[AA](close)/STD[AA](Barindex))
     if t>1.96 then
      beta=1
     endif
     
     if t<-1.96 then
      beta=-1
     endif
     
     if t-1.96 then
      beta=0
     endif
    endif 
     
    return beta
    #189134 quote
    MishapMishap
    Participant
    Junior

    lol thanks guys, i was trying something a little different 🙂

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

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

division by zero error but im not dividing anything


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 MishapMishap
4 years, 6 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 03/01/2022
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...