Placer les 3 ordres (dont 2 en attentes) en même temps svp…

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #52036 quote
    Toto le Heros
    Participant
    Veteran

    Bonjour,

    J’ai créé ce petit code UT=5min sur base des fractales de Bill Williams (indicateur trouvé dans la bibliothèque, merci).

    Le code est très simple. On achète si on casse la fractale haute et on vend à découvert si on casse la fractale basse.

    Pour la sortie, l’idée est de définir un STOP LOSS sur la fractale basse au moment de la prise de position (pour une position longue) et sur la fractale haute (pour une position short) ; et de placer un TARGET PROFIT = STOP LOSS.

    Voici donc mon code, qui fonctionne très bien. Sauf que…

    Les 2 ordres en attente (STOP et LIMITE) ne sont placés en même temps que l’ordre de position, mais 1 chandelier + tard (ici 5 minutes)… Donc je suis “sans filet” pendant 5 minutes. Est-ce possible d’anticiper et de placer les 3 ordres (dont 2 en attentes) en même temps svp ?

    D’avance merci.

    DEFPARAM CumulateOrders = False
    
    /////////// FRACTALS BILL WILLIAMS
    //Variable:
    
    cp = 2 //(default)
    
    if high[cp] >= highest[2*cp+1](high) then
    LH = 1
    else
    LH=0
    endif
    
    if low[cp] <= lowest[2*cp+1](low)  then
    LL= -1
    else
    LL=0
    endif
    
    if LH=1 then
    hil = high[cp]
    endif
    
    if LL  = -1 then
    LOL=low[cp]
    endif
    //////////////////////////////////////////////
    
    
    indicator1 = LOL
    indicator2 = hil
    
    c1 = close>indicator2
    
    c2 = close<indicator1
    
    
    if c1 then
    Filter=1
    elsif c2 then
    Filter=-1
    else
    Filter=0
    endif
    
    // Conditions pour ouvrir une position acheteuse
    IF time>080000 and time<180000 and NOT LongOnMarket AND Filter=1 THEN
    BUY 1 CONTRACTS AT MARKET
    A=LOL
    ENDIF
    
    // Conditions pour fermer une position acheteuse
    If LongOnMarket THEN
    SELL AT A STOP
    SELL AT positionprice+positionprice-A LIMIT
    ENDIF
    
    // Conditions pour ouvrir une position en vente à découvert
    IF time>080000 and time<180000 and NOT ShortOnMarket AND Filter=-1 THEN
    SELLSHORT 1 CONTRACTS AT MARKET
    B=hil
    ENDIF
    
    // Conditions pour fermer une position acheteuse
    If ShortOnMarket THEN
    EXITSHORT AT B STOP
    EXITSHORT AT positionprice-(B-positionprice) LIMIT
    ENDIF
    
    #52132 quote
    Nicolas
    Keymaster
    Master

    Dans ce cas il faudrait mieux placer un stoploss et un takeprofit dés la prise de position (et ce sera en plus compatible avec les comptes de trading à risques limités), pourquoi ne pas utiliser un SET TARGET PROFIT et un SET STOP LOSS après la ligne 48 et 60, ces distances en valeurs en points sont facilement calculables.

    #52150 quote
    Toto le Heros
    Participant
    Veteran

    Merci de ta réponse Nicolas.

    Ca me semblait plus simple à “ma” façon… 😉

    Je vais essayer un “mystop=positionprice-LOL” puis “SET STOP LOSS = mystop ; SET TARGET PROFIT=mystop ; mais de mémoire çà n’a pas bien fonctionné qunand j’ai (déjà) essayé…

    #52311 quote
    Toto le Heros
    Participant
    Veteran

    Arghh… J’ai fait le code ci-dessous, qui fonctionne parfaitement bien en BACKTEST, mais quand j’essaie de lancer la stratégie en démo dans ProOrder Auto Trading il me met le message d’erreur suivant :

    “Ce système de trading a été arrêté car il a essayé de placer un Stop ou une Limite avec un prix négatif. Merci d’ajouter des protections à votre code pour éviter la placement d’ordres possédant un prix négatif.”

    Puis-je contourner cela svp ?

    DEFPARAM CumulateOrders = False
    
    /////////// FRACTALS BILL WILLIAMS
    //Variable:
    
    cp = 2 //(default)
    
    if high[cp] >= highest[2*cp+1](high) then
    LH = 1
    else
    LH=0
    endif
    
    if low[cp] <= lowest[2*cp+1](low)  then
    LL= -1
    else
    LL=0
    endif
    
    if LH=1 then
    hil = high[cp]
    endif
    
    if LL  = -1 then
    LOL=low[cp]
    endif
    //////////////////////////////////////////////
    
    
    indicator1 = LOL
    indicator2 = hil
    
    c1 = close>indicator2
    
    c2 = close<indicator1
    
    
    if c1 then
    Filter=1
    elsif c2 then
    Filter=-1
    else
    Filter=0
    endif
    
    //
    COMPTEUR=COMPTEUR+1
    
    // Conditions pour ouvrir une position acheteuse
    IF time>080000 and time<180000 and NOT LongOnMarket AND Filter=1 THEN
    BUY 1 CONTRACTS AT MARKET
    COMPTEUR=0
    ENDIF
    
    DISTANCE=positionprice-LOL[COMPTEUR]
    SET TARGET PROFIT DISTANCE
    SET STOP LOSS DISTANCE
    
    // Conditions pour ouvrir une position en vente à découvert
    //IF time>080000 and time<180000 and NOT ShortOnMarket AND Filter=-1 THEN
    //SELLSHORT 1 CONTRACTS AT MARKET
    //ENDIF
    
    #52518 quote
    Nicolas
    Keymaster
    Master

    Tu dois inclure les instructions pour placer les stoploss et takeprofit directement après avoir passé ton order à la ligne 51, personnellement je le coderai de cette manière :

    // Conditions pour ouvrir une position acheteuse
    IF time>080000 and time<180000 and NOT LongOnMarket AND Filter=1 THEN
     BUY 1 CONTRACTS AT MARKET
     set stop loss close-LOL
     set target profit close-LOL
     COMPTEUR=0
    ENDIF
Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.

Placer les 3 ordres (dont 2 en attentes) en même temps svp…


Support ProOrder

New Reply
Author
Summary

This topic contains 4 replies,
has 2 voices, and was last updated by Nicolas
8 years, 2 months ago.

Topic Details
Forum: Support ProOrder
Language: French
Started: 11/09/2017
Status: Active
Attachments: 1 files
Logo Logo
Loading...