Stratégie MTF, besoins d'explications sur le comportement de ma stratégie

Viewing 7 posts - 16 through 22 (of 22 total)
  • Author
    Posts
  • #93930 quote
    Nicolas
    Keymaster
    Master

    Ok, après quelques tests de mon côté, je m’aperçois qu’il existe un comportement curieux avec le cumul d’ordres activé, tu avais raison Geoffrey. Même en “updateonclose”, les ordres lancés en timeframe 5-minutes se cumulent en timeframe 1-minute. Je viens de faire répertorier ce soucis chez ITF, j’attends des informations, merci d’être patient 🙂

    Voici le code en question, en essayant de tester le dernier barindex du dernier ordre, le cumul se fait tout de même .. 😕

    // Définition des paramètres du code
    DEFPARAM CumulateOrders = true // Cumul des positions activé
    // Annule tous les ordres en attente et ferme toutes les positions à 0:00, puis empêche toute création d'ordre avant l'heure "FLATBEFORE".
    DEFPARAM FLATBEFORE = 090000
    // Annule tous les ordres en attente et ferme toutes les positions à l'heure "FLATAFTER"
    DEFPARAM FLATAFTER = 220000
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
     
    //-------- Stratégie sur le 5 minutes --------
    timeframe(5 minutes, updateonclose)
    
    //Définition de la pénétration ou de l'avalement d'une bougie
    
    TBP = high[1]-low[1] // taille de la bougie précédente mèches comprises
    
    PenetrationAchat = close > low[1]+1*TBP
    PenetrationVente = close < high[1]-1*TBP
    
    //Définition du RSI
    
    RSIA = RSI[7](close)crosses over 70
    RSIV = RSI[7](close)crosses under 30
    
    //Définitions des MM
    
    MM50 = average[50](close)
    
    //Conditions pour un signal d'achat --------
    
    ca1 = RSIA
    ca2 = PenetrationAchat
    ca3 = MM50 > MM50 [1]
    
    //-------- condition d'achat
    
    achat= ca1 and ca2 and ca3 
    if achat then 
    buysignalbar=barindex
    endif
    
    if not daysForbiddenEntry and buysignalbar>lastbuysignalbar then
    buy 1 contract at market
    SET STOP pLOSS 30
    SET TARGET pPROFIT 30
    lastbuysignalbar=buysignalbar
    endif
    
    //Conditions pour un signal de vente --------
    
    cv1 = RSIV
    cv2 = PenetrationVente
    cv3 = MM50 < MM50 [1]
    
    //-------- Condition de vente
    vente= cv1 and cv2 and cv3 
    if vente then
    sellsignalbar=barindex
    endif
    if not daysForbiddenEntry and sellsignalbar>lastsellsignalbar then
    sellshort 1 contract at market
    SET STOP pLOSS 30
    SET Target pProfit 30
    lastsellsignalbar=sellsignalbar
    endif
    
    
    //-------- Définition de l'unité de temps principale d'action pour la mise à Break Even
    timeframe(1 minute)
    
    //Définition du stop à BE (break-even)
    startBEA = 12 //Nombre de point pour activer le stopBE
    startBEV = 12
    PointsToKeepA = 2 //Nombre de point de mise en place du stop par rapport au point d'entrée afin d'être stopé non pas à 0 mais un peu en postif
    PointsToKeepV = 2
    
    
    //On remet le niveau de mise à BE à 0 losque l'on n'est pas en position
    if not onmarket then
    BELvAchat=0
    endif
     
    //on regarde si le trade actuel à fait au moins x pips
    if longonmarket and high-tradeprice>=startBEA then
    BELvAchat=1
    endif
     
    //placer stoploss au prix d'entrée + x points
    if BELvAchat=1 then
    sell at tradeprice+PointsToKeepA stop
    endif
    
    
     
    //On remet le niveau de mise à BE à 0 losque l'on n'est pas en position
    if not onmarket then
    BELvVente=0
    endif
     
    //on regarde si le trade actuel à fait au moins x pips
    if shortonmarket and tradeprice-low>=startBEV then
    BELvVente=1
    endif
     
    //placer stoploss au prix d'entrée + x points
    if BELvVente=1 then
    exitshort at tradeprice+PointsToKeepV stop
    endif
    
    graph cv1 and cv2 and cv3 coloured(200,0,0)
    graph ca1 and ca2 and ca3 coloured(0,200,0)
    //graph buysignalbar
    #93953 quote
    lannoogeoffrey
    Participant
    Average

    Bonjour,

    J’ai refais des tests pendants le wkd et en live en essayant des changements dans le code mais au final rien n’y fait. J’ai systématiquement des prises de positions multiple durant la même bougie horaire alors qu’à première vue tout est bien clair dans le timeframe horaire, tout est déclaré en (close). L’objectif étant de pouvoir avoir un seul trade par signal horaire mais pouvoir cumuler plusieurs trades à chaque fois qu’un signal horaire se présente.

    Je remet la version du code de base et une image d’un exemple d’une multitude de trades pris durant la bougie horaire . Si vous pouviez le tester et m’aider, car je suis complètement bloqué.

    Merci d’avance.

    // Définition des paramètres du code
    DEFPARAM CumulateOrders = True // Cumul des positions activé
    // Annule tous les ordres en attente et ferme toutes les positions à 0:00, puis empêche toute création d'ordre avant l'heure "FLATBEFORE".
    //DEFPARAM FLATBEFORE = 090000
    // Annule tous les ordres en attente et ferme toutes les positions à l'heure "FLATAFTER"
    //DEFPARAM FLATAFTER = 221500
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
    
    // ---------------- Stratégie en horaire ----------------
    timeframe(1 hour, updateonclose)
    // ------ Définition de la pénétration ou de l'avalement d'une bougie --------
    
    TBP = high[1]-low[1] // taille de la bougie précédente mèches comprises
    
    PenetrationAchat = close > low[1]+0.7*TBP
    PenetrationVente = close < high[1]-0.7*TBP
    
    // -------- Définition du RSI --------
    
    RSIA = RSI[7](close)crosses over 70
    RSIV = RSI[7](close)crosses under 30
    
    // ---------- Définitions des MM --------
    
    MM50 = average[50](close)
    
    // -------- Définition des Bandes de Bollinger --------
    
    BBhaute = Average[20](close)+2.5*std[20](close)
    BBbasse = Average[20](close)-2.5*std[20](close)
    
    if close > (BBhaute+20*pipsize) then
    BBexclusionAchat =1
    else
    BBexclusionAchat =0
    endif
    
    if close < (BBbasse-20*pipsize) then
    BBexclusionVente =1
    else
    BBexclusionVente =0
    endif
    
    // -------- Conditions pour un signal d'achat --------
    
    ca1 = RSIA
    ca2 = PenetrationAchat
    ca3 = MM50 > MM50 [1]
    ca4 = BBexclusionAchat = 0
    
    
    If ca1 and ca2 and ca3 and ca4 and not daysForbiddenEntry then
    BUY 1 CONTRACT AT MARKET
    SET STOP pLOSS 150
    SET TARGET pPROFIT 1200
    ENDIF
    
    // ------ Conditions pour un signal de vente --------
    
    cv1 = RSIV
    cv2 = PenetrationVente
    cv3 = MM50 < MM50 [1]
    cv4 = BBexclusionVente = 0
    
    If cv1 and cv2 and cv3 and cv4 and not daysForbiddenEntry then
    SELLSHORT 1 CONTRACT AT MARKET
    SET STOP pLOSS 130
    SET Target pProfit 1000
    endif
    
    // ---------------- Gestion du trade en 5 minutes ----------------
    timeframe (5 minute,default)
    // -------- Fonction de mise à BE et déplacement du stop en cours de trade - Trailing stop --------
    
    //1/TRAILING STOP//////////////////////////////////////////////////////
    once trailinstop = 0   //1 on - 0 off
    startBreakevenAchat = 70 //how much pips/points in gain to activate the breakeven function?
    startBreakevenVente = 70
    PointsToKeep = 2 //how much pips/points to keep in profit above of below our entry price when the breakeven is activated (beware of spread)
    
    trailingstart1 = 200 //trailing will start @trailinstart points profit
    trailingstep1 = 100 //trailing step to move the "stoploss"
    trailingstart2 = 400 //trailing will start @trailinstart points profit
    trailingstep2 = 250 //trailing step to move the "stoploss"
    trailingstart3 = 700 //trailing will start @trailinstart points profit
    trailingstep3 = 500 //trailing step to move the "stoploss"
    
    //1 trailing stop function (ici l'effet trainant est suprimé et remplacé par un stopwin qui reste fixe)
    if trailinstop>0 then
    //reset the stoploss value
    IF NOT ONMARKET THEN
    newSL=0
    ENDIF
     
    //manage long positions
    IF LONGONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND high-tradeprice(1)>=startBreakevenAchat*pipsize THEN
    newSL = tradeprice(1)+PointsToKeep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND high-tradeprice(1)>=trailingstart1*pipsize THEN
    newSL = tradeprice(1)+trailingstep1*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND high-tradeprice(1)>=trailingstart2*pipsize THEN
    newSL = tradeprice(1)+trailingstep2*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND high-tradeprice(1)>=trailingstart3*pipsize THEN
    newSL = tradeprice(1)+trailingstep3*pipsize
    ENDIF
    ENDIF
     
    //manage short positions
    IF SHORTONMARKET THEN
    //first move (breakeven)
    IF newSL=0 AND tradeprice(1)-low>=startBreakevenVente*pipsize THEN
    newSL = tradeprice(1)-PointsToKeep*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND tradeprice(1)- low>=trailingstart1*pipsize THEN
    newSL = tradeprice(1)-trailingstep1*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND tradeprice(1)- low>=trailingstart2*pipsize THEN
    newSL = tradeprice(1)-trailingstep2*pipsize
    ENDIF
    //next moves
    IF newSL>0 AND tradeprice(1)- low>=trailingstart3*pipsize THEN
    newSL = tradeprice(1)-trailingstep3*pipsize
    ENDIF
    ENDIF
     
    //stop order to exit the positions
    IF newSL>0 THEN
    SELL AT newSL STOP
    EXITSHORT AT newSL STOP
    ENDIF
    endif
    
    Sans-titre.png Sans-titre.png
    #93955 quote
    lannoogeoffrey
    Participant
    Average

    Ok merci désolé on a posté en même temps 🙂

    Je serais donc patient 🙂

     

    Un tout grand merci

    #94026 quote
    Nicolas
    Keymaster
    Master

    J’ai été confronté au même problème ce matin avec un client, j’aurai du y penser avant, mais j’ai trouvé cette solution : 😉

    // Définition des paramètres du code
    DEFPARAM CumulateOrders = true // Cumul des positions activé
    // Annule tous les ordres en attente et ferme toutes les positions à 0:00, puis empêche toute création d'ordre avant l'heure "FLATBEFORE".
    DEFPARAM FLATBEFORE = 090000
    // Annule tous les ordres en attente et ferme toutes les positions à l'heure "FLATAFTER"
    DEFPARAM FLATAFTER = 220000
    daysForbiddenEntry = OpenDayOfWeek = 6 OR OpenDayOfWeek = 0
     
    //-------- Stratégie sur le 5 minutes --------
    timeframe(5 minutes, updateonclose)
    
    //Définition de la pénétration ou de l'avalement d'une bougie
    
    TBP = high[1]-low[1] // taille de la bougie précédente mèches comprises
    
    PenetrationAchat = close > low[1]+1*TBP
    PenetrationVente = close < high[1]-1*TBP
    
    //Définition du RSI
    
    RSIA = RSI[7](close)crosses over 70
    RSIV = RSI[7](close)crosses under 30
    
    //Définitions des MM
    
    MM50 = average[50](close)
    
    //Conditions pour un signal d'achat --------
    
    ca1 = RSIA
    ca2 = PenetrationAchat
    ca3 = MM50 > MM50 [1]
    
    //-------- condition d'achat
    
    achat= ca1 and ca2 and ca3
    if achat then
    buysignalbar=barindex
    endif
    
    
    
    //Conditions pour un signal de vente --------
    
    cv1 = RSIV
    cv2 = PenetrationVente
    cv3 = MM50 < MM50 [1]
    
    //-------- Condition de vente
    vente= cv1 and cv2 and cv3
    if vente then
    sellsignalbar=barindex
    endif
    
    
    
    //-------- Définition de l'unité de temps principale d'action pour la mise à Break Even
    timeframe(1 minute)
    
    if not daysForbiddenEntry and buysignalbar>lastbuysignalbar then
    buy 1 contract at market
    SET STOP pLOSS 30
    SET TARGET pPROFIT 30
    lastbuysignalbar=buysignalbar
    endif
    
    if not daysForbiddenEntry and sellsignalbar>lastsellsignalbar then
    sellshort 1 contract at market
    SET STOP pLOSS 30
    SET Target pProfit 30
    lastsellsignalbar=sellsignalbar
    endif
    
    //Définition du stop à BE (break-even)
    startBEA = 12 //Nombre de point pour activer le stopBE
    startBEV = 12
    PointsToKeepA = 2 //Nombre de point de mise en place du stop par rapport au point d'entrée afin d'être stopé non pas à 0 mais un peu en postif
    PointsToKeepV = 2
    
    
    //On remet le niveau de mise à BE à 0 losque l'on n'est pas en position
    if not onmarket then
    BELvAchat=0
    endif
     
    //on regarde si le trade actuel à fait au moins x pips
    if longonmarket and high-tradeprice>=startBEA then
    BELvAchat=1
    endif
     
    //placer stoploss au prix d'entrée + x points
    if BELvAchat=1 then
    sell at tradeprice+PointsToKeepA stop
    endif
    
    
     
    //On remet le niveau de mise à BE à 0 losque l'on n'est pas en position
    if not onmarket then
    BELvVente=0
    endif
     
    //on regarde si le trade actuel à fait au moins x pips
    if shortonmarket and tradeprice-low>=startBEV then
    BELvVente=1
    endif
     
    //placer stoploss au prix d'entrée + x points
    if BELvVente=1 then
    exitshort at tradeprice+PointsToKeepV stop
    endif
    
    //graph cv1 and cv2 and cv3 coloured(200,0,0)
    //graph ca1 and ca2 and ca3 coloured(0,200,0)
    //graph buysignalbar
    

    J’enregistre le barindex du signal en M5 et je l’utilise en M1 pour vérifier si il est différent du dernier. Cela contourne le “problème”, qui n’en ai plus vraiment un au final .. Mais si on ne le sait pas, on tourne en rond comme on vient de le faire ! 😎

    #94032 quote
    lannoogeoffrey
    Participant
    Average

    Un tout grand merci, je vais continuer les tests en réel sur base de ceci.

    #96573 quote
    Nicolas
    Keymaster
    Master

    Pour information, une nouvelle instruction (de type defparam) va être ajouté, nous permettant de choisir dans quel TF les ordres peuvent être lancés, sans avoir à faire des manips comme j’ai pu le faire avec ma dernière version du code.

    #102183 quote
    Nicolas
    Keymaster
    Master

    Finalement, il n’y aura pas de nouvelle instruction.

    Désormais, pour un ordre dans un timeframe (x, updateonclose), on ne passe l’ordre qu’une seule fois, lorsque le calcul de ce timeframe est fait et que les conditions sont réunies, et non pas a chaque chandelier du timeframe de base.

    Ce qui est logique AMHA 😀

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

Stratégie MTF, besoins d'explications sur le comportement de ma stratégie


ProOrder : Trading Automatique & Backtests

New Reply
Author
Summary

This topic contains 21 replies,
has 3 voices, and was last updated by Nicolas
6 years, 8 months ago.

Topic Details
Forum: ProOrder : Trading Automatique & Backtests
Language: French
Started: 03/14/2019
Status: Active
Attachments: 4 files
Logo Logo
Loading...