Division by zero parameter error on 3 different strategies

Forums ProRealTime English forum ProOrder support Division by zero parameter error on 3 different strategies

Viewing 15 posts - 1 through 15 (of 36 total)
  • #210853

    Hi PRC Coders,

    I have been trying to figure out what the problem in my code is regarding the trading strategies on a 5 minute timeframe and have tried different nuances to solve the error (division by zero parameter). I have both tried it on the demo as well as my live account but it keep on stopping with the same error message. It works fine on the back tests but not demo or live! Can someone perhaps show me the error of my ways in this regard?

    1.) The first strategy is a MA cross with a RSI condition, being met not more than 5 bars after the crossover.
    2.) The second strategy is also a MA cross over without the bar count but only the RSI condition (Trying to eliminate some code to try and figure out why I get the error).
    3.) The third strategy is altogether different with various variables but with the same cross over principal (completely different cross over but same error message)

     

    #210856

    Apologies I see I missed a part of the 3rd strategy, here it is:

     

    #210874

    I have run them in autotrading on Dax, 5-minute TF. I’ll report any returned message and findings, though it doesn’t seem they have any apparent issues.

     

    1 user thanked author for this post.
    #210910

    Thanks Roberto, I was also surprised it is straight forward…with no divisions in the code?

    #210911

    Hi Roberto,

    Also notice that one of the strategies actually opened a trade and when the division by zero error appeared it closed the position prematurely (please see image attachments). Thank you.

    #210923

    Johann,

    It is a bit tricky to check, but you mix Length with Lenght. And if you do this one time inconsistently within one code, there you go;
    Depending how you apply the “errors”, PRT may not detect you are using an undefined variable and instead uses it with a value of 0. It is your typo of course, but it is PRT failing.

    Peter

    1 user thanked author for this post.
    #210966

    Thanks PeterSt, well spotted. I was going around in circles and could not figure it out will simplify the code and replace with actual numbers that should also help! The only weird thing about this is how the code with the error was accepted on the back testing …?

    #210971

    If I guessed correctly that your code fails somewhere on an undefined variable (and this is a long shot despite the “typos”) then it just depends in what sequence the code is executed, which depends on the (bar-) data. So this is not entirely odd. And even if it is not about the variables, it still can depend on the data which is always new in Live or Demo, against Backtest which is old. IOW, it always is different.

    Btw, one other thing I noticed was the RSI(1). This would not make sense (I think ?) and maybe something can choke on it. This too could be data depended (referring to your code not dying from of bar-1).
    Edit: But that RSI(1) was in one of the Strategies only, so I never really thought of that being the culprit.

    #210973

    Perhaps, I will replace the defined variables with recognized terminology or code and the defined numbers with actual numbers and see what happens…? It remains a bit of a head scratcher the code is so simple?

    #210974

    I have simplified strategy number 1, will run it and see what happens: (the insert code button was not available fir this post so I just pasted it in below)

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated

    Possize = 1

    // Time management
    Ctime = time >= 10000 and time < 220000

    // Identify the cross over piont using the moving averages
    crossover = 0
    if Average[10](close) > Average[80](close) and Average[10](close)[1] < Average[80](close)[1] Then
    crossover = barindex // moving average crossover occurred = store the barindex
    Endif

    // Use the cross over signal and RSI value to determine the entry price
    if Ctime and barindex-crossover <= 5 and crossover > 0 Then //crossover occured less than 5 bars ago
    if rsi[1](close) < 30 Then
    Buy Possize contract at market
    crossover = 0 //reset and prevent next order with same crossover
    LE = 0
    Endif
    Endif

    // Stops and targets
    SET STOP pLOSS 180
    SET TARGET pPROFIT 250

    #210981

    Hi Roberto, strategy 2 just got rejected on Wall Street Cash :

    // Definition of code parameters
    DEFPARAM CumulateOrders = False // Cumulating positions deactivated

    // Position Management

    Possize = 1

    // Time management
    Ctime = time >= 10000 and time < 220000

    // Define the lengths of the moving averages and RSI indicator
    maLength1 = 10
    maLength2 = 80
    rsiLength = 1

    // Calculate the moving averages and RSI value
    ma1 = Average[maLength1](close)
    ma2 = Average[maLength2](close)
    nrsi = rsi[rsiLength](close)

    // Condition to buy
    if Ctime and ma1 > ma2 and nrsi < 30 Then
    Buy Possize contract at market
    Endif

    // Stops and targets
    SET STOP pLOSS 180
    SET TARGET pPROFIT 250

    #210996

    Strategy #1 and #2 both were stopped.

    I can’t understand why as I can’t spot any undefined variables, nor can I spot wrong period numbers!

    I will run them again letting the entry code be executed only after maLength2 bars, but even this should not be an issue, owing to a default 2K preloaded bars.

     

    #210997

    This modified Strategy #2 entered a Long trade, Dax 5€ 5min-TF, with no errors reported:

    #210998

    Thanks Roberto for trying it is a mystery….!

    #210999

    Thanks I will test modified strategy # 2 on Wall Street and see what happens…

Viewing 15 posts - 1 through 15 (of 36 total)

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