Les ordres en attente sont des ordres qui s'exécutent lorsque le prix atteint un niveau que nous avons spécifié. En d'autres termes, passer un ordre en attente signifie que l'on demande d'ouvrir une position à un certain niveau de prix. Ainsi, lorsque le prix touche le niveau prédéterminé, nous avons automatiquement une position de trading ouverte.
Dans un système de trading (EA), il existe 6 types d'ordres :
- Type 0 = Achat
- Type 1 = Vente
- Type 2 = Achat limite
- Type 3 = Vente limite
- Type 4 = Achat stop
- Type 5 = Vente stop
Parmi ces 6 types d'ordres, 4 types d'ordres en attente sont disponibles. Nous allons discuter de chaque type d'ordre en attente un par un avant de passer à l'action dans notre EA.
1. Achat Limite
Un ordre d'achat limite est un ordre qui s'exécute lorsque le prix descend en dessous d'un certain niveau. Pour cela, il faut que la structure soit modifiée, ce qui signifie que le prix doit être enregistré.
Note sur l'ordre d'achat :
OrderSend(Symbol(), 0, start_lot, Ask, 3, Ask-SL*Point,Ask+TP*Point, "", Magic, 0, Blue);
Il est crucial de tenir compte de la distance entre le prix actuel et le prix enregistré pour les ordres en attente.
Ask- Distance*Point
Ce qui donne :
OrderSend(Symbol(), 2, start_lot, Ask- Distance*Point, 3, Ask- Distance*Point-SL*Point,Ask-Distance*Point+TP*Point, "", Magic, 0, Blue);
Cela pourrait également être écrit comme suit :
OrderSend(Symbol(), OP_BUYLIMIT, start_lot, Ask- Distance*Point, 3, Ask- Distance*Point-SL*Point,Ask-Distance*Point+TP*Point, "", Magic, 0, Blue);
2. Vente Limite
Les ordres de vente limite sont des ordres qui s'exécutent lorsque le prix se situe au-dessus d'un certain niveau.
Comme pour l'ordre d'achat limite, l'élément essentiel est le type d'ordre et la distance. Voici un exemple :
OrderSend(Symbol(), 3, start_lot, Bid+Distance*Point, 3, Bid +Distance*Point+ SL*Point,Bid+Distance*Point-TP*Point, "", Magic, 0, Red);
Cela pourrait également être écrit comme suit :
OrderSend(Symbol(), OP_SELLLIMIT, start_lot, Bid+Distance*Point, 3, Bid+Distance*Point + SL*Point,Bid+Distance*Point-TP*Point, "", Magic, 0, Red);
3. Achat Stop
Les ordres d'achat stop s'exécutent lorsque le prix dépasse un certain niveau.
Voici un exemple :
OrderSend(Symbol(), 4, start_lot, Ask+ Distance*Point, 3, Ask+ Distance*Point-SL*Point,Ask+Distance*Point+TP*Point, "", Magic, 0, Blue);
Cela pourrait également être écrit comme suit :
OrderSend(Symbol(), OP_BUYSTOP, start_lot, Ask+ Distance*Point, 3, Ask+ Distance*Point-SL*Point,Ask+Distance*Point+TP*Point, "", Magic, 0, Blue);
4. Vente Stop
Les ordres de vente stop s'exécutent lorsque le prix descend en dessous d'un certain niveau.
Voici un exemple :
OrderSend(Symbol(), 5, start_lot, Bid-Distance*Point, 3, Bid -Distance*Point+SL*Point,Bid-Distance*Point-TP*Point, "", Magic, 0, Red);
Cela pourrait également être écrit comme suit :
OrderSend(Symbol(), OP_SELLSTOP, start_lot, Bid-Distance*Point, 3, Bid- Distance*Point+SL*Point,Bid-Distance*Point-TP*Point, "", Magic, 0, Red);
Comme promis, nous allons essayer de rendre notre EA simple en utilisant tous les quatre types d'ordres en attente ! Mais avant de commencer, il est important de passer commande selon le type d'ordre, je vous fournis un script pour faciliter cela :
int totalorder(int m) { int total = 0; for (int i = 0; i < OrdersTotal(); i++) { if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue; if (OrderSymbol() != Symbol()|| OrderMagicNumber()!=Magic || OrderType()!=m ) continue; total++; } return(total); }
Voici comment l'appeler :
Exemple :
Pour l'achat limite
if(totalorder(OP_BUYLIMIT)==0){res=OrderSend(Symbol(), 2, start_lot, Ask- Distance*Point, 3, Ask- Distance*Point-SL*Point,Ask-Distance*Point+TP*Point, "", Magic, 0, Blue);}
Ou
if(totalorder(2)==0){res=OrderSend(Symbol(), OP_BUYLIMIT, start_lot, Ask- Distance*Point, 3, Ask- Distance*Point-SL*Point,Ask-Distance*Point+TP*Point, "", Magic, 0, Blue);}
Pour la vente limite
if(totalorder(OP_SELLLIMIT)==0){res=OrderSend(Symbol(), 3, start_lot, Bid+Distance*Point, 3, Bid +Distance*Point+SL*Point,Bid+Distance*Point-TP*Point, "", Magic, 0, Red);}
Ou
if(totalorder(3)==0){res=OrderSend(Symbol(), OP_SELLLIMIT, start_lot, Bid+Distance*Point, 3, Bid +Distance*Point+SL*Point,Bid+Distance*Point-TP*Point, "", Magic, 0, Red);}
Continuons avec l'Ea....
J'ai essayé de rendre l'Ea simple pour une meilleure compréhension.
Veuillez observer ci-dessous :
//+------------------------------------------------------------------+ //| EA Pending Order.mq4 | //| Copyright 2016, MetaQuotes Software Corp. | //| https://www.mql5.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2016, WidiPramana." #property link "https://www.mql5.com" #property version "1.00" #property strict extern string Name_EA = "PendingOrder"; extern int Start_Hour = 6; extern int End_Hour = 20; extern int TP = 20; extern int SL = 100; extern double Lots = 0.01; extern int Distance = 15; extern int Magic = 69; double slb,tpb,sls,tps,pt; int res,wt,wk,tiket,ticet; //+------------------------------------------------------------------+ //| fonction d'initialisation de l'expert | //+------------------------------------------------------------------+ int init() { //---- if(Digits==3 || Digits==5) pt=10*Point; else pt=Point; //---- return(0); } //+------------------------------------------------------------------+ //| fonction de désinitialisation de l'expert | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| fonction de démarrage de l'expert | //+------------------------------------------------------------------+ int start() { label(); if(Hour_trade()==1){ if(totalorder(2)==0){res=OrderSend(Symbol(), OP_BUYLIMIT,NR(Lots), Ask-Distance*Point, 3, Ask-Distance*Point-SL*Point,Ask-Distance*Point+TP*Point, "", Magic, 0, Blue);} if(totalorder(3)==0){res=OrderSend(Symbol(), OP_SELLLIMIT,NR(Lots) , Bid+Distance*Point, 3, Bid+Distance*Point+SL*Point,Bid+Distance*Point-TP*Point, "", Magic, 0, Red);} if(totalorder(4)==0){res=OrderSend(Symbol(), OP_BUYSTOP,NR(Lots) , Ask+Distance*Point, 3, Ask+Distance*Point-SL*Point,Ask+Distance*Point+TP*Point, "", Magic, 0, Blue);} if(totalorder(5)==0){res=OrderSend(Symbol(), OP_SELLSTOP,NR(Lots) , Bid-Distance*Point, 3, Bid-Distance*Point+SL*Point,Bid-Distance*Point-TP*Point, "", Magic, 0, Red);} } return(0); } //+------------------------------------------------------------------+ int Hour_trade() { bool trade = false; if(Start_Hour > End_Hour){ if (Hour() >= Start_Hour || Hour() < End_Hour) trade = true; } else if (Hour() >= Start_Hour && Hour() < End_Hour) trade = true; return (trade); } int totalorder( int tipe) { int total=0; for(int i=0; i<OrdersTotal(); i++) { if(!OrderSelect(i,SELECT_BY_POS,MODE_TRADES)) continue; if(OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic || OrderType()!=tipe) continue; total++; } return(total); } double NR(double thelot) { double maxlots = MarketInfo(Symbol(), MODE_MAXLOT), minilot = MarketInfo(Symbol(), MODE_MINLOT), lstep = MarketInfo(Symbol(), MODE_LOTSTEP); double lots = lstep * NormalizeDouble(thelot / lstep, 0); lots = MathMax(MathMin(maxlots, lots), minilot); return (lots); } void label() { Comment(" ", " ", " ------------------------------------------------", " :: Ordre en Attente", " ------------------------------------------------", " :: Spread : ", MarketInfo(Symbol(), MODE_SPREAD), " :: Leverage : 1 : ", AccountLeverage(), " :: Equity : ", AccountEquity(), " :: Heure Serveur :", Hour(), ":", Minute(), " ------------------------------------------------"); }
Le fonctionnement de l'Ea est le suivant :

J'espère que cela vous sera utile, n'hésitez pas à laisser un commentaire.
Bonne chance et bonne journée !
Articles connexes
- Générer des Signaux de Trading avec MQL5 Wizard : Étoiles du Matin/du Soir et RSI
- Utiliser MQL5 Wizard pour Créer un Expert Advisor Basé sur les Modèles de Chandeliers Englobants et MFI
- Développez un Expert Advisor avec MQL5 : Signaux de Trading 3 Corbeaux Noirs / 3 Soldats Blancs + RSI
- Générez des Signaux de Trading avec MQL5 Wizard : Dark Cloud Cover et Piercing Line
- AOCCI : Un Expert pour MetaTrader 5