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 - 16 through 30 (of 36 total)
  • #211002
    JS

    Hi Johann,

    I see that in your code (first and second strategy) you use an RSI with a period of 1.

    An RSI with a period of 1 only “looks” at the last bar so the RSI will then be either 0 or 100, other values with a period of 1 are not possible…

    It could be that the “division by zero” comes from here…

    (xRS = xUp / xDown where xDown=0)

    So, it makes no sense to check in your code whether nrsi < 30 because nrsi = 0 or nrsi=100

    1 user thanked author for this post.
    #211004

    Well spotted JS, that’s why using if BarIndex > maLength2 then made it work.

    Despite the RSI is calculated BEFORE that line, BUY is executed AFTER that line. So this means that ProBulder might have a check to prevent a division by zero error, while ProOrder may not.

     

    1 user thanked author for this post.
    #211005

    Still what happened to Strategy #3 is a mystery.

     

    #211007

    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).

    Maybe this helps.
    🙁

    1 user thanked author for this post.
    #211012

    Thanks JS and Peter ST, yes I was also wondering about that but it seems as if it is not a problem. I just had a trade with the RSI value as 1 and the trade is fine so far I will have to see if remains ok I have had situations where the position was opened just to be stopped prematurely because of the error. If this happens again then the only thing left after eliminating all the other probabilities will indeed be the RSI. Thanks for the help.

    #211013

    Thanks Roberto, I have changed the code and had a trade and so far it seems ok. Will do some more testing …

    #211014

    I will keep on trying to figure out strategy # 3 by maybe simplifying it some how and start to eliminate some variables to see if I can figure out what is causing the error…

    #211023

    Strategy #2 with Roberto’s modification – if BarIndex > maLength2 then –  also stopped. So it must be RSI[1] which causes all the commotion. Thanks PeterST and JS for pointing that out. I am running them now with RSI[2] and will see what happens. I am also running one strategy with RSI[1] to make double sure that there are no other variables but will let you know.

    1 user thanked author for this post.
    #211025

    But your Strategy #3 does not contain the RSI(1), right ?
    And that fails too (or ?).

    For some longer now I am thinking of a possible error on the 5 minute TF. Or … or that you possibly don’t post the full code. But assumed you do, can you please export the last one which went wrong per means of its exported .itf file ?

    #211038

    Yes it is strange. It is the full code and I will attach the file.

    #211041

    I am a little bit in doubt with strategy # 3. I think after I have simplified it by making use of the actual indicators instead of CALL instructions it might actually be ok. I am testing it now to see if it stops?

    #211053

    I too can’t see anything wrong with it. Not even with lengths vs lenghts.

    All what can get to zero is allowed to be zero (as far as I checked).

    The possible solution could be to hand this to the PRT development team by means of making a Technical Report (Via Help – Help Center – and allow hem to look at the offending code – you will see a question about that once you choose for “Autotrading” in there). Notice, however, that this will end up with IG at first, and they won’t know what to do with it and the process will be long-winded (if it ever gets somewhere).
    Maybe @Nicolas can be of service ?

    Difficult …

    #211075

    What i’m sure of is RSI[1] is not working and will return an error in any case.

    Be sure to check if you are not trying to calculate indicatos while values are missing (possibly during the night), enclose indicators calculation into time conditions. Also, when Volume is equal to 0, zero divide can happen (I have not checked your code to see if you are using volumes or not).

     

    1 user thanked author for this post.
    #211614

    Hi Nicolas, with everybody’s help I have sorted the 3 strategies they seem to be ok now. I am working on a 4th one which get stopped and I noticed you have referred to the problem when Volume = 0 and I think this is my problem with this strategy how can I change this code to bypass the stoppage? Thank you in advance.

    DEFPARAM CumulateOrders = False // Cumulating positions deactivated

    Possize = 2

    Ctime = time >= 10000 and time < 220000

    // Define the lengths of the averages and RSI indicator

    BuyAvgLenght = 16
    SellAvgLenght = 6
    rsiLength = 2
    nrsi = rsi[rsiLength](close)

    // Calculate Buy Averages

    VolB=0

    If (Close > Open) or (Open = Close and Close – Low >= High – Close) Then
    VolB = VolB + Volume
    Endif

    TotBuyVol = VolB
    TotBuyPrice = Close * TotBuyVol

    NetTotBuyprice = summation[BuyAvgLenght](TotBuyPrice)
    NetTotBuyVol = summation[BuyAvgLenght](VolB)

    BuyAvg = NetTotBuyprice/NetTotBuyVol

    // Calculate Sell Averages

    VolS=0

    If (Close < Open) or (Open = Close and Close – Low =< High – Close) Then
    VolS = VolS + Volume
    Endif

    TotSellVol = VolS
    TotSellPrice = Close * TotSellVol

    NetTotSellprice = summation[SellAvgLenght](TotSellPrice)
    NetTotSellVol = summation[SellAvgLenght](VolS)

    SellAvg = NetTotSellprice/NetTotSellVol

    // Conditions
    if Ctime and (BuyAvg < SellAvg and BuyAvg[1] > SellAvg[1]) Then
    if nrsi < 30 Then
    Buy Possize contract at market
    Endif
    Endif

    // Stops and targets
    SET STOP pLOSS 170
    SET TARGET pPROFIT 210

    #211646

    Hi Nicolas, I noticed that the volume is zero during a certain time in my time zone (gmt +2). Do you have code I can use in my strategy not to calculate during those times?

Viewing 15 posts - 16 through 30 (of 36 total)

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