Rejoindre la communauté
banner_forum
Devenez membre de la plus grande
communauté francophone sur le Forex
Partagez, échangez et apprenez en gagnant des crédits sur votre compte de trading

Est il possible de coder un TRAILING ORDER ?

  • Rengou

    Salut mes frères. S'il vous plaît existe til un code qui permet de déplacer des ordres BUY STOP et SELL STOP ?
    exactement comme le fonctionnement de trailing stop. Mais cette fois c'est plutôt le BUY STOP TRAILING,, SELL STOP TRAILING. aidez moi s'il vous plaît
  • stani

    Oui, mais honnêtement, cela ne présente pas d’intérêt.
    Sur quelle base déplacer l'ordre? Un écart ? Il suffit d'attendre qu'il se produise pour rentrer. Une moyenne? Il suffit d'attendre de la toucher. Etc...
  • Rengou

    Merci Stani. Parlant d'intérêt, je travaille sur un système de trading à l'aveugle depuis un certain temps. Un système qui n'a pas besoin d'indicateurs ni de Time frame. Mais pour réussir mon coup, je dois avoir un EA capable de bouger mes pending order. Or ce bout de code m'échappe
  • riden — en réponse à Rengou dans son message #114095

    Salut,

    J'ai rédigé rapidement une fonction qui permet de déplacer les BUY STOP et SELL STOP déjà existants. Après, c'est à toi de définir les conditions d’exécution de cette fonction. La fonction prend 3 paramètres: le numéro de ticket de l'ordre, de combien de pips l'ordre sera déplacé et dans quelle sens l'ordre sera déplacé. fais attention de ne pas exécuter la fonction à chaque tick. J'ai fait quelques alertes pour prévenir des erreurs les plus communes lors de la modification de l'ordre.


    Code
    int magic1 = 777; int set_h1,set_h2,set_h3,set_h4,set_h5,set_h6,set_h7,set_h8; //---------------------------------------------Diff en pips entre deux niveau de prix-----------------------------// double diff_pips(string paire, double p1, double p2){ double res; res=MathAbs(p1-p2)/(MarketInfo(paire,MODE_POINT)*10); return(res);} //----------------------------------------------fonction de déplacement des BUY_STOP et SELL_STOP--------------------- void move_order(int ticket, int pips, string eloigner_rapprocher){ double new_IN,new_SL,new_TP, ecart_min; bool mod1; int sig = 1; if (eloigner_rapprocher=="rapprocher") sig = -1; // eloigner ou rapprocher les ordres par rapport au prix actuel if(OrderSelect(ticket,SELECT_BY_TICKET)){ ecart_min = MarketInfo(OrderSymbol(),MODE_STOPLEVEL); if(OrderMagicNumber()== magic1){ if(OrderType()==OP_BUYSTOP){ new_IN = NormalizeDouble(OrderOpenPrice()+sig*pips*10*MarketInfo(OrderSymbol(),MODE_POINT),(int)MarketInfo(OrderSymbol(),MODE_DIGITS)); new_TP = NormalizeDouble(OrderTakeProfit()+sig*pips*10*MarketInfo(OrderSymbol(),MODE_POINT),(int)MarketInfo(OrderSymbol(),MODE_DIGITS)); if(OrderTakeProfit()==0) new_TP =0; new_SL = NormalizeDouble(OrderStopLoss()+sig*pips*10*MarketInfo(OrderSymbol(),MODE_POINT),(int)MarketInfo(OrderSymbol(),MODE_DIGITS)) ; if(OrderStopLoss()==0) new_SL =0; if(new_IN<MarketInfo(OrderSymbol(),MODE_BID)) { if(set_h1!=Hour()){Alert("IN ne peut pas être au-dessous du prix actuel en BUY_STOP");set_h1=Hour();} return;} if(diff_pips(OrderSymbol(),new_IN,new_SL)*10 < ecart_min) { if(set_h2!=Hour()){Alert("SL trop proche du IN");set_h2=Hour();} return;} if(diff_pips(OrderSymbol(),new_IN,new_TP)*10 < ecart_min) { if(set_h3!=Hour()){Alert("TP trop proche du IN");set_h3=Hour();} return;} if(diff_pips(OrderSymbol(),new_IN,MarketInfo(OrderSymbol(),MODE_BID))*10 < ecart_min) {if(set_h4!=Hour()){Alert("IN trop proche du prix actuel");set_h4=Hour();} return;} mod1 = OrderModify(ticket,new_IN,new_SL,new_TP,0,clrNONE);} if(OrderType()==OP_SELLSTOP){ new_IN = NormalizeDouble(OrderOpenPrice()-sig*pips*10*MarketInfo(OrderSymbol(),MODE_POINT),(int)MarketInfo(OrderSymbol(),MODE_DIGITS)); new_TP = NormalizeDouble(OrderTakeProfit()-sig*pips*10*MarketInfo(OrderSymbol(),MODE_POINT),(int)MarketInfo(OrderSymbol(),MODE_DIGITS)) ; if(OrderTakeProfit()==0) new_TP =0; new_SL = NormalizeDouble(OrderStopLoss()-sig*pips*10*MarketInfo(OrderSymbol(),MODE_POINT),(int)MarketInfo(OrderSymbol(),MODE_DIGITS)) ; if(OrderStopLoss()==0) new_SL =0; if(new_IN>MarketInfo(OrderSymbol(),MODE_ASK)) { if(set_h5!=Hour()){Alert("IN ne peut pas être au-dessus du prix actuel en SELL_STOP");set_h5=Hour();} return;} if(diff_pips(OrderSymbol(),new_IN,new_SL)*10 < ecart_min) { if(set_h6!=Hour()){Alert("SL trop proche du IN");set_h6=Hour();} return;} if(diff_pips(OrderSymbol(),new_IN,new_TP)*10 < ecart_min) { if(set_h7!=Hour()){Alert("TP trop proche du IN");set_h7=Hour();} return;} if(diff_pips(OrderSymbol(),new_IN,MarketInfo(OrderSymbol(),MODE_ASK))*10 < ecart_min) { if(set_h8!=Hour()){Alert("IN trop proche du prix actuel");set_h8=Hour();} return;} mod1 = OrderModify(ticket,new_IN,new_SL,new_TP,0,clrNONE);} }}}
  • Rengou — en réponse à riden dans son message #114124

    Bonjour RIDEN. Depuis avril , c'est aujourdhui que je reviens sur le forum. Merci pour ta reponse. tout de suite je vais compiler et te dire la suite. Merci
  • lefeuvr3

    Si cela peut aider

    Code
    //+------------------------------------------------------------------+ //| Trailing Stop | //+------------------------------------------------------------------+ void trail() { for(int i=0; i<OrdersTotal(); i++) { if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) if(OrderSymbol()==Symbol()) { if(OrderType()==OP_BUYSTOP) { if(Bid - OrderOpenPrice() > TrailingStop * MarketInfo(OrderSymbol(),MODE_POINT)) { if(OrderStopLoss() < Bid - TrailingStop * MarketInfo(OrderSymbol(), MODE_POINT)) { bool modify1=OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop*MarketInfo(OrderSymbol(),MODE_POINT),OrderTakeProfit(),Red); } } } else if(OrderType()==OP_SELLSTOP) { if(OrderOpenPrice()-Ask>TrailingStop*MarketInfo(OrderSymbol(),MODE_POINT)) { if((OrderStopLoss()>Ask+TrailingStop*MarketInfo(OrderSymbol(),MODE_POINT)) || (OrderStopLoss()==0)) { bool modify2=OrderModify(OrderTicket(),OrderOpenPrice(), Ask+TrailingStop*MarketInfo(OrderSymbol(),MODE_POINT),OrderTakeProfit(),Red); } } } } } } //+------------------------------------------------------------------+