Compréhension des Boucles

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #147586 quote
    Fantasio2020
    Participant
    Senior

    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.

    1. Quand utiliser une boucle plutôt qu’une condition booléenne?
    2. Comment écrire par exemple:
      While 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

    #147592 quote
    JC_Bywan
    Moderator
    Master

    Mieux 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

    #149671 quote
    Fantasio2020
    Participant
    Senior

    J’ai créé une petite stratégie avec des boucles, mais j’ai une erreur et je ne parvient pas à la solutionner:

    //-------------------------------------------------------------------------
    // Définition des paramètres du code
    Defparam CumulateOrders = False
    Defparam Preloadbars = 8640
    Defparam FlatBefore = 090000
    Defparam FlatAfter = 153000
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    //daysForbiddenEntry = OpenDayOfWeek = 1 OR OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    //************************************************************************
    
    //Pivot (H + L + C + O)/4
    If OpenDayOfWeek = 1 Then
    Ht = DHigh(2)
    Bs = DLow(2)
    C = DClose(2)
    O = DOpen(0)
    Endif
    If OpenDayOfWeek => 2 and dayofweek < 6 Then
    Ht = DHigh(1)
    Bs = DLow(1)
    C = DClose(1)
    O = DOpen(0)
    Endif
    
    Pivot = (Ht + Bs + C + O)/4
    Res4 = Ht + (3*(Pivot - BS))
    Res3 = Ht + (2*(Pivot - Bs))
    Res2 = Pivot + (Ht - Bs)
    Res1 = (2*Pivot) - Bs
    Sup1 = (2*Pivot) - Ht
    Sup2 = Pivot-(Ht - Bs)
    Sup3 = Bs - (2*(Ht - Pivot))
    Sup4 = Bs - (3*(Ht - Pivot))
    
    //Heikin-Hachi
    Once UpDown = 0
    IF BarIndex = 0 Then
    xClose = TotalPrice
    xOpen = Range
    xHigh = High
    xLow = Low
    Else
    xClose = TotalPrice
    xOpen = (xOpen[1] + xClose[1])/2
    xHigh = Max(max(high, xOpen), xClose)
    xLow = Min(min(Low, xOpen), xClose)
    endif
    If XClose >= XOpen then
    if UpDown <> 1 then
    UpDown = 1
    endif
    Else
    If UpDown <> -1 then
    UpDown = -1
    endif
    endif
    
    HHSize = 0.6
    Distance = 8
    LookBack = 8640
    Coeff = 0.8
    P = 10 // Slope, R², RSI, Sochastic
    R2LimE = 0.52 // Coefficient de correlation R² d'entrée
    R2LimS = 0.77 // Coefficient de correlation R² de sortie
    Q = P // Stochastic
    
    
    // --- icihmoku support and resistance
    kijun = (highest[26](high)+lowest[26](low))/2
    SSB = (highest[52](high[26])+lowest[52](low[26]))/2
    
    If Kijun = Kijun[1] then
    KijunPrice = Kijun
    endif
    If SSB = SSB[1] then
    SSBPrice = SSB
    endif
    
    if KijunPrice = SSBPrice then
    SRLevel = KijunPrice
    if SRLevel > Close then
    ResLevel = SRlevel
    //elsif SRLevel < Close then
    //SupLevel = SRlevel
    //endif
    endif
    endif
    
    MyStoch = 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*ecart
    
    EMA50 = ExponentialAverage[50](Close)
    EMA200 = ExponentialAverage[200](Close)
    
    Slope = EndpointAverage[P](LinearRegressionSlope[P](Close))
    MyR2 = R2[P](WeightedClose)
    
    //************************************************************************
    levier = 2
    capital = 500 + (strategyprofit*2/5)
    z = (capital / (close/20)) * levier
    //************************************************************************
    //Position acheteuse
    BuyConditionA = (xClose - xOpen)*pipsize => HHSize
    BuyConditionB = EMA50 > EMA200 and EMA50 < Close and EMA200 < Close
    
    SLUp = Slope > Slope[1]
    iSL = 0
    While SLUp[iSL] and iSL < 20 do
    iSLSup = iSLSup + 1
    if SLUp - SLUp[1] = 0 then
    break
    endif
    if MyStoch > UpBand then
    if MyR2 crosses over R2LimE then
    while MyR2 > MyR2[1]
    if MyR2 - MyR2[1] = 0 or MyR2 < MyR2[1] then
    Break
    endif
    wend
    endif
    allowtrading = 1
    for iSRB = 0 to lookback -1
    dist = (Reslevel[iSRB] - Close) < distance*pipsize
    if dist then
    allowtrading = 0 //no trading is allowed we are near a SR!
    break //break the loop, no need to continue, trading is not allowed anymore!
    endif
    next
    if close > pivot then
    //above Pivot
    iPivt = 1
    while iPivt =< 4 do
    if iPivt = 1 then
    Floor = Pivot
    Ceil = Res1
    if close > Floor and close < Ceil then
    break
    endif
    elsif iPivt = 2 then
    Floor = Res1
    Ceil = Res2
    if close > Floor and close < Ceil then
    break
    endif
    elsif iPivt = 3 then
    Floor = Res2
    Ceil = Res3
    if close > Floor and close < Ceil then
    break
    endif
    elsif iPivt = 4 then
    Floor = Res3
    Ceil = Res4
    if close > Floor and close < Ceil then
    break
    endif
    endif
    iPivt = iPivt + 1
    wend
    elsif close < Pivot then
    //below Pivot
    iPivt = 1
    while iPivt <= 4 do
    if iPivt = 1 then
    Floor = Sup1
    Ceil = Pivot
    if close > Floor and close < Ceil then
    break
    endif
    elsif iPivt = 2 then
    Floor = Sup2
    Ceil = Sup1
    if close > Floor and close < Ceil then
    break
    endif
    elsif iPivt = 3 then
    Floor = Sup3
    Ceil = Sup2
    if close > Floor and close < Ceil then
    break
    endif
    elsif iPivt = 4 then
    Floor = Sup4
    Ceil = Sup3
    if close > Floor and close < Ceil then
    break
    endif
    endif
    iPivt = iPivt + 1
    wend
    endif
    For IPivt = 1 to 8 do
    dist = (Ceil - Close) < distance*pipsize
    If Dist then
    allowtrading = 0
    Break
    endif
    iPivt = iPivt + 1
    next
    If BuyConditionA and BuyConditionB and not daysForbiddenEntry then
    if allowtrading then
    buy z shares at market
    endif
    endif
    endif
    wend
    
    
    If Longonmarket and MyR2 crosses under R2LimS then
    Sell at Market
    elsif Longonmarket and MyR2 crosses under R2LimE then
    Sell at Market
    Endif
    
    //************************************************************************
    //Stop Loss & Trailing function
    //Set stop $loss capital*levier*2/100
    Set Target $Profit capital*levier*3/100
    trailingstart = 5
    trailingstep = 3
    
    //reset the stoploss value
    If not onmarket then
    newSL = 0
    Endif
    
    //manage long positions
    If Longonmarket Then
    If newSL = 0 and xLow-tradeprice(1) > trailingstart*pipsize then
    newSL = tradeprice(1) + trailingstep*pipsize
    Endif
    If newSL <> 0 and xLow-newSL > trailingstep*pipsize then
    newSL = newSL + trailingstep*pipsize
    Endif
    Endif
    
    //manage short positions
    If ShortonMarket then
    If newSL = 0 and tradeprice(1)-xHigh > trailingstart*pipsize Then
    newSL = tradeprice(1) - trailingstep*pipsize
    Endif
    If newSL <> 0 and newSL-xHigh > trailingstep*pipsize Then
    newSL = newSL - trailingstep*pipsize
    Endif
    Endif
    
    //stop order to exit the positions
    If newSL <> 0 Then
    Sell at newSL Stop
    Exitshort at newSL Stop
    Endif
    //************************************************************************
    

    est-ce que quelqu’un peut m’aider à comprendre mes erreurs?

    merci

    #149679 quote
    Nicolas
    Keymaster
    Master

    Ta boucle WHILE/WEND est infini car tu demandes à la continuer tant que iSL < 20 , hors iSL n’est jamais incrémenté dans la boucle .. 🙄

    Pour mémoire WHILE/WEND signifie TANT QUE … iSL<20 ALORS

    #149687 quote
    Fantasio2020
    Participant
    Senior

    Merci 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.

    #149692 quote
    Nicolas
    Keymaster
    Master

    Je 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 🙂

    #149693 quote
    Fantasio2020
    Participant
    Senior

    ok j’ai pigé!

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.

Compréhension des Boucles


ProOrder : Trading Automatique & Backtests

New Reply
Author
Summary

This topic contains 6 replies,
has 3 voices, and was last updated by Fantasio2020
5 years, 4 months ago.

Topic Details
Forum: ProOrder : Trading Automatique & Backtests
Language: French
Started: 10/16/2020
Status: Active
Attachments: No files
Logo Logo
Loading...