Division by zero ERROR
Forums › ProRealTime English forum › ProOrder support › Division by zero ERROR
- This topic has 19 replies, 6 voices, and was last updated 3 years ago by GraHal.
-
-
06/08/2020 at 5:33 PM #13522006/08/2020 at 6:33 PM #135225
Hope you don’t mind … code is below so that the wizards can see if they can spot anything to produce the divide by zero error.
Is below similar to / a copy off here or your own code?
How often are you getting the error and when?
Is it when you try to start the System on Pro-Order or at random times?
Has the System taken any trades at all on ProOrder / Auto-Trading??
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330// ALLEMAGNE 30// H1DEFPARAM CumulateOrders = False// TAILLE DES POSITIONSN = 1TIMEFRAME (60 MINUTES, UPDATEONCLOSE)c7 = Average[50] > Average[50][1]//c10 = Average[50] < Average[50][1]TIMEFRAME (10 MINUTES, UPDATEONCLOSE)indicator11 = Stochastic[14,3](close) //Stabilare men mindre returnsc14 = (indicator11 > 95)TIMEFRAME (Default)// Donchian// Pour le DAX :V = 7V = ValueX//ONCE Profitablecloses = 80//ONCE Profx = 0//DonchianSupV = highest[V](high)DonchianInfV = lowest[V](low)indicator1, ignored, ignored, ignored, ignored, ignored, ignored = CALL "VWAP BAND SOM FUNKAR"// ACHATc2 = close crosses under DonchianInfV[1]c1 = (close > indicator1)//c5 = close[3] < indicator1//c6 = RSI[10] > 85 // mer returns men mer risk//indicator3, ignored, ignored, ignored, ignored, ignored, ignored, ignored = CALL "M-Oscillator"//c6 = (indicator3 >= 12)IF c1 and c2 and c7 THENbuy N shares at market//Profx = 0ENDIFset stop $loss ValueY//IF LONGONMARKET and close[0] >= TRADEPRICE then//profx = profx + 1//ENDIF////IF profx >= profitablecloses THEN//SELL AT MARKET//ENDIFIF longonmarket and C14 THENsell at marketendif//// VENTE//c3 = close crosses under DonchianSupV[1]//c11 = (close < indicator1)//c12 = RSI[14] < 30//////IF c10 and c11 and c3 THEN//sellshort N shares at market//ENDIF////if shortonmarket and c12 then//exitshort at market//endif//period1=7//period2=14HeuristicsCycleLimit = 2once HeuristicsCycle = 0once HeuristicsAlgo1 = 1once HeuristicsAlgo2 = 0If HeuristicsCycle >= HeuristicsCycleLimit ThenIf HeuristicsAlgo1 = 1 ThenHeuristicsAlgo2 = 1HeuristicsAlgo1 = 0ElsIf HeuristicsAlgo2 = 1 ThenHeuristicsAlgo1 = 1HeuristicsAlgo2 = 0EndIfHeuristicsCycle = 0EndIf////If HeuristicsAlgo1 = 1 Then//Heuristics Algorithm 1 StartIf (onmarket[1] = 1 and onmarket = 0) or (longonmarket[1] = 1 and longonmarket and countoflongshares < countoflongshares[1]) or (longonmarket[1] = 1 and longonmarket and countoflongshares > countoflongshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares < countofshortshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares > countofshortshares[1]) or (longonmarket[1] and shortonmarket) or (shortonmarket[1] and longonmarket) Thenoptimize = optimize + 1EndIfStartingValue = 22 //5ResetPeriod = 3 //Specify no of months after which to reset optimizationIncrement = 1MaxIncrement = 6 //3 //Limit of no of increments either up or downReps = 3 //Number of trades to use for analysisMinValue = 1 //Minimum allowed valueMaxValue = 30 //Maximum allowed valueIf monthinit = 1 or monthinit = 3 or monthinit = 5 or monthinit = 7 or monthinit = 8 or monthinit = 10 or monthinit = 12 ThenMonthDays = 31ElsIf monthinit = 4 or monthinit = 6 or monthinit = 9 or monthinit = 11 ThenMonthDays = 30ElsIf monthinit = 2 ThenIf (yearinit/4 = round(yearinit/4)) or (yearinit/400 = round(yearinit/400)) Then //haha not sure how exactly to do thisMonthDays = 29 //leap yearElseMonthDays = 28EndIfEndIfIf (month = monthinit and day = dayinit + ResetPeriod) or (month = monthinit + 1 and (day + (MonthDays - dayinit)) >= ResetPeriod) ThenValueX = StartingValueWinCountB = 0StratAvgB = 0BestA = 0BestB = 0dayinit = daymonthinit = monthyearinit = yearEndIfonce ValueX = StartingValueonce PIncPos = 1 //Positive Increment Positiononce NIncPos = 1 //Neative Increment Positiononce Optimize = 0 ////Initialize Heuristicks Engine Counter (Must be Incremented at Position Start or Exit)once Mode = 1 //Switches between negative and positive increments//once WinCountB = 3 //Initialize Best Win Count//GRAPH WinCountB coloured (0,0,0) AS "WinCountB"//once StratAvgB = 4353 //Initialize Best Avg Strategy Profit//GRAPH StratAvgB coloured (0,0,0) AS "StratAvgB"If Optimize = Reps ThenWinCountA = 0 //Initialize current Win CountStratAvgA = 0 //Initialize current Avg Strategy ProfitHeuristicsCycle = HeuristicsCycle + 1For i = 1 to Reps DoIf positionperf(i) > 0 ThenWinCountA = WinCountA + 1 //Increment Current WinCountEndIfStratAvgA = StratAvgA + (((PositionPerf(i)*countofposition[i]*100000)*-1)*-1)NextStratAvgA = StratAvgA/Reps //Calculate Current Avg Strategy Profit//Graph (PositionPerf(1)*countofposition[1]*100000)*-1 as "PosPerf1"//Graph (PositionPerf(2)*countofposition[2]*100000)*-1 as "PosPerf2"//Graph StratAvgA*-1 as "StratAvgA"//once BestA = 300//GRAPH BestA coloured (0,0,0) AS "BestA"If StratAvgA >= StratAvgB ThenStratAvgB = StratAvgA //Update Best Strategy ProfitBestA = ValueXEndIf//once BestB = 300//GRAPH BestB coloured (0,0,0) AS "BestB"If WinCountA >= WinCountB ThenWinCountB = WinCountA //Update Best Win CountBestB = ValueXEndIfIf WinCountA > WinCountB and StratAvgA > StratAvgB ThenMode = 0ElsIf WinCountA < WinCountB and StratAvgA < StratAvgB and Mode = 1 ThenValueX = ValueX - (Increment*NIncPos)NIncPos = NIncPos + 1Mode = 2ElsIf WinCountA >= WinCountB or StratAvgA >= StratAvgB and Mode = 1 ThenValueX = ValueX + (Increment*PIncPos)PIncPos = PIncPos + 1Mode = 1ElsIf WinCountA < WinCountB and StratAvgA < StratAvgB and Mode = 2 ThenValueX = ValueX + (Increment*PIncPos)PIncPos = PIncPos + 1Mode = 1ElsIf WinCountA >= WinCountB or StratAvgA >= StratAvgB and Mode = 2 ThenValueX = ValueX - (Increment*NIncPos)NIncPos = NIncPos + 1Mode = 2EndIfIf NIncPos > MaxIncrement or PIncPos > MaxIncrement ThenIf BestA = BestB ThenValueX = BestAElseIf reps >= 10 ThenWeightedScore = 10ElseWeightedScore = round((reps/100)*100)EndIfValueX = round(((BestA*(20-WeightedScore)) + (BestB*WeightedScore))/20) //Lower Reps = Less weight assigned to Win%EndIfNIncPos = 1PIncPos = 1ElsIf ValueX > MaxValue ThenValueX = MaxValueElsIf ValueX < MinValue ThenValueX = MinValueEndIFOptimize = 0EndIf// Heuristics Algorithm 1 End//ElsIf HeuristicsAlgo2 = 1 Then//Heuristics Algorithm 2 StartIf (onmarket[1] = 1 and onmarket = 0) or (longonmarket[1] = 1 and longonmarket and countoflongshares < countoflongshares[1]) or (longonmarket[1] = 1 and longonmarket and countoflongshares > countoflongshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares < countofshortshares[1]) or (shortonmarket[1] = 1 and shortonmarket and countofshortshares > countofshortshares[1]) or (longonmarket[1] and shortonmarket) or (shortonmarket[1] and longonmarket) Thenoptimize2 = optimize2 + 1EndIfStartingValue2 = 60ResetPeriod2 = 3 //Specify no of months after which to reset optimizationIncrement2 = 1MaxIncrement2 = 44 //Limit of no of increments either up or downReps2 = 3 //Number of trades to use for analysisMinValue2 = 84 //Minimum allowed valueMaxValue2 = 78 //Maximum allowed valueIf monthinit2 = 1 or monthinit2 = 3 or monthinit2 = 5 or monthinit2 = 7 or monthinit2 = 8 or monthinit2 = 10 or monthinit2 = 12 ThenMonthDays2 = 31ElsIf monthinit2 = 4 or monthinit2 = 6 or monthinit2 = 9 or monthinit2 = 11 ThenMonthDays2 = 30ElsIf monthinit2 = 2 ThenIf (yearinit2/4 = round(yearinit2/4)) or (yearinit2/400 = round(yearinit2/400)) Then //haha not sure how exactly to do thisMonthDays2 = 29 //leap yearElseMonthDays2 = 28EndIfEndIfIf (month = monthinit2 and day = dayinit2 + ResetPeriod2) or (month = monthinit2 + 1 and (day + (MonthDays2 - dayinit2)) >= ResetPeriod2) ThenValueY = StartingValue2WinCountB2 = 0StratAvgB2 = 0BestA2 = 0BestB2 = 0dayinit2 = daymonthinit2 = monthyearinit2 = yearEndIfonce ValueY = StartingValue2once PIncPos2 = 1 //Positive Increment Positiononce NIncPos2 = 1 //Neative Increment Positiononce Optimize2 = 0 ////Initialize Heuristicks Engine Counter (Must be Incremented at Position Start or Exit)once Mode2 = 1 //Switches between negative and positive increments//once WinCountB2 = 3 //Initialize Best Win Count//GRAPH WinCountB2 coloured (0,0,0) AS "WinCountB2"//once StratAvgB2 = 4353 //Initialize Best Avg Strategy Profit//GRAPH StratAvgB2 coloured (0,0,0) AS "StratAvgB2"If Optimize2 = Reps2 ThenWinCountA2 = 0 //Initialize current Win CountStratAvgA2 = 0 //Initialize current Avg Strategy ProfitHeuristicsCycle = HeuristicsCycle + 1For i2 = 1 to Reps2 DoIf positionperf(i) > 0 ThenWinCountA2 = WinCountA2 + 1 //Increment Current WinCountEndIfStratAvgA2 = StratAvgA2 + (((PositionPerf(i)*countofposition[i]*100000)*-1)*-1)NextStratAvgA2 = StratAvgA2/Reps2 //Calculate Current Avg Strategy Profit//Graph (PositionPerf(1)*countofposition[1]*100000)*-1 as "PosPerf1-2"//Graph (PositionPerf(2)*countofposition[2]*100000)*-1 as "PosPerf2-2"//Graph StratAvgA2*-1 as "StratAvgA2"//once BestA2 = 300//GRAPH BestA2 coloured (0,0,0) AS "BestA2"If StratAvgA2 >= StratAvgB2 ThenStratAvgB2 = StratAvgA2 //Update Best Strategy ProfitBestA2 = ValueYEndIf//once BestB2 = 300//GRAPH BestB2 coloured (0,0,0) AS "BestB2"If WinCountA2 >= WinCountB2 ThenWinCountB2 = WinCountA2 //Update Best Win CountBestB2 = ValueYEndIfIf WinCountA2 > WinCountB2 and StratAvgA2 > StratAvgB2 ThenMode = 0ElsIf WinCountA2 < WinCountB2 and StratAvgA2 < StratAvgB2 and Mode2 = 1 ThenValueY = ValueY - (Increment2*NIncPos2)NIncPos2 = NIncPos2 + 1Mode2 = 2ElsIf WinCountA2 >= WinCountB2 or StratAvgA2 >= StratAvgB2 and Mode2 = 1 ThenValueY = ValueY + (Increment2*PIncPos2)PIncPos2 = PIncPos2 + 1Mode = 1ElsIf WinCountA2 < WinCountB2 and StratAvgA2 < StratAvgB2 and Mode2 = 2 ThenValueY = ValueY + (Increment2*PIncPos2)PIncPos2 = PIncPos2 + 1Mode2 = 1ElsIf WinCountA2 >= WinCountB2 or StratAvgA2 >= StratAvgB2 and Mode2 = 2 ThenValueY = ValueY - (Increment2*NIncPos2)NIncPos2 = NIncPos2 + 1Mode2 = 2EndIfIf NIncPos2 > MaxIncrement2 or PIncPos2 > MaxIncrement2 ThenIf BestA2 = BestB2 ThenValueY = BestAElseIf reps2 >= 10 ThenWeightedScore2 = 10ElseWeightedScore2 = round((reps2/100)*100)EndIfValueY = round(((BestA2*(20-WeightedScore2)) + (BestB2*WeightedScore2))/20) //Lower Reps = Less weight assigned to Win%EndIfNIncPos2 = 1PIncPos2 = 1ElsIf ValueY > MaxValue2 ThenValueY = MaxValue2ElsIf ValueY < MinValue2 ThenValueY = MinValue2EndIFOptimize2 = 0EndIf// Heuristics Algorithm 2 End06/08/2020 at 6:42 PM #135227The code below looks like it may be a possible source of divide by zero??
1(yearinit/4 = round(yearinit/4)) or (yearinit/400 = round(yearinit/400))1 user thanked author for this post.
06/08/2020 at 6:48 PM #135228Try also changing line 17 to:
1V = max(1,ValueX)Try moving line 25 BEFORE the expression highlighted by GraHal, this might cause assign a correct value to yearinit before it’s evaluated.
06/08/2020 at 6:56 PM #135229You may want to do some research / reading back over Topics from which you got the ML parts of your code because below has been discussed and it is flawed re the i2 (see my comment below).
12345For i2 = 1 to Reps2 DoIf positionperf(i) > 0 ThenWinCountA2 = WinCountA2 + 1 //Increment Current WinCountEndIfStratAvgA2 = StratAvgA2 + (((PositionPerf(i)*countofposition[i]*100000)*-1)*-1)should be as below (3 instances of i that should be i2)
12345For i2 = 1 to Reps2 DoIf positionperf(i2) > 0 ThenWinCountA2 = WinCountA2 + 1 //Increment Current WinCountEndIfStratAvgA2 = StratAvgA2 + (((PositionPerf(i2)*countofposition[i2]*100000)*-1)*-1)06/08/2020 at 7:04 PM #13523106/08/2020 at 7:08 PM #13523306/08/2020 at 8:05 PM #135236Yeah I recall same issue when I was involved with the ML code … best to read over any suggestions already made for a fix?
But that i2 is flawed anyway as the code states
1For i2 = 1 to Reps2 Dobut the code doesn’t have an i2 (it has i but not i2).
The result is crosstalk / cross referring of values between the ValueX code and the ValueY code.
06/08/2020 at 8:08 PM #135237I have cleaned up the code now, and now it gives me a new error; “The trading system was stopped because it encountered an error. please send us a report to enable us to analyze the error….
this is the code wich gave the error
12345678910111213141516171819202122232425262728// ALLEMAGNE 30DEFPARAM CumulateOrders = FalseTIMEFRAME (60 MINUTES, UPDATEONCLOSE)c7 = Average[50] > Average[50][1]TIMEFRAME (10 MINUTES, UPDATEONCLOSE)indicator11 = Stochastic[14,3](close)c14 = (indicator11 > 95)TIMEFRAME (Default)// DonchianV = 23DonchianInfV = lowest[V](low)indicator1, ignored, ignored, ignored, ignored, ignored, ignored = CALL "VWAP BAND SOM FUNKAR"c2 = close crosses under DonchianInfV[1]c1 = (close > indicator1)IF c1 and c2 and c7 THENbuy 1 shares at marketENDIFset stop $loss 90IF longonmarket and C14 THENsell at marketendif06/08/2020 at 8:09 PM #135238Here you are … a good one to start with … JuanJ is the Author of the ML code!
https://www.prorealcode.com/topic/division-by-zero-error-solved/
and another
06/08/2020 at 8:23 PM #135240it gives me a new error
When … Is it when you try to start the System on Pro-Order or at random times?
Also did you see the suggestion made higher up by Roberto … I only just noticed it.
06/08/2020 at 8:27 PM #13524106/08/2020 at 8:37 PM #13524206/08/2020 at 9:22 PM #13524706/09/2020 at 7:47 AM #135258 -
AuthorPosts
Find exclusive trading pro-tools on