protection division pae zero
Forums › ProRealTime forum Français › Support ProOrder › protection division pae zero
- This topic has 4 replies, 3 voices, and was last updated 3 years ago by vschmitt.
-
-
07/28/2021 at 6:04 AM #174274
Bonjour Nicolas
J’utilise un code réalisé par Juan Jacobs “trend breakout” . Celui-ci m’interesse particulièrement car il fonctionne en général très bien sauf que de temps en temps j’ai une erreur de division par zero.
Aurais-tu la possibilité d’y regarder pour peut-être m’écrire le bout de code manquant
Cordialement
jp
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272//-------------------------------------------------------------------------// Code principal : juan final fractal//-------------------------------------------------------------------------//Stategy: Trend Breakout//Author: Juan Jacobs//Market: Neutral//Timezone: UTC +2//Timeframe: 1Hr but not 'completely' timeframe dependantDefparam cumulateorders = Falsedefparam preloadbars = 10000If hour <= 8 or hour >= 22 then //outside market hourspossize = 0If longonmarket Thensell at marketBear = 0Bull = 0Trendbreak = 0optimize = optimize + 1ElsIf shortonmarket Thenexitshort at marketBear = 0Bull = 0Trendbreak = 0optimize = optimize + 1EndIfElsepossize = 1 //position contract sizeEndIf// Heuristics Algorithm Startonce period =8Increment = 1MaxIncrement = 5Reps = 7 //Number of bars to use for analysisonce 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 incrementsonce WinCountB = 0 //Initialize Best Win Countonce StratAvgB = 0 //Initialize Best Avg Strategy ProfitIf Optimize = Reps ThenWinCountA = 0 //Initialize current Win CountStratAvgA = 0 //Initialize current Avg Strategy ProfitFor z = 1 to Reps DoIf positionperf(z) > 0 ThenWinCountA = WinCountA + 1 //Increment Current WinCountEndIfStratAvgA = StratAvgA + StrategyProfit[z]NextStratAvgA = StratAvgA/Reps //Calculate Current Avg Strategy ProfitIf StratAvgA >= StratAvgB ThenStratAvgB = StratAvgA //Update Best Strategy ProfitBestA = PeriodEndIfIf WinCountA >= WinCountB ThenWinCountB = WinCountB //Update Best Win CountBestB = PeriodEndIfIf WinCountA > WinCountB and StratAvgA > StratAvgB ThenMode = 0ElsIf WinCountA < WinCountB and StratAvgA < StratAvgB and Mode = 1 ThenPeriod = Period - (Increment*NIncPos)NIncPos = NIncPos + IncrementMode = 2ElsIf WinCountA >= WinCountB or StratAvgA >= StratAvgB and Mode = 1 ThenPeriod = Period + (Increment*PIncPos)PIncPos = PIncPos + IncrementMode = 1ElsIf WinCountA < WinCountB and StratAvgA < StratAvgB and Mode = 2 ThenPeriod = Period + (Increment*PIncPos)PIncPos = PIncPos + IncrementMode = 1ElsIf WinCountA > WinCountB or StratAvgA > StratAvgB and Mode = 2 ThenPeriod = Period - (Increment*NIncPos)NIncPos = NIncPos + IncrementMode = 2EndIfIf NIncPos > MaxIncrement or PIncPos > MaxIncrement ThenIf BestA = BestB ThenPeriod = BestAElsePeriod = (BestA+BestB)/2EndIfNIncPos = 1PIncPos = 1EndIFOptimize = 0EndIf// Heuristics Algorithm End//Calculate Fractalonce Trendbreak = 0If Trendbreak = 0 Then //No potential trendbreaks have been identifiedonce FracH = 0 //initialize fractal countonce FracL = 0 //initialize fractal countFor i = 0 to 4 DoIf high[2] > high[i] Then //look for high fractal with 2 lower highs on either sideFracH = FracH + 1EndIfIf low[2] < low[i] Then //look for low fractal with 2 higher lows on either sideFracL = FracL + 1EndIfNextIf FracH = 4 Then //High Fractal IdentifiedIf Bear = 0 and Bull = 0 ThenBear = 1 //Initialize first trend directionEndIfFractalH = high[2] //High Fractal Price LevelLFractalH = low[2] //Low of High FractalIf Bear = 1 ThenFractalP = barindex - 2 //High Fractal Bar PositionEndIfElsIf FracL = 4 Then //Low Fractal IdentifiedIf Bear = 0 and Bull = 0 ThenBull = 1 //Initialize first trend directionEndIfFractalL = low[2] //Low Fractal Price LevelHFractalL = high[2] //High of Low FractalIf Bull = 1 ThenFractalP = barindex - 2 //Low Fractal Bar PositionEndIfEndIfFracH = 0 //reset fractal countFracL = 0 //reset fractal count//Calculate trendline using widest angle from extreme of last fractal to curent extreme (Trigonometry Function)If barindex = FractalP + 2 Then //Initialize angle using 1st candle after fractal candleIf Bear = 1 ThenMaxAngle = Tan(1/(FractalH - high[1])) //Initial value of the angle between the fractal and the last highElsIf Bull = 1 ThenMaxAngle = Tan(1/(low[1]-FractalL)) //Initial value of the angle between the fractal and the last highEndIfEndIfEndIfIf Bear = 1 Then //Down trendHeight = FractalH - high //Calcululate height between high fractal and high of current barHeightB = FractalH - close[1] //Calcululate height between high fractal and close of current bar (used to determine trend violation)ElsIf Bull = 1 Then //Up trendHeight = Low - FractalL //Calcululate height between low fractal and low of current barHeightB = close[1] - FractalL //Calcululate height between high fractal and close of current bar (used to determine trend violation)EndIfIf barindex > FractalP + 2 Then //If current bar greater than end of fractal set:If Bear = 1 Then //For Down TrendIf Trendbreak = 1 and close >= close[1] ThenTrendbreak = 2 //Trend violation confirmed, there was a close outside the trend line (close angle > trend)BreakoutP = Barindex //Breakout positionOrderLevel = LFractalH + (AverageTrueRange[PERIOD](close)*1.618) //Enter into long position at specified price levelPreviousLow = LFractalH //Level to re-initate preious trendElsIf Trendbreak = 1 and close <= open[1] ThenTrendbreak = 0//Trend violation invalidated, latest close did not confirmMaxAngle = TAngle //New max trend as trend break was invalidatedEndIfIf Trendbreak = 0 and (Tan((barindex-FractalP)/Height) > MaxAngle) and close <= open ThenMaxAngle = Tan((barindex-FractalP)/Height) //calculate new max trend if down trend rules are validElsIf Trendbreak = 0 and (Tan((barindex-FractalP)/HeightB) > MaxAngle) and close > open ThenTrendBreak = 1 //Trend violation potentially present, wait for confirmation on close of next barTAngle = Tan((barindex-FractalP)/Height) //Save temporary angle to use if trend violation invalidatedEndIFElsIf Bull = 1 Then //For Up TrendIf Trendbreak = 1 and close <= close[1] ThenTrendbreak = 2 //Trend violation confirmed, there was a close outside the trend line (close angle < trend)BreakoutP = Barindex //Breakout positionOrderLevel = HFractalL - (AverageTrueRange[PERIOD](close)*1.618) //Enter into short position at specified price levelPreviousHigh = HFractalL //Level to re-initiate previous trendElsIf Trendbreak = 1 and close >= open[1] ThenMaxAngle = TAngle //New max trend as trend break was invalidatedTrendbreak = 0EndIfIf Trendbreak = 0 and (Tan((barindex-FractalP)/Height) > MaxAngle) and close >= open ThenMaxAngle = Tan((barindex-FractalP)/Height) //calculate new max trend if up trend rules are validElsIf Trendbreak = 0 and (Tan((barindex-FractalP)/HeightB) > MaxAngle) and close < open ThenTrendBreak = 1 //Trend violation potentially present, wait for confirmation on close of next barTAngle = Tan((barindex-FractalP)/Height) //Save temporary angle to use if trend violation invalidatedEndIfEndIfEndIfIf Trendbreak = 2 Then //Trend violation is confirmed:If Bear = 1 and close > PreviousLow ThenBuy possize contract at OrderLevel stopElsIf Bull = 1 and close < PreviousHigh ThenSellshort possize contract at OrderLevel stopEndIfIf barindex >= BreakoutP ThenIf Bear = 1 and longonmarket Then //If position is opened counter last trend, reset variables and initialize new trendTrendbreak = 0Bear = 0Bull = 1optimize = optimize + 1ElsIf Bear = 1 and close < PreviousLow Then //New trend invalidated and previous trend resumedTrendbreak = 0ElsIf Bull = 1 and shortonmarket Then //If position is opened counter last trend, reset variables and initialize new trendTrendbreak = 0Bear = 1Bull = 0optimize = optimize + 1ElsIf Bull = 1 and close > PreviousHigh Then //New trend invalidated and previous trend resumedTrendbreak = 0EndIfEndIfEndIf//Trade Management (Note that Trend Direction need to be reset with exits's)Deviations = 1.5periods = 32PRICE = LOG(customclose)alpha = 2/(PERIODS+1)if barindex < PERIODS thenEWMA = AVERAGE[3](PRICE)elseEWMA = alpha * PRICE + (1-alpha)*EWMAendiferror = PRICE - EWMAdev = SQUARE(error)if barindex < PERIODS+1 thenvar = develsevar = alpha * dev + (1-alpha) * varendifESD = SQRT(var)BollU = EXP(EWMA + (DEVIATIONS*ESD))BollL = EXP(EWMA - (DEVIATIONS*ESD))RS2 = ROUND(RSI[2](close))PSH = Highest[100](high)[1]PSL = Lowest[100](low)[1]If longonmarket and ((close[1] > BollU and close < BollU) or (high[1] > BollU and high < BollU) or (close > PSH or close < PSL)) ThenLE = 1ElsIf shortonmarket and ((close[1] < BollL and close > BollL) or (low[1] < BollL and low > BollL) or (close < PSL or close > PSH)) ThenSE = 1EndIfIf longonmarket and LE = 1 and RS2 >= 85 and close < BollU ThenSell at marketBear = 0Bull = 0optimize = optimize + 1ElsIf shortonmarket and SE = 1 and RS2 <= 15 and close > BollL ThenExitshort at marketBear = 0Bull = 0optimize = optimize + 1EndIf07/28/2021 at 10:30 AM #17428107/28/2021 at 5:07 PM #174303Bonsoir, Nicolas n’est pas disponible, pour débugguer une div par zéro si on ne la trouve pas facilement, on peut se transformer sa stratégie en indicateur, identifier les dénominateurs de toutes les divisions faites, et les mettre dans des variables retournées dans la ligne return de l’indicateur. Quand tu tombes visuellement sur l’une d’entre elle à zéro, tu en conclus la modif à faire selon le cas.
Nicolas est au courant qu’il y a effectivement un bug avec le bouton “insert PRT code” parfois disparu. Je reformate le code ci-dessus. En attendant que le bug soit résolu, si avant de taper son message on voit que le bouton est absent, on peut faire un CTRL+touche F5 qui devrait le faire revenir (et si on a commencé un message et qu’on ne veut pas le perdre, penser à le copier quelque part ailleurs dans un word ou un bloc-note, car ctrl+f5 va obliger à recommencer le message à zéro).
1 user thanked author for this post.
07/28/2021 at 6:08 PM #17430608/28/2021 at 6:52 PM #176424Bonjour @saccucci,
le mieux est d’utiliser l’instruction GRAPH pour afficher la valeur des variables utilisées comme dénominateur et/ou le résultat des calculs entre parenthèses.
Sinon, une autre possibilité serait d’ajouter un très petit nombre au dénominateur de chaque division, par exemple 0.0000001. Cela vous garantirait de ne plus avoir cette erreur mais cela pourrait changer le comportement du robot…
Finalement la question serait : est-il normal de vous retrouver avec un zéro au dénominateur ? Il y a peut-être un problème de conception dans votre algo ? ou quelque chose à revoir ?
-
AuthorPosts