Entrer et sortir de position sur chaque barre (ou presque)

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #201054 quote
    Xavier61
    Participant
    New

    Bonjour,
    Je souhaiterais coder la stratégie suivante (en 10 mn) :
    si la barre clôture verte (close > open), entrer long à l’ouverture de la barre suivante ; si la barre d’ouverture de trade clôture verte, clôturer le trade au marché (plus-value) et acheter à nouveau à l’entrée de la barre suivante, etc. Inversement pour une barre rouge (close < <open). Pas de target profit, mais des stops sont prévus.

    Les diverses rédactions de codes que j’ai réalisées et remaniées n’exécutent pas cette stratégie avec régularité : en gros, lorsqu’un trade est clôturé (en gain notamment), le système est incapable de générer une nouvelle entrée à l’ouverture de la barre suivante (NextOpenBar). Il reprend à la suivante encore (donc 2 barres plus loin). Est-ce inhérent au logiciel ou est-ce dû à une mauvaise rédaction ? Lui est-il impossible de lancer 2 actions en même temps ?

    Ci-joint la dernière version du code 😉

    DEFPARAM CumulateOrders = true
    DEFPARAM FlatAfter = 172959
    
    HeureDebut = 090000
    HeureFin = 172959
    
    Plage = (time >= HeureDebut AND time <= HeureFin)
    
    //Entrée LONG
    ch = close > open //chandelier haussier
    
    IF NOT SHORTONMARKET AND ch AND Plage THEN
    IF LONGONMARKET THEN
    SELL AT MARKET
    BUY 1 contract AT MARKET NextBarOpen
    op = open
    TPL = TradePrice //TradePrice Long
    PrixStopL = (TPL - (TPL*0.0015))
    IF (TPL - op) > (TPL*0.0009) THEN
    SET STOP PRICE op
    ELSIF (TPL - op) < (TPL*0.0009) THEN
    SET STOP PRICE PrixStopL
    ENDIF
    ELSIF NOT LONGONMARKET THEN
    BUY 1 contract AT MARKET NextBarOpen
    op = open
    TPL = TradePrice //TradePrice Long
    PrixStopL = (TPL - (TPL*0.0015))
    IF (TPL - op) > (TPL*0.0009) THEN
    SET STOP PRICE op
    ELSIF (TPL - op) < (TPL*0.0009) THEN
    SET STOP PRICE PrixStopL
    ENDIF
    ENDIF
    ENDIF
    
    IF LONGONMARKET AND ch AND Plage THEN
    SELL AT close LIMIT
    ENDIF
    
    //cl = close > TPL //clôture Long
    
    
    //==========================================
    
    //Entrée SHORT
    cb = close < open
    
    IF NOT LONGONMARKET AND cb AND Plage THEN
    IF SHORTONMARKET THEN
    EXITSHORT AT MARKET
    SELLSHORT 1 contract AT MARKET NextBarOpen
    op = open
    TPS = TradePrice //TradePrice Short
    PrixStopS = (TPS + (TPS*0.0015))
    IF (op -TPS) > (TPL*0.0009) THEN
    SET STOP PRICE op
    ELSIF (op - TPS) < (TPL*0.0009) THEN
    SET STOP PRICE PrixStopS
    ENDIF
    ELSIF NOT SHORTONMARKET THEN
    SELLSHORT 1 contract AT MARKET NextBarOpen
    op = open
    TPS = TradePrice //TradePrice Short
    PrixStopS = (TPS + (TPS*0.0015))
    IF (op -TPS) > (TPL*0.0009) THEN
    SET STOP PRICE op
    ELSIF (op - TPS) < (TPL*0.0009) THEN
    SET STOP PRICE PrixStopS
    ENDIF
    ENDIF
    ENDIF
    
    IF SHORTONMARKET AND cb AND Plage THEN
    EXITSHORT AT close LIMIT
    ENDIF
    
    //cs = close < TPS //clôture Short
    

     

    Merci et bonne journée.

    #201403 quote
    Nicolas
    Keymaster
    Master

    Je pense qu’il y a peut être un problème dans la succession de tests “LONGONMARKET” et “SHORTONMARKET”. Par ailleurs, lorsque tu places un stop ou une limit, ce prix s’applique à tous les ordres ouverts, il ne peut pas y avoir de takeprofit/stoploss individuel à chaque ordre. Aussi, visuellement sur ton graphique, l’ordre s’ouvre à l’open suivant (inutile d’ailleurs d’utiliser l’instruction NextBarOpen qui est obsolète), donc un décalage qui peut gêner ta lecture.

    #201533 quote
    Xavier61
    Participant
    New

    Merci Nicolas, je vais retravailler la rédaction, simplifier quelques enchaînements, et alléger les instructions de Stop.

    J’ai pensé aussi tenter de contourner le problème en transposant en TF une minute et en comptant ensuite le nombre de barres voulu pour obtenir un équivalent TF 10 minutes. L’idée serait d’entrer à l’ouverture de la première minute (ex. 10h20), sortir à l’ouverture de la 10e (10h29), pour ensuite pouvoir entrer à nouveau à l’ouverture de la 11e minute, qui serait la première de la barre 10′ suivante (10h30). En ce cas, il y aurait bien un espace de temps en “NOT ONMARKET” non ?

    Je reviendrai donner un retour de ce travail, et partager les scripts s’ils donnent des tests satisfaisants.

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

Entrer et sortir de position sur chaque barre (ou presque)


ProOrder : Trading Automatique & Backtests

New Reply
Author
author-avatar
Xavier61 @xavier61 Participant
Summary

This topic contains 2 replies,
has 2 voices, and was last updated by Xavier61
3 years, 5 months ago.

Topic Details
Forum: ProOrder : Trading Automatique & Backtests
Language: French
Started: 09/19/2022
Status: Active
Attachments: No files
Logo Logo
Loading...