Division by zero parameter error on 3 different strategies
Forums › ProRealTime English forum › ProOrder support › Division by zero parameter error on 3 different strategies
- This topic has 35 replies, 5 voices, and was last updated 1 year ago by Johann.
-
-
03/06/2023 at 5:30 PM #211002
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.
03/06/2023 at 5:42 PM #211004Well 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.
03/06/2023 at 5:45 PM #211005Still what happened to Strategy #3 is a mystery.
03/06/2023 at 6:16 PM #211007Btw, 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.
03/06/2023 at 8:16 PM #211012Thanks 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.
03/06/2023 at 8:18 PM #21101303/06/2023 at 8:21 PM #21101403/07/2023 at 7:12 AM #211023Strategy #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.
03/07/2023 at 9:17 AM #211025But 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 ?
03/07/2023 at 1:17 PM #21103803/07/2023 at 2:17 PM #21104103/07/2023 at 5:40 PM #211053I 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 …
03/08/2023 at 9:31 AM #211075What 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.
03/15/2023 at 8:04 PM #211614Hi 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
EndifTotBuyVol = VolB
TotBuyPrice = Close * TotBuyVolNetTotBuyprice = 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
EndifTotSellVol = VolS
TotSellPrice = Close * TotSellVolNetTotSellprice = 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 21003/16/2023 at 1:41 PM #211646 -
AuthorPosts
Find exclusive trading pro-tools on