Compréhension des Boucles
Forums › ProRealTime forum Français › Support ProOrder › Compréhension des Boucles
- This topic has 6 replies, 3 voices, and was last updated 4 years ago by Fantasio2020.
-
-
10/16/2020 at 5:21 PM #147586
Bonjour,
je galère un peu avec la compréhension des boucles. j’ai parcouru le manuel mais je comprends pas bien comment ça fonctionne.
Je suis pas programmeur et c’est un peu du chinois pour moi.
- Quand utiliser une boucle plutôt qu’une condition booléenne?
- Comment écrire par exemple:
1While Shortonmarket do //(garder la position tant que MM50 est décroissant)
si quelqu’un pouvait me donner un mini cours j’apprécierai énormément
Slts
10/16/2020 at 5:53 PM #147592Mieux que le manuel, il y a les vidéos de Nicolas (menu du haut, rubrique “learning videos”, lien: https://www.prorealcode.com/programming-with-prorealtime/), qui remplissent exactement cet objectif en 2 vidéos (en Français ou en Anglais) : permettre aux non-programmeurs d’acquérir les notions de base telles que les boucles
11/06/2020 at 12:53 PM #149671J’ai créé une petite stratégie avec des boucles, mais j’ai une erreur et je ne parvient pas à la solutionner:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261//-------------------------------------------------------------------------// Définition des paramètres du codeDefparam CumulateOrders = FalseDefparam Preloadbars = 8640Defparam FlatBefore = 090000Defparam FlatAfter = 153000daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0//daysForbiddenEntry = OpenDayOfWeek = 1 OR OpenDayOfWeek = 6 OR OpenDayOfWeek = 0//************************************************************************//Pivot (H + L + C + O)/4If OpenDayOfWeek = 1 ThenHt = DHigh(2)Bs = DLow(2)C = DClose(2)O = DOpen(0)EndifIf OpenDayOfWeek => 2 and dayofweek < 6 ThenHt = DHigh(1)Bs = DLow(1)C = DClose(1)O = DOpen(0)EndifPivot = (Ht + Bs + C + O)/4Res4 = Ht + (3*(Pivot - BS))Res3 = Ht + (2*(Pivot - Bs))Res2 = Pivot + (Ht - Bs)Res1 = (2*Pivot) - BsSup1 = (2*Pivot) - HtSup2 = Pivot-(Ht - Bs)Sup3 = Bs - (2*(Ht - Pivot))Sup4 = Bs - (3*(Ht - Pivot))//Heikin-HachiOnce UpDown = 0IF BarIndex = 0 ThenxClose = TotalPricexOpen = RangexHigh = HighxLow = LowElsexClose = TotalPricexOpen = (xOpen[1] + xClose[1])/2xHigh = Max(max(high, xOpen), xClose)xLow = Min(min(Low, xOpen), xClose)endifIf XClose >= XOpen thenif UpDown <> 1 thenUpDown = 1endifElseIf UpDown <> -1 thenUpDown = -1endifendifHHSize = 0.6Distance = 8LookBack = 8640Coeff = 0.8P = 10 // Slope, R², RSI, SochasticR2LimE = 0.52 // Coefficient de correlation R² d'entréeR2LimS = 0.77 // Coefficient de correlation R² de sortieQ = P // Stochastic// --- icihmoku support and resistancekijun = (highest[26](high)+lowest[26](low))/2SSB = (highest[52](high[26])+lowest[52](low[26]))/2If Kijun = Kijun[1] thenKijunPrice = KijunendifIf SSB = SSB[1] thenSSBPrice = SSBendifif KijunPrice = SSBPrice thenSRLevel = KijunPriceif SRLevel > Close thenResLevel = SRlevel//elsif SRLevel < Close then//SupLevel = SRlevel//endifendifendifMyStoch = Average[5](Stochastic[14,3](close))ind = SQUARE(MyStoch)ind1 = Average[Q](MyStoch)ind2 = Average[Q](ind)variance = ind2 - SQUARE(ind1)ecart = SQRT(variance)UpBand = ind1 + coeff*ecart//DownBand = ind1 - coeff*ecartEMA50 = ExponentialAverage[50](Close)EMA200 = ExponentialAverage[200](Close)Slope = EndpointAverage[P](LinearRegressionSlope[P](Close))MyR2 = R2[P](WeightedClose)//************************************************************************levier = 2capital = 500 + (strategyprofit*2/5)z = (capital / (close/20)) * levier//************************************************************************//Position acheteuseBuyConditionA = (xClose - xOpen)*pipsize => HHSizeBuyConditionB = EMA50 > EMA200 and EMA50 < Close and EMA200 < CloseSLUp = Slope > Slope[1]iSL = 0While SLUp[iSL] and iSL < 20 doiSLSup = iSLSup + 1if SLUp - SLUp[1] = 0 thenbreakendifif MyStoch > UpBand thenif MyR2 crosses over R2LimE thenwhile MyR2 > MyR2[1]if MyR2 - MyR2[1] = 0 or MyR2 < MyR2[1] thenBreakendifwendendifallowtrading = 1for iSRB = 0 to lookback -1dist = (Reslevel[iSRB] - Close) < distance*pipsizeif dist thenallowtrading = 0 //no trading is allowed we are near a SR!break //break the loop, no need to continue, trading is not allowed anymore!endifnextif close > pivot then//above PivotiPivt = 1while iPivt =< 4 doif iPivt = 1 thenFloor = PivotCeil = Res1if close > Floor and close < Ceil thenbreakendifelsif iPivt = 2 thenFloor = Res1Ceil = Res2if close > Floor and close < Ceil thenbreakendifelsif iPivt = 3 thenFloor = Res2Ceil = Res3if close > Floor and close < Ceil thenbreakendifelsif iPivt = 4 thenFloor = Res3Ceil = Res4if close > Floor and close < Ceil thenbreakendifendifiPivt = iPivt + 1wendelsif close < Pivot then//below PivotiPivt = 1while iPivt <= 4 doif iPivt = 1 thenFloor = Sup1Ceil = Pivotif close > Floor and close < Ceil thenbreakendifelsif iPivt = 2 thenFloor = Sup2Ceil = Sup1if close > Floor and close < Ceil thenbreakendifelsif iPivt = 3 thenFloor = Sup3Ceil = Sup2if close > Floor and close < Ceil thenbreakendifelsif iPivt = 4 thenFloor = Sup4Ceil = Sup3if close > Floor and close < Ceil thenbreakendifendifiPivt = iPivt + 1wendendifFor IPivt = 1 to 8 dodist = (Ceil - Close) < distance*pipsizeIf Dist thenallowtrading = 0BreakendifiPivt = iPivt + 1nextIf BuyConditionA and BuyConditionB and not daysForbiddenEntry thenif allowtrading thenbuy z shares at marketendifendifendifwendIf Longonmarket and MyR2 crosses under R2LimS thenSell at Marketelsif Longonmarket and MyR2 crosses under R2LimE thenSell at MarketEndif//************************************************************************//Stop Loss & Trailing function//Set stop $loss capital*levier*2/100Set Target $Profit capital*levier*3/100trailingstart = 5trailingstep = 3//reset the stoploss valueIf not onmarket thennewSL = 0Endif//manage long positionsIf Longonmarket ThenIf newSL = 0 and xLow-tradeprice(1) > trailingstart*pipsize thennewSL = tradeprice(1) + trailingstep*pipsizeEndifIf newSL <> 0 and xLow-newSL > trailingstep*pipsize thennewSL = newSL + trailingstep*pipsizeEndifEndif//manage short positionsIf ShortonMarket thenIf newSL = 0 and tradeprice(1)-xHigh > trailingstart*pipsize ThennewSL = tradeprice(1) - trailingstep*pipsizeEndifIf newSL <> 0 and newSL-xHigh > trailingstep*pipsize ThennewSL = newSL - trailingstep*pipsizeEndifEndif//stop order to exit the positionsIf newSL <> 0 ThenSell at newSL StopExitshort at newSL StopEndif//************************************************************************est-ce que quelqu’un peut m’aider à comprendre mes erreurs?
merci
11/06/2020 at 2:19 PM #14967911/06/2020 at 3:33 PM #149687Merci Nicolas, je comprend.
la valeur de iSL peut varier, mais en générale la pente de slope est toujours inférieur à 20 périodes.
l’idée derrière c’est que : tant que SLup est vérifié alors je reste dans la boucle.
à l’inverse lorsque SLup n’est plus vérifié je sort.
Merci pour ton aide si tu peux m’aider sur une solution.
11/06/2020 at 4:04 PM #149692Je crois que tu ne comprends pas comment le code est lu. Il est lu de haut en bas, une seule fois par chandelier, à sa fermeture. Donc aucune valeur ne va bouger dans ta boucle, comme ici celle concernant la “slope”, puisqu’il faut plusieurs périodes pour cela n’est ce pas ? Dans ce genre de cas de figure, un simple IF/THEN est suffisant 🙂
11/06/2020 at 4:07 PM #149693 -
AuthorPosts
Find exclusive trading pro-tools on