Backtest fonctionne OK, mais division par zéro en trading réel
Forums › ProRealTime forum Français › Support ProBuilder › Backtest fonctionne OK, mais division par zéro en trading réel
- This topic has 4 replies, 2 voices, and was last updated 4 years ago by Khaled.
-
-
10/22/2020 at 12:44 AM #148038
Bonjour, J’ai testé le code ci-dessous trouvé sur ce site et alors que le backtest fonctionne correctement, en réel le trading s’arrête en affichant le message d’erreur (copie d’écran ci-dessous) “division par zéro lors de l’évaluation du dernier chandelier”. Pourriez-vous m’aider à trouver d’où vient l’erreur dans le code?
Merci
Renko 1M ML2 v4b123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302//-------------------------------------------------------------------------//main code : Paul/Bard Renko 1M ML2 v4b machine learning (ml2)MLx2 applied to Long and Short Boxsize//https://www.prorealcode.com/topic/machine-learning-in-proorder/page/3/#post-121130//-------------------------------------------------------------------------//https://www.prorealcode.com/topic/why-is-backtesting-so-unreliable/#post-110889//definition of code parametersdefparam cumulateorders = false // cumulating positions deactivateddefparam preloadbars = 1000//once mode = 0//1 // [0] with minimum distance stop; [1] without//once minstopdistance = 20//once percentage = 0 // [1] percentage; [0] points//Money Management//Capital = 10000 + strategyprofit //Current profit made by the closed trades of the running strategy.N = 1//30*Capital / Closeheuristicscyclelimit = 2once heuristicscycle = 0once heuristicsalgo1 = 1once heuristicsalgo2 = 0if heuristicscycle >= heuristicscyclelimit thenif heuristicsalgo1 = 1 thenheuristicsalgo2 = 1heuristicsalgo1 = 0elsif heuristicsalgo2 = 1 thenheuristicsalgo1 = 1heuristicsalgo2 = 0endifheuristicscycle = 0elseonce valuex = startingvalueonce valuey = startingvalue2endifif 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) thenoptimise = optimise + 1endif//Settings 1 & 2startingvalue = 40 //5, 100, 10 //LONG BOXSIZEResetPeriod = 3 //1, 0.5 Specify no of months after which to reset optimisationincrement = 10 //5, 20, 10maxincrement = 20 //5, 10 limit of no of increments either up or downreps = 3 //1 number of trades to use for analysis //2maxvalue = 50 //50, 20, 300, 150 //maximum allowed valueminvalue = increment //15, 5, minimum allowed valuestartingvalue2 = 40 //5, 100, 50 //SHORT BOXSIZEResetPeriod2 = 3 //1, 0.5 Specify no of months after which to reset optimisationincrement2 = 10 //5, 10maxincrement2 = 20 //1, 30 limit of no of increments either up/down //4reps2 = 3 //1, 2 nos of trades to use for analysis //3maxvalue2 = 50 //50, 20, 300, 200 maximum allowed valueminvalue2 = increment //15, 5, minimum allowed valueonce monthinit = monthonce yearinit = yearIf (year = yearinit and month = (monthinit + ResetPeriod)) or (year = (yearinit + 1) and ((12 - monthinit) + month = ResetPeriod)) ThenValueX = StartingValueWinCountB = 0StratAvgB = 0BestA = 0BestB = 0monthinit = monthyearinit = yearEndIfonce valuex = startingvalueonce pincpos = 1 //positive increment positiononce nincpos = 1 //negative increment positiononce optimise = 0 //initialize heuristicks engine counter (must be incremented at position start or exit)once mode1 = 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 optimise = 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]*close)*-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 thenmode1 = 0elsif wincounta < wincountb and stratavga < stratavgb and mode1 = 1 thenvaluex = valuex - (increment*nincpos)nincpos = nincpos + 1mode1 = 2elsif wincounta >= wincountb or stratavga >= stratavgb and mode1 = 1 thenvaluex = valuex + (increment*pincpos)pincpos = pincpos + 1mode1 = 1elsif wincounta < wincountb and stratavga < stratavgb and mode1 = 2 thenvaluex = valuex + (increment*pincpos)pincpos = pincpos + 1mode1 = 1elsif wincounta >= wincountb or stratavga >= stratavgb and mode1 = 2 thenvaluex = valuex - (increment*nincpos)nincpos = nincpos + 1mode1 = 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 = minvalueendifoptimise = 0endif// heuristics algorithm 1 endelsif 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) thenoptimise2 = optimise2 + 1endif//Settings 2once monthinit2 = monthonce yearinit2 = yearIf (year = yearinit2 and month = (monthinit2 + ResetPeriod2)) or (year = (yearinit2 + 1) and ((12 - monthinit2) + month = ResetPeriod2)) ThenValueY = StartingValue2WinCountB2 = 0StratAvgB2 = 0BestA2 = 0BestB2 = 0monthinit2 = monthyearinit2 = yearEndIfonce valuey = startingvalue2once pincpos2 = 1 //positive increment positiononce nincpos2 = 1 //negative increment positiononce optimise2 = 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 optimise2 = reps2 thenwincounta2 = 0 //initialize current win countstratavga2 = 0 //initialize current avg strategy profitheuristicscycle = heuristicscycle + 1for i2 = 1 to reps2 doif positionperf(i2) > 0 thenwincounta2 = wincounta2 + 1 //increment current wincountendifstratavga2 = stratavga2 + (((positionperf(i2)*countofposition[i2]*close)*-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 thenmode2 = 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 + 1mode2 = 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 = besta2elseif 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 = minvalue2endifoptimise2 = 0endif// heuristics algorithm 2 endendif//boxsizel = ValueXboxsizes = ValueY//renkomaxl = round(close / boxsizel) * boxsizelrenkominl = renkomaxl - boxsizelrenkomaxs = round(close / boxsizes) * boxsizesrenkomins = renkomaxs - boxsizes//if high > renkomaxl + boxsizel thenrenkomaxl = renkomaxl + boxsizelrenkominl = renkominl + boxsizelendifif low < renkomins - boxsizes thenrenkomaxs = renkomaxs - boxsizesrenkomins = renkomins - boxsizesendif// Conditions to enter long positionsBuy N CONTRACT at renkoMaxL + boxSizeL stop// Conditions to enter short positionsSellshort N CONTRACT at renkoMinS - boxSizeS stop////if percentage then//set stop %loss 0.25 %trailing 0.5//set target %profit 2//elseset stop ptrailing 50 //50 + 100set target pprofit 500//endif10/22/2020 at 9:29 AM #148062Je n’ai pas décelé de valeur nulle dans une division à la première lecture, mais il semble en avoir discuté dans le sujet d’où provient ce code, aurais-tu l’URL ?
Une division par zéro provoque l’arrêt du système quoi qu’il arrive, si cela arrive dés l’envoi de la stratégie dans ProOrder, c’est parce qu’une variable utilisée dans une division n’a pas encore de valeur. Il faut donc relire le code et vérifier que chaque variable utilisée comme diviseur a bien une valeur supérieure à 0 lors de la première lecture du code.
10/22/2020 at 9:46 AM #148065Merci Nicolas, le code vient de https://www.prorealcode.com/reply/128486/
mais pourquoi cela fonctionne-t-il correctement dans le Backtest alors?
j’ai changé les lignes 267 et 268 comme suit et j’ai un Win Rate % qui chute de 80% à 60%. L’Algo n’est plus arrêté par “division à zéro” dans certains TF (pas tous).
123boxsizel = max (ValueX , increment)boxsizes = max (ValueY , increment2)10/22/2020 at 10:05 AM #148068Concernant les performances de l’algo, je ne vais pas pouvoir t’aider, tu devrais en discuter dans le sujet approprié.
ProBacktest n’a pas de problème à exécuter du code avec des erreurs de programmation, contrairement à ProOrder qui lui ne veut te faire prendre aucun risque. Quelle est le but de faire une division par zéro ? 🙂
10/22/2020 at 10:24 AM #148072 -
AuthorPosts
Find exclusive trading pro-tools on