Extratrend stratégie en un indicateur

Viewing 15 posts - 1 through 15 (of 29 total)
  • Author
    Posts
  • #193712 quote
    HienAlpha
    Participant
    New

    Bonjour à toutes et tous,

    J’ai effectué un backtest d’une stratégie en faisant appel à Extratrend.

    J’aimerai transformé cette stratégie en indicateur, afin de pouvoir l’utiliser en temps réel. Pourriez vous m’aider à le faire svp ?

    Merci d’avance,

    Voici le code du backtest :

    DEFPARAM CumulateOrders=False
    
    capitalinitial=10000
    risque=0.5
    exitstrategy=1
    profitfactor=6
    stopfactor=1.5
    partialprofit=1
    partialprofitfactor=3
    ratchetfactor=7
    
    // Appel des valeurs d'ExtraTrend
    //myTrend, ignored, ignored = CALL "ExtraTrend v2" [0,0,0,0,0](close)
    myTrend, ignored, ignored, ignored, ignored = CALL "ExtraTrend"[0,0,0,0,0](close)
    
    // Tendance ExtraTrend
    if myTrend>myTrend[1] then
    tendance=1
    endif
    if myTrend<myTrend[1] then
    tendance=0
    endif
    
    if tendance and not tendance[1] and not longonmarket THEN
    //if not longonmarket then
    positionsize=round(((capitalinitial+STRATEGYPROFIT)*(risque/100))/(stopfactor*averagetruerange[20]))
    //positionsize=round(((capitalinitial+STRATEGYPROFIT)/close)
    BUY positionsize shares AT MARKET
    set stop loss stopfactor*averagetruerange[20]
    if exitstrategy=0 then
    set target profit profitfactor*averagetruerange[20]
    endif
    flag=0
    endif
    
    if longonmarket and close>=myTrend+partialprofitfactor*averagetruerange[20] and flag=0 and partialprofit=1 then
    sell round(positionsize/2) shares at market
    flag=1
    endif
    
    if longonmarket and exitstrategy=1 and close<lowest[30](highest[55](high)-ratchetfactor*averagetruerange[20])then
    sell at market
    endif
    #193720 quote
    Nicolas
    Keymaster
    Master

    ok je vais regarder cela, je vais ajouter du texte sur le graphique pour marquer les événements, si il faut changer cet aspect visuel on verra par la suite, il faudra me l’indiquer.

    #193724 quote
    Nicolas
    Keymaster
    Master

    Ci-joint la version graphique de cette stratégie avec Extratrend:

    capitalinitial=10000
    risque=0.5
    exitstrategy=1
    profitfactor=6
    stopfactor=1.5
    partialprofit=1
    partialprofitfactor=3
    ratchetfactor=7
    
    // Appel des valeurs d'ExtraTrend
    myTrend, ignored, ignored, ignored, ignored = CALL "ExtraTrend"[0,0,0,0,0](close)
    
    // Tendance ExtraTrend
    if myTrend>myTrend[1] then
    tendance=1
    endif
    if myTrend<myTrend[1] then
    tendance=0
    endif
    
    if tendance and not tendance[1] and not ionmarket THEN
    drawarrowup(barindex,low-AverageTrueRange[14](close)/2) coloured("green")
    istoploss = close-stopfactor*averagetruerange[20]
    //set stop loss stopfactor*averagetruerange[20]
    if exitstrategy=0 then
    itakeprofit = close+profitfactor*averagetruerange[20]
    //set target profit profitfactor*averagetruerange[20]
    endif
    flag=0
    ionmarket=1
    endif
    
    if ionmarket and close>=myTrend+partialprofitfactor*averagetruerange[20] and flag=0 and partialprofit=1 then
    drawtext("X",barindex,high+AverageTrueRange[14](close)/2,dialog,bold,20) coloured("green")
    flag=1
    endif
    
    if ionmarket and exitstrategy=1 and close<lowest[30](highest[55](high)-ratchetfactor*averagetruerange[20])then
    drawtext("exit",barindex,high+AverageTrueRange[14](close)/2,dialog,bold,20) coloured("green")
    ionmarket=0
    endif
    
    //test stoploss & takeprofit
    if ionmarket then  
    if high >= itakeprofit and exitstrategy=0 then 
    drawtext("TP",barindex,high+AverageTrueRange[14](close)/2,dialog,bold,20) coloured("green")
    ionmarket=0
    elsif low <= istoploss then 
    drawtext("SL",barindex,high+AverageTrueRange[14](close)/2,dialog,bold,20) coloured("red")
    ionmarket=0
    endif
    endif
    
    return itakeprofit style(dottedline2) coloured("green"), istoploss style(dottedline3) coloured("red")
    
    Keyeming thanked this post
    extratrend-strategie-manuel.png extratrend-strategie-manuel.png
    #193726 quote
    HienAlpha
    Participant
    New

    Super, un grand merci Nicolas !

    Je vais essayer ça et je te reviens.

    #193729 quote
    HienAlpha
    Participant
    New

    Cela a l’air de bien marcher.

    J’ai trois questions.

    – Je suppose que :
    SL c’est Stop Loss touché
    Le “X” c’est une prise de profit
    La flèche vers le haut c’est la prise de position
    Mais qu’est ce que le “EXIT” ?

    – Est il possible d’avoir le niveau trailing stop ? Car sur le graphique, il ne “suit” pas vraiment le cours. Je suis prévenu que lorsqu’il est tapé.

    – J’essaye de changer la couleur des évènements du vert vers le noir, mais je n’y arrive pas ^^

    #193747 quote
    Nicolas
    Keymaster
    Master

    X c’est le profit partiel que tu as codé et EXIT, c’est la sortie totale avec le SELL AT MARKET.

    #193763 quote
    HienAlpha
    Participant
    New

    D’accord, merci Nicolas.

    Mais du coup, si EXIT est la sortie totale, qu’est ce que “SL” ?

    #193771 quote
    Nicolas
    Keymaster
    Master

    Ta stratégie comporte un STOPLOSS, ce niveau je le teste dans le code et si il est touché, on affiche “SL” 🙂

    et tu as aussi codé une sortie de position selon des conditions (voir ton code lignes 41 à 43) = EXIT

    #194221 quote
    HienAlpha
    Participant
    New

    Bonsoir Nicolas,

    Un grand merci pour ton aide !

    Je viens de recevoir ma licence Metascore, et j’aimerai rajouter une condition d’achat.

    Pourrais tu m’aider à le faire stp ? (Désolé, je suis vraiment très mauvais en codage, je ne sais pas faire grand chose).

    J’aimerai conserver cette stratégie (entrée quand nouvelle zone de force à condition de ne pas déjà être en position, prise de profit partielle, trailing stop avec un ratchet…) mais en rajoutant la condition stricte que le métascore soit supérieur ou égal à 80.

    J’aimerai le backtester d’abord et puis le transformer en indicateur visuel si cela se révèle probant.

    En te remerciant par avance,

    Amicalement,

    Thibaut

    Keyeming thanked this post
    #194246 quote
    Nicolas
    Keymaster
    Master

    On récupère l’information de la valeur de MetaScore comme ceci:

    myScore, ignored, ignored = CALL "MetaScore"[80, 0, 0](close)

    ensuite on teste myScore si il est < ou > à la valeur souhaitée.

    #194250 quote
    HienAlpha
    Participant
    New

    D’accord, merci.

    J’ai tenté d’implémenter.

    Cela donne ça, c’est correct ?

    DEFPARAM CumulateOrders=False
    
    capitalinitial=10000
    risque=0.5
    exitstrategy=1
    profitfactor=6
    stopfactor=1.5
    partialprofit=1
    partialprofitfactor=3
    ratchetfactor=7
    
    // Appel des valeurs d'ExtraTrend
    //myTrend, ignored, ignored = CALL "ExtraTrend v2" [0,0,0,0,0](close)
    myTrend, ignored, ignored, ignored, ignored = CALL "ExtraTrend"[0,0,0,0,0](close)
    
    // Tendance ExtraTrend
    if myTrend>myTrend[1] then
    tendance=1
    endif
    if myTrend<myTrend[1] then
    tendance=0
    endif
    // score Metascore
    myScore, ignored, ignored = CALL "MetaScore"[80, 0, 0](close)
    if myScore>80 then
    tendance=1
    endif
    if myScore<80 then
    tendance=0
    endif
    
    //strategy of entry
    if tendance and not tendance[1] and not longonmarket THEN
    //if not longonmarket then
    positionsize=round(((capitalinitial+STRATEGYPROFIT)*(risque/100))/(stopfactor*averagetruerange[20]))
    //positionsize=round(((capitalinitial+STRATEGYPROFIT)/close)
    BUY positionsize shares AT MARKET
    set stop loss stopfactor*averagetruerange[20]
    if exitstrategy=0 then
    set target profit profitfactor*averagetruerange[20]
    endif
    flag=0
    endif
    
    if longonmarket and close>=myTrend+partialprofitfactor*averagetruerange[20] and flag=0 and partialprofit=1 then
    sell round(positionsize/2) shares at market
    flag=1
    endif
    
    if longonmarket and exitstrategy=1 and close<lowest[30](highest[55](high)-ratchetfactor*averagetruerange[20])then
    sell at market
    endif
    #194251 quote
    JC_Bywan
    Moderator
    Master

    Bonjour, pour joindre le code PRT au bon format, merci d’utiliser le bouton “insert PRT code”, s’il disparait temporairement (bug du site), merci de faire CTRL+F5 pour le faire réapparaitre, mini-tuto qui contourne le bug et permet de localiser le bouton si on ne le connait pas encore: https://www.youtube.com/watch?v=jBuqwWPW3H4

    (psa besoin de reposter, je vais éditer le code ci-dessus pour le mettre au bon format)

    #194288 quote
    Nicolas
    Keymaster
    Master

    Non, la logique n’est pas correct, le code devrait être comme ceci :

    DEFPARAM CumulateOrders=False
    
    capitalinitial=10000
    risque=0.5
    exitstrategy=1
    profitfactor=6
    stopfactor=1.5
    partialprofit=1
    partialprofitfactor=3
    ratchetfactor=7
    
    // Appel des valeurs d'ExtraTrend
    //myTrend, ignored, ignored = CALL "ExtraTrend v2" [0,0,0,0,0](close)
    myTrend, ignored, ignored, ignored, ignored = CALL "ExtraTrend"[0,0,0,0,0](close)
    
    // Tendance ExtraTrend
    if myTrend>myTrend[1] then
    tendance=1
    endif
    if myTrend<myTrend[1] then
    tendance=0
    endif
    // score Metascore
    myScore, ignored, ignored = CALL "MetaScore"[80, 0, 0](close)
    
    //strategy of entry
    if tendance and not tendance[1] and not longonmarket and myscore>80 THEN
    //if not longonmarket then
    positionsize=round(((capitalinitial+STRATEGYPROFIT)*(risque/100))/(stopfactor*averagetruerange[20]))
    //positionsize=round(((capitalinitial+STRATEGYPROFIT)/close)
    BUY positionsize shares AT MARKET
    set stop loss stopfactor*averagetruerange[20]
    if exitstrategy=0 then
    set target profit profitfactor*averagetruerange[20]
    endif
    flag=0
    endif
    
    if longonmarket and close>=myTrend+partialprofitfactor*averagetruerange[20] and flag=0 and partialprofit=1 then
    sell round(positionsize/2) shares at market
    flag=1
    endif
    
    if longonmarket and exitstrategy=1 and close<lowest[30](highest[55](high)-ratchetfactor*averagetruerange[20])then
    sell at market
    endif
    #194326 quote
    HienAlpha
    Participant
    New

    Super !

    Un grand merci Nicolas.

    Excellente soirée à toi,

    Keyeming thanked this post
    #195900 quote
    HienAlpha
    Participant
    New

    Bonjour Nicolas,

    J’ai développé une variante de ma stratégie, en incluant une partie SHORT.

    Mais j’ai du mal à la transformer en indicateur visuel ^^

    Je ne veux pas abuser mais pourrais tu m’aider stp ?

    (Désolé mais j’ai beau tape CTRL+F5 mais le bouton Insert PRT code ne s’affiche pas…)

    DEFPARAM CumulateOrders=False
    
    capitalinitial=100000
    risque=0.5
    exitstrategy=1
    profitfactor=6
    stopfactor=1.5
    partialprofit=1
    partialprofitfactor=3
    ratchetfactor=7
    
    //myTrend, ignored, ignored = CALL "ExtraTrend v2" [0,0,0,0,0](close)
    myTrend, ignored, ignored, myReDyn, ignored = CALL "ExtraTrend"[0,0,0,0,0](close)
    
    // Tendance ExtraTrend
    if myTrend>myTrend[1] then
    tendance=1
    endif
    if myTrend<myTrend[1] then
    tendance=0
    endif
    
    // Break Résistance Dynamique ExtraTrend
    if myReDyn>myReDyn[1] then
    ReDyn=1
    endif
    if myReDyn<myReDyn[1] then
    ReDyn=0
    endif
    
    // Metascore
    myScore, ignored, ignored = CALL "MetaScore"[0,0,0](close)
    
    //STRATEGIES OF BUY
    
    if tendance and not tendance[1] and not longonmarket and not shortonmarket and myScore>80 and ReDyn=1 THEN
    //if not longonmarket then
    positionsize=round(((capitalinitial+STRATEGYPROFIT)*(risque/100))/(stopfactor*averagetruerange[20]))
    
    //positionsize=round(((capitalinitial+STRATEGYPROFIT)/close)
    BUY positionsize shares AT MARKET
    set stop loss stopfactor*averagetruerange[20]
    if exitstrategy=0 then
    set target profit profitfactor*averagetruerange[20]
    endif
    flag=0
    endif
    
    if longonmarket and close>=myTrend+partialprofitfactor*averagetruerange[20] and flag=0 and partialprofit=1 then
    sell round(positionsize/2) shares at market
    flag=1
    endif
    
    if longonmarket and exitstrategy=1 and close<lowest[30](highest[55](high)-ratchetfactor*averagetruerange[20])then
    sell at market
    endif
    
    //STRATEGIES OF SELL
    if not tendance and not tendance[0] and not shortonmarket and not longonmarket and myScore<20 THEN
    
    //if not ShortOnMarket then
    positionsize=round(((capitalinitial+STRATEGYPROFIT)*(risque/100))/(stopfactor*averagetruerange[20]))
    
    //positionsize=round(((capitalinitial+STRATEGYPROFIT)/close)
    SELLSHORT positionsize shares AT MARKET
    set stop loss stopfactor*averagetruerange[20]
    if exitstrategy=0 then
    set target profit profitfactor*averagetruerange[20]
    endif
    flag=0
    endif
    
    if shortonmarket and close>=myTrend+partialprofitfactor*averagetruerange[20] and flag=0 and partialprofit=1 then
    sell round(positionsize/2) shares at market
    flag=1
    endif
    
    if shortonmarket and exitstrategy=1 and close<lowest[30](highest[55](high)-ratchetfactor*averagetruerange[20])then
    exitshort at market
    endif
Viewing 15 posts - 1 through 15 (of 29 total)
  • You must be logged in to reply to this topic.

Extratrend stratégie en un indicateur


ProBuilder : Indicateurs & Outils Personnalisés

New Reply
Author
author-avatar
HienAlpha @hienalpha Participant
Summary

This topic contains 28 replies,
has 8 voices, and was last updated by plbourse
3 years, 5 months ago.

Topic Details
Forum: ProBuilder : Indicateurs & Outils Personnalisés
Language: French
Started: 05/23/2022
Status: Active
Attachments: 3 files
Logo Logo
Loading...