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/03/2023 at 1:07 PM #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)1234567891011121314151617181920212223242526272829303132333435// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Position ManagementPossize = 1Ctime = time >= 10000 and time < 220000// Define the lengths of the moving averages and RSI indicatormaLength1 = 10maLength2 = 80rsiLength = 1// Calculate the moving averages and RSI valuema1 = Average[maLength1](close)ma2 = Average[maLength2](close)nrsi = rsi[rsiLength](close)// Identify the cross over using the moving averagescrossover = 0if ma1 > ma2 and ma1[1] < ma2[1] Thencrossover = barindex // moving average crossover occurred = store the barindexEndif// Use the cross over signal and RSI value to determine the entry priceif Ctime and ma1 > ma2 and barindex-crossover <= 5 and crossover>0 Then //crossover occured less than 5 bars agoif nrsi < 30 ThenBuy Possize contract at marketcrossover = 0 //reset and prevent next order with same crossoverEndifEndif// Stops and targetsSET STOP pLOSS 180SET TARGET pPROFIT 25012345678910111213141516171819202122232425262728// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Position ManagementPossize = 1// Time managementCtime = time >= 10000 and time < 220000// Define the lengths of the moving averages and RSI indicatormaLength1 = 10maLength2 = 80rsiLength = 1// Calculate the moving averages and RSI valuema1 = Average[maLength1](close)ma2 = Average[maLength2](close)nrsi = rsi[rsiLength](close)// Condition to buyif Ctime and ma1 > ma2 and nrsi < 30 ThenBuy Possize contract at marketEndif// Stops and targetsSET STOP pLOSS 180SET TARGET pPROFIT 250123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263If a < 30 Then // trendreversalupWeight = 1Elsif a > 30 Then // trendreversaldownWeight = 0EndifIf b < 20 Then // trendreversalupWeight = 1Elsif b > 20 Then // trendreversaldownWeight = 0EndifIf c > d Then // directionupWeight = 1Elsif c < d Then // directiondownWeight = 0EndifIf e > f Then // directionupWeight = 1Elsif e < f Then // directiondownWeight = 0EndifIf g < -80 Then // trendreversalupWeight = 1Elsif g > -20 ThenWeight = 0 // trendreversaldownEndifIf i < -100 Then // trendreversalupWeight = 1Elsif i > 100 ThenWeight = 0 // trendreversaldownEndifIf j = 1 Then // trendreversalupWeight = 1Elsif j = -1 ThenWeight = 0 // trendreversaldownEndifIf k = 1 Then // trendreversalupWeight = 1Elsif k = -1 Then // trendreversaldownWeight = 0EndifIf l[6] < l[5] and l[5] < l[4] and l[4] < l[3] and l[3] < l[2] and l[2] < l[1] and l[1] < l Then // directionupWeight = 1Elsif l[6] > l[5] and l[5] > l[4] and l[4] > l[3] and l[3] > l[2] and l[2] > l[1] and l[1] > l Then // directiondownWeight = 0EndifIf m[6] < m[5] and m[5] < m[4] and l[4] < m[3] and m[3] < m[2] and m[2] < m[1] and m[1] < m Then // directionupWeight = 1Elsif m[6] > m[5] and m[5] > m[4] and m[4] > m[3] and m[3] > m[2] and m[2] > m[1] and m[1] > m Then // directiondownWeight = 0EndifTrendDirV2 = Summation[n](Weight)AvgTrendDirV2 = Average[AvgTrendLenght](TrendDirV2)nrsi = rsi[rsiLength](close)//graph TrendDirV2if Ctime and TrendDirV2 crosses over AvgTrendDirV2 and nrsi < 30 ThenBuy Possize contract at marketEndif// Stops and targetsSET STOP pLOSS 180SET TARGET pPROFIT 25003/03/2023 at 1:10 PM #210856Apologies I see I missed a part of the 3rd strategy, here it is:
The complete 3rd strategy12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091DEFPARAM CumulateOrders = False // Cumulating positions deactivatedPossize = 1Ctime = time >= 10000 and time < 220000// Define the lengths of the moving averages and RSI indicatorrsiLength = 8TrendLenght = 2AvgTrendLenght = 2n = 16a = RSI[n](close)//OBOSb = Stochastic[9,6](close)//OBOSc = MACDline[20,30,n](close)//DIRd = MACDSignal[20,30,n](close)//DIRe = DIplus[n](close)//DIRf = DIminus[n](close)//DIRg = Williams[n](close)//OBOSi = CCI[n](close)//OBOSj = DivergenceCCI[n,-100,100,n]//OBOSk = DivergenceRSI[n,30,70,n](close)//OBOVl = Average[7](CCI[n](close))//DIRm = Average[14](close)//DIRWeight = 0If a < 30 Then // trendreversalupWeight = 1Elsif a > 30 Then // trendreversaldownWeight = 0EndifIf b < 20 Then // trendreversalupWeight = 1Elsif b > 20 Then // trendreversaldownWeight = 0EndifIf c > d Then // directionupWeight = 1Elsif c < d Then // directiondownWeight = 0EndifIf e > f Then // directionupWeight = 1Elsif e < f Then // directiondownWeight = 0EndifIf g < -80 Then // trendreversalupWeight = 1Elsif g > -20 ThenWeight = 0 // trendreversaldownEndifIf i < -100 Then // trendreversalupWeight = 1Elsif i > 100 ThenWeight = 0 // trendreversaldownEndifIf j = 1 Then // trendreversalupWeight = 1Elsif j = -1 ThenWeight = 0 // trendreversaldownEndifIf k = 1 Then // trendreversalupWeight = 1Elsif k = -1 Then // trendreversaldownWeight = 0EndifIf l[6] < l[5] and l[5] < l[4] and l[4] < l[3] and l[3] < l[2] and l[2] < l[1] and l[1] < l Then // directionupWeight = 1Elsif l[6] > l[5] and l[5] > l[4] and l[4] > l[3] and l[3] > l[2] and l[2] > l[1] and l[1] > l Then // directiondownWeight = 0EndifIf m[6] < m[5] and m[5] < m[4] and l[4] < m[3] and m[3] < m[2] and m[2] < m[1] and m[1] < m Then // directionupWeight = 1Elsif m[6] > m[5] and m[5] > m[4] and m[4] > m[3] and m[3] > m[2] and m[2] > m[1] and m[1] > m Then // directiondownWeight = 0EndifTrendDirV2 = Summation[n](Weight)AvgTrendDirV2 = Average[AvgTrendLenght](TrendDirV2)nrsi = rsi[rsiLength](close)//graph TrendDirV2if Ctime and TrendDirV2 crosses over AvgTrendDirV2 and nrsi < 30 ThenBuy Possize contract at marketEndif// Stops and targetsSET STOP pLOSS 180SET TARGET pPROFIT 25003/04/2023 at 11:20 AM #210874I 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.
03/05/2023 at 7:11 AM #21091003/05/2023 at 7:24 AM #21091103/05/2023 at 8:00 AM #210923Johann,
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.
03/06/2023 at 7:46 AM #210966Thanks 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 …?
03/06/2023 at 8:13 AM #210971If 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.03/06/2023 at 8:29 AM #21097303/06/2023 at 8:37 AM #210974I 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 deactivatedPossize = 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 25003/06/2023 at 9:23 AM #210981Hi 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 25003/06/2023 at 4:24 PM #210996Strategy #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.
03/06/2023 at 4:31 PM #210997This modified Strategy #2 entered a Long trade, Dax 5€ 5min-TF, with no errors reported:
12345678910111213141516171819202122232425262728// Definition of code parametersDEFPARAM CumulateOrders = False // Cumulating positions deactivated// Position ManagementPossize = 1// Time managementCtime = time >= 010000 and time < 220000 //010000 instead of 10000 ???// Define the lengths of the moving averages and RSI indicatormaLength1 = 10maLength2 = 80rsiLength = 1// Calculate the moving averages and RSI valuema1 = Average[maLength1](close)ma2 = Average[maLength2](close)nrsi = rsi[rsiLength](close)if BarIndex > maLength2 then //wait for enough bars to be elapsed ???// Condition to buyif Ctime and ma1 > ma2 and nrsi < 30 ThenBuy Possize contract at marketEndifendif// Stops and targetsSET STOP pLOSS 180SET TARGET pPROFIT 25003/06/2023 at 4:33 PM #21099803/06/2023 at 4:38 PM #210999 -
AuthorPosts
Find exclusive trading pro-tools on