
Mar
Introduction
Tous les traders se tournent à un moment donnée vers le price action. Ce n’est évidemment pas une simple technique d’analyse des cours, mais un système permettant d’éavluer statistiquement le futur mouvement du prix. Dans cet article nous analysons le motif d’enveloppement (Engulfing pattern) en créant un robot de trading gratuit pertinent qui utilise cette stratégie.
Règle de la stratégie « Engulfing pattern »
La détection
La philosophie de ce pattern est de localiser une bougie qui couvre complètement le corps de la bougie qui la précède. On peut également élargir cette définition en ajoutant l’enveloppement des ombres.
Il y a donc deux types de bougies enveloppantes :
- BUOVB — Bullish Outside Vertical Bar (bougie enveloppante haussière)
- BEOVB — Bearish Outside Vertical Bar (bougie enveloppante baissière)
Rentrons dans le détail de chacune des configurations :
- BUEVB : Le graphique ci-dessus nous montre que le plus haut de la bougie baissière enveloppante est au-dessus du plus haut de la bougie précédente. Inversement pour les plus bas.
- BUOVB : Le graphique ci-dessus nous montre que le plus haut de la bougie haussière enveloppante est au-dessus du plus haut de la bougie précédente. Inversement pour les plus bas.
Les règles
- Nous utiliserons uniquement des TF élevés : H4, D1
- Pour plus de précisions et moins de faux signaux, nous devrions nous appuyer sur les supports/résistances, niveaux de Fibonacci et les autres patterns
- L’utilisation d’ordre pending est recommandé pour éviter une entrée prématurée sur le marché
- Les signaux seront ignorés dans le cas d’une faible volatilité
Les points d’entrées
BUOVB
Dans notre exemple nous nous baserons sur le graphique ci-dessus :
- Le prix d’entrée de l’ordre BUY STOP se situera juste au-dessus du plus haut de la bougie enveloppante
- Le STOPLOSS se situera juste au-dessous du plus bas de cette même bougie
- Pour finir le TAKEPROFIT sera placé juste au-dessous de la prochaine résistance
BEOVB
Dans cet nouvel exemple nous nous baserons sur le graphique ci-dessus :
- Le prix d’entrée de l’ordre SELL STOP se situera juste au-dessous du plus bas de la bougie enveloppante
- Le STOPLOSS se situera juste au-dessus du plus bas de cette même bougie
- Pour finir le TAKEPROFIT sera placé juste au-dessus du prochain support
L’algorithme de trading
Si vous avez assidûment lu le début de cet article, vous savez maintenant reconnaître notre pattern « Engulfing » et entrer correctement sur le marché.
A présent nous allons voir comment créer notre robot de trading.
Pour commencer, ouvrez MetaEditor lié à votre plateforme MetaTrader 4 et créez un nouveau Expert Advisor.
Devant s’ouvre donc une page presque blanche avec les principales fonctions de l’expert advisor.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | //+------------------------------------------------------------------+ //| BEOVB_BUOVB_Bar.mq4 | //| Copyright 2015, Iglakov Dmitry. | //| cjdmitri@gmail.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, Iglakov Dmitry." #property link "cjdmitri@gmail.com" #property version "1.00" #property strict //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { //--- //--- return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { //--- } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- } //+------------------------------------------------------------------+ |
Traduisons la détection de la pattern en algorithme MQL4
Aprs avoir crée un Expert Advisor nous devons détecter si nous sommes en présence de notre pattern à chaque fermeture de bougie.
Pour ce faire nous rajoutons des variables que nous initialiserons.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | //+------------------------------------------------------------------+ //| BEOVB_BUOVB_Bar.mq4 | //| Copyright 2015, Iglakov Dmitry. | //| cjdmitri@gmail.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, Iglakov Dmitry." #property link "cjdmitri@gmail.com" #property version "1.00" #property strict double open1,//first candle Open price open2, //second candle Open price close1, //first candle Close price close2, //second candle Close price low1, //first candle Low price low2, //second candle Low price high1, //first candle High price high2; //second candle High price //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { //--- define prices of necessary bars open1 = NormalizeDouble(iOpen(Symbol(), Period(), 1), Digits); open2 = NormalizeDouble(iOpen(Symbol(), Period(), 2), Digits); close1 = NormalizeDouble(iClose(Symbol(), Period(), 1), Digits); close2 = NormalizeDouble(iClose(Symbol(), Period(), 2), Digits); low1 = NormalizeDouble(iLow(Symbol(), Period(), 1), Digits); low2 = NormalizeDouble(iLow(Symbol(), Period(), 2), Digits); high1 = NormalizeDouble(iHigh(Symbol(), Period(), 1), Digits); high2 = NormalizeDouble(iHigh(Symbol(), Period(), 2), Digits); } //+------------------------------------------------------------------+ |
Maintenant détectons nos 2 types de pattern :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | void OnTick() { //--- define prices of necessary bars open1 = NormalizeDouble(iOpen(Symbol(), Period(), 1), Digits); open2 = NormalizeDouble(iOpen(Symbol(), Period(), 2), Digits); close1 = NormalizeDouble(iClose(Symbol(), Period(), 1), Digits); close2 = NormalizeDouble(iClose(Symbol(), Period(), 2), Digits); low1 = NormalizeDouble(iLow(Symbol(), Period(), 1), Digits); low2 = NormalizeDouble(iLow(Symbol(), Period(), 2), Digits); high1 = NormalizeDouble(iHigh(Symbol(), Period(), 1), Digits); high2 = NormalizeDouble(iHigh(Symbol(), Period(), 2), Digits); //--- Finding bearish pattern BEOVB if(low1 < low2 &&// First bar's Low is below second bar's Low high1 > high2 &&// First bar's High is above second bar's High close1 < open2 && //First bar's Close price is below second bar's Open open1 > close1 && //First bar is a bearish bar open2 < close2) //Second bar is a bullish bar { //--- we have described all conditions indicating that the first bar completely engulfs the second bar and is a bearish bar } //--- Finding bullish pattern BUOVB if(low1 < low2 &&// First bar's Low is below second bar's Low high1 > high2 &&// First bar's High is above second bar's High close1 > open2 && //First bar's Close price is higher than second bar's Open open1 < close1 && //First bar is a bullish bar open2 > close2) //Second bar is a bearish bar { //--- we have described all conditions indicating that the first bar completely engulfs the second bar and is a bullish bar } |
Puis nous rajoutons :
- Des paramètres : stop orders, slippage, order expiration time, EA magic number, lot. Le stoploss peut être omis car il est déduit de la stratégie
- Variables locales : pour convertir les paramètres en variable à exploiter dans l’algorithme
- Nous avons également besoin d’une variable permettant de quantifier l’écart entre le plus haut ou le plus bas de la bougie enveloppante (pour définir le stoploss et point d’entrée). Ce paramètre se nomme Interval.
- Une variable permettant de ne pas rentrer plusieurs fois sur le même niveau : timeBUOVB_BEOVB
- Et une dernière variable pour vérifier la taille de la bougie enveloppante : bar1size
Nous obtenons le code suivant :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | //+------------------------------------------------------------------+ //| BEOVB_BUOVB_bar.mq4 | //| Copyright 2015, Iglakov Dmitry. | //| cjdmitri@gmail.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, Iglakov Dmitry." #property link "cjdmitri@gmail.com" #property version "1.00" #property strict extern int interval = 25; //Interval extern double lot = 0.1; //Lot Size extern int TP = 400; //Take Profit extern int magic = 962231; //Magic number extern int slippage = 2; //Slippage extern int ExpDate = 48; //Expiration Hour Order extern int bar1size = 900; //Bar 1 Size double buyPrice,//define BuyStop setting price buyTP, //Take Profit BuyStop buySL, //Stop Loss BuyStop sellPrice, //define SellStop setting price sellTP, //Take Profit SellStop sellSL; //Stop Loss SellStop double open1,//first candle Open price open2, //second candle Open price close1, //first candle Close price close2, //second candle Close price low1, //first candle Low price low2, //second candle Low price high1, //first candle High price high2; //second candle High price datetime _ExpDate =0; // local variable for defining pending orders expiration time double _bar1size;// local variable required to avoid a flat market datetime timeBUOVB_BEOVB;// time of a bar when pattern orders were opened, to avoid re-opening //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { double _bid = NormalizeDouble(MarketInfo (Symbol(), MODE_BID), Digits); // define Low price double _ask = NormalizeDouble(MarketInfo(Symbol(), MODE_ASK), Digits); //define High price double _point = MarketInfo(Symbol(), MODE_POINT); //--- define prices of necessary bars open1 = NormalizeDouble(iOpen(Symbol(), Period(), 1), Digits); open2 = NormalizeDouble(iOpen(Symbol(), Period(), 2), Digits); close1 = NormalizeDouble(iClose(Symbol(), Period(), 1), Digits); close2 = NormalizeDouble(iClose(Symbol(), Period(), 2), Digits); low1 = NormalizeDouble(iLow(Symbol(), Period(), 1), Digits); low2 = NormalizeDouble(iLow(Symbol(), Period(), 2), Digits); high1 = NormalizeDouble(iHigh(Symbol(), Period(), 1), Digits); high2 = NormalizeDouble(iHigh(Symbol(), Period(), 2), Digits); //--- _bar1size=NormalizeDouble(((high1-low1)/_point),0); //--- Finding bearish pattern BEOVB if(timeBUOVB_BEOVB!=iTime(Symbol(),Period(),1) && //orders are not yet opened for this pattern _bar1size > bar1size && //first bar is big enough, so the market is not flat low1 < low2 &&//First bar's Low is below second bar's Low high1 > high2 &&//First bar's High is above second bar's High close1 < open2 && //First bar's Сlose price is lower than second bar's Open price open1 > close1 && //First bar is a bearish bar open2 < close2) //Second bar is a bullish bar { //--- we have described all conditions indicating that the first bar completely engulfs the second bar and is a bearish bar timeBUOVB_BEOVB=iTime(Symbol(),Period(),1); // indicate that orders are already placed on this pattern } //--- Finding bullish pattern BUOVB if(timeBUOVB_BEOVB!=iTime(Symbol(),Period(),1) && //orders are not yet opened for this pattern _bar1size > bar1size && //first bar is big enough not to consider a flat market low1 < low2 &&//First bar's Low is below second bar's Low high1 > high2 &&//First bar's High is above second bar's High close1 > open2 && //First bar's Close price is higher than second bar's Open price open1 < close1 && //First bar is a bullish bar open2 > close2) //Second bar is a bearish bar { //--- we have described all conditions indicating that the first bar completely engulfs the second bar and is a bullish bar timeBUOVB_BEOVB=iTime(Symbol(),Period(),1); // indicate that orders are already placed on this pattern } } //+------------------------------------------------------------------+ |
Les niveaux d’entrées
Nous sommes capables de trouver nos patterns, nous devons donc définir nos ordres STOP.
Définissons les prix dans la fonction OnTick() :
1 2 3 4 5 6 7 8 9 | //--- Define prices for placing orders and stop orders buyPrice =NormalizeDouble(high1 + interval * _point,Digits); //define a price of order placing with intervals buySL =NormalizeDouble(low1-interval * _point,Digits); //define stop-loss with an interval buyTP =NormalizeDouble(buyPrice + TP * _point,Digits); //define take profit _ExpDate =TimeCurrent() + ExpDate*60*60; //pending order expiration time calculation //--- We also calculate sell orders sellPrice=NormalizeDouble(low1-interval*_point,Digits); sellSL=NormalizeDouble(high1+interval*_point,Digits); sellTP=NormalizeDouble(sellPrice-TP*_point,Digits); |
Gérer les erreurs d’exécution
Si vous avez déjà codé un robot de trading, vous savez qu’il y a souvent des erreurs d’exécution renvoyées par le serveur. Nous mettons donc en place une fonction nous permettant de les gérer :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 | //+----------------------------------------------------------------------------------------------------------------------+ //| The function opens or sets an order | //| symbol - symbol, at which a deal is performed. | //| cmd - a deal (may be equal to any of the deal values). | //| volume - amount of lots. | //| price - Open price. | //| slippage - maximum price deviation for market buy or sell orders. | //| stoploss - position close price when an unprofitability level is reached (0 if there is no unprofitability level).| //| takeprofit - position close price when a profitability level is reached (0 if there is no profitability level). | //| comment - order comment. The last part of comment can be changed by the trade server. | //| magic - order magic number. It can be used as a user-defined ID. | //| expiration - pending order expiration time. | //| arrow_color - open arrow color on a chart. If the parameter is absent or equal to CLR_NONE, | //| the open arrow is not displayed on a chart. | //+----------------------------------------------------------------------------------------------------------------------+ int OrderOpenF(string OO_symbol, int OO_cmd, double OO_volume, double OO_price, int OO_slippage, double OO_stoploss, double OO_takeprofit, string OO_comment, int OO_magic, datetime OO_expiration, color OO_arrow_color) { int result = -1;// result of opening an order int Error = 0; // error when opening an order int attempt = 0; // amount of performed attempts int attemptMax = 3; // maximum amount of attempts bool exit_loop = false; // exit the loop string lang =TerminalInfoString(TERMINAL_LANGUAGE);// trading terminal language for defining the language of the messages double stopllvl =NormalizeDouble(MarketInfo (OO_symbol, MODE_STOPLEVEL) * MarketInfo (OO_symbol, MODE_POINT),Digits);// minimum stop loss/take profit level, in points //the module provides safe order opening //--- checking stop orders for buying if(OO_cmd==OP_BUY || OO_cmd==OP_BUYLIMIT || OO_cmd==OP_BUYSTOP) { double tp = (OO_takeprofit - OO_price)/MarketInfo(OO_symbol, MODE_POINT); double sl = (OO_price - OO_stoploss)/MarketInfo(OO_symbol, MODE_POINT); if(tp>0 && tp<=stopllvl) { OO_takeprofit=OO_price+stopllvl+2*MarketInfo(OO_symbol,MODE_POINT); } if(sl>0 && sl<=stopllvl) { OO_stoploss=OO_price -(stopllvl+2*MarketInfo(OO_symbol,MODE_POINT)); } } //--- checking stop orders for selling if(OO_cmd==OP_SELL || OO_cmd==OP_SELLLIMIT || OO_cmd==OP_SELLSTOP) { double tp = (OO_price - OO_takeprofit)/MarketInfo(OO_symbol, MODE_POINT); double sl = (OO_stoploss - OO_price)/MarketInfo(OO_symbol, MODE_POINT); if(tp>0 && tp<=stopllvl) { OO_takeprofit=OO_price -(stopllvl+2*MarketInfo(OO_symbol,MODE_POINT)); } if(sl>0 && sl<=stopllvl) { OO_stoploss=OO_price+stopllvl+2*MarketInfo(OO_symbol,MODE_POINT); } } //--- while loop while(!exit_loop) { result=OrderSend(OO_symbol,OO_cmd,OO_volume,OO_price,OO_slippage,OO_stoploss,OO_takeprofit,OO_comment,OO_magic,OO_expiration,OO_arrow_color); //attempt to open an order using the specified parameters //--- if there is an error when opening an order if(result<0) { Error = GetLastError(); //assign a code to an error switch(Error) //error enumeration { //order closing error enumeration and an attempt to fix them case 2: if(attempt<attemptMax) { attempt=attempt+1; //define one more attempt Sleep(3000); //3 seconds of delay RefreshRates(); break; //exit switch } if(attempt==attemptMax) { attempt=0; //reset the amount of attempts to zero exit_loop = true; //exit while break; //exit switch } case 3: RefreshRates(); exit_loop = true; //exit while break; //exit switch case 4: if(attempt<attemptMax) { attempt=attempt+1; //define one more attempt Sleep(3000); //3 seconds of delay RefreshRates(); break; //exit switch } if(attempt==attemptMax) { attempt = 0; //reset the amount of attempts to zero exit_loop = true; //exit while break; //exit switch } case 5: exit_loop = true; //exit while break; //exit switch case 6: if(attempt<attemptMax) { attempt=attempt+1; //define one more attempt Sleep(5000); //3 seconds of delay break; //exit switch } if(attempt==attemptMax) { attempt = 0; //reset the amount of attempts to zero exit_loop = true; //exit while break; //exit switch } case 8: if(attempt<attemptMax) { attempt=attempt+1; //define one more attempt Sleep(7000); //3 seconds of delay break; //exit switch } if(attempt==attemptMax) { attempt = 0; //reset the amount of attempts to zero exit_loop = true; //exit while break; //exit switch } case 64: exit_loop = true; //exit while break; //exit switch case 65: exit_loop = true; //exit while break; //exit switch case 128: Sleep(3000); RefreshRates(); continue; //exit switch case 129: if(attempt<attemptMax) { attempt=attempt+1; //define one more attempt Sleep(3000); //3 seconds of delay RefreshRates(); break; //exit switch } if(attempt==attemptMax) { attempt = 0; //reset the amount of attempts to zero exit_loop = true; //exit while break; //exit switch } case 130: exit_loop=true; //exit while break; case 131: exit_loop = true; //exit while break; //exit switch case 132: Sleep(10000); //sleep for 10 seconds RefreshRates(); //update data //exit_loop = true; //exit while break; //exit switch case 133: exit_loop=true; //exit while break; //exit switch case 134: exit_loop=true; //exit while break; //exit switch case 135: if(attempt<attemptMax) { attempt=attempt+1; //define one more attempt RefreshRates(); break; //exit switch } if(attempt==attemptMax) { attempt = 0; //set the number of attempts to zero exit_loop = true; //exit while break; //exit switch } case 136: if(attempt<attemptMax) { attempt=attempt+1; //define one more attempt RefreshRates(); break; //exit switch } if(attempt==attemptMax) { attempt = 0; //set the amount of attempts to zero exit_loop = true; //exit while break; //exit switch } case 137: if(attempt<attemptMax) { attempt=attempt+1; Sleep(2000); RefreshRates(); break; } if(attempt==attemptMax) { attempt=0; exit_loop=true; break; } case 138: if(attempt<attemptMax) { attempt=attempt+1; Sleep(1000); RefreshRates(); break; } if(attempt==attemptMax) { attempt=0; exit_loop=true; break; } case 139: exit_loop=true; break; case 141: Sleep(5000); exit_loop=true; break; case 145: exit_loop=true; break; case 146: if(attempt<attemptMax) { attempt=attempt+1; Sleep(2000); RefreshRates(); break; } if(attempt==attemptMax) { attempt=0; exit_loop=true; break; } case 147: if(attempt<attemptMax) { attempt=attempt+1; OO_expiration=0; break; } if(attempt==attemptMax) { attempt=0; exit_loop=true; break; } case 148: exit_loop=true; break; default: Print("Error: ",Error); exit_loop=true; //exit while break; //other options } } //--- if no errors detected else { if(lang == "Russian") {Print("Ордер успешно открыт. ", result);} if(lang == "English") {Print("The order is successfully opened.", result);} Error = 0; //reset the error code to zero break; //exit while //errorCount =0; //reset the amount of attempts to zero } } return(result); } //+------------------------------------------------------------------+ |
Le code de l’expert advisor dans son ensemble est le suivant :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 | //+------------------------------------------------------------------+ //| BEOVB_BUOVB_bar.mq4 | //| Copyright 2015, Iglakov Dmitry. | //| cjdmitri@gmail.com | //+------------------------------------------------------------------+ #property copyright "Copyright 2015, Iglakov Dmitry." #property link "cjdmitri@gmail.com" #property version "1.00" #property strict extern int interval = 25; //Interval extern double lot = 0.1; //Lot Size extern int TP = 400; //Take Profit extern int magic = 962231; //Magic number extern int slippage = 2; //Slippage extern int ExpDate = 48; //Expiration Hour Order extern int bar1size = 900; //Bar 1 Size double buyPrice,//define BuyStop price buyTP, //Take Profit BuyStop buySL, //Stop Loss BuyStop sellPrice, //define SellStop price sellTP, //Take Profit SellStop sellSL; //Stop Loss SellStop double open1,//first candle Open price open2, //second candle Open price close1, //first candle Close price close2, //second candle Close price low1, //first candle Low price low2, //second candle Low price high1, //first candle High price high2; //second candle High price datetime _ExpDate =0; // local variable for defining pending orders expiration time double _bar1size;// local variable required to avoid a flat market datetime timeBUOVB_BEOVB;// time of a bar when pattern orders were opened, to avoid re-opening //+------------------------------------------------------------------+ //| Expert initialization function | //+------------------------------------------------------------------+ int OnInit() { return(INIT_SUCCEEDED); } //+------------------------------------------------------------------+ //| Expert deinitialization function | //+------------------------------------------------------------------+ void OnDeinit(const int reason) { } //+------------------------------------------------------------------+ //| Expert tick function | //+------------------------------------------------------------------+ void OnTick() { double _bid = NormalizeDouble(MarketInfo (Symbol(), MODE_BID), Digits); // define Low price double _ask = NormalizeDouble(MarketInfo(Symbol(), MODE_ASK), Digits); //define High price double _point = MarketInfo(Symbol(), MODE_POINT); //--- define prices of necessary bars open1 = NormalizeDouble(iOpen(Symbol(), Period(), 1), Digits); open2 = NormalizeDouble(iOpen(Symbol(), Period(), 2), Digits); close1 = NormalizeDouble(iClose(Symbol(), Period(), 1), Digits); close2 = NormalizeDouble(iClose(Symbol(), Period(), 2), Digits); low1 = NormalizeDouble(iLow(Symbol(), Period(), 1), Digits); low2 = NormalizeDouble(iLow(Symbol(), Period(), 2), Digits); high1 = NormalizeDouble(iHigh(Symbol(), Period(), 1), Digits); high2 = NormalizeDouble(iHigh(Symbol(), Period(), 2), Digits); //--- Define prices for placing orders and stop orders buyPrice =NormalizeDouble(high1 + interval * _point,Digits); //define a price of order placing with intervals buySL =NormalizeDouble(low1-interval * _point,Digits); //define stop loss with an interval buyTP =NormalizeDouble(buyPrice + TP * _point,Digits); //define take profit _ExpDate =TimeCurrent() + ExpDate*60*60; //pending order expiration time calculation //--- We also calculate sell orders sellPrice=NormalizeDouble(low1-interval*_point,Digits); sellSL=NormalizeDouble(high1+interval*_point,Digits); sellTP=NormalizeDouble(sellPrice-TP*_point,Digits); //--- _bar1size=NormalizeDouble(((high1-low1)/_point),0); //--- Finding bearish pattern BEOVB if(timeBUOVB_BEOVB!=iTime(Symbol(),Period(),1) && //orders are not yet opened for this pattern _bar1size > bar1size && //first bar is big enough, so the market is not flat low1 < low2 &&//First bar's Low is below second bar's Low high1 > high2 &&//First bar's High is above second bar's High close1 < open2 && //First bar's Close price is lower than second bar's Open price open1 > close1 && //First bar is a bearish bar open2 < close2) //Second bar is a bullish bar { //--- we have described all conditions indicating that the first bar completely engulfs the second bar and is a bearish bar OrderOpenF(Symbol(),OP_SELLSTOP,lot,sellPrice,slippage,sellSL,sellTP,NULL,magic,_ExpDate,Blue); timeBUOVB_BEOVB=iTime(Symbol(),Period(),1); //indicate that orders are already placed on this pattern } //--- Finding bullish pattern BUOVB if(timeBUOVB_BEOVB!=iTime(Symbol(),Period(),1) && //orders are not yet opened for this pattern _bar1size > bar1size && //first bar is big enough, so the market is not flat low1 < low2 &&//First bar's Low is below second bar's Low high1 > high2 &&//First bar's High is above second bar's High close1 > open2 && //First bar's Close price is higher than second bar's Open price open1 < close1 && //First bar is a bullish bar open2 > close2) //Second bar is a bearish bar { //--- we have described all conditions indicating that the first bar completely engulfs the second bar and is a bullish bar OrderOpenF(Symbol(),OP_BUYSTOP,lot,buyPrice,slippage,buySL,buyTP,NULL,magic,_ExpDate,Blue); timeBUOVB_BEOVB = iTime(Symbol(),Period(),1); //indicate that orders are already placed on this pattern } } //+------------------------------------------------------------------+ |
Conclusion
Dans cet article nous avons :
- Abordé un nouveau pattern
- Développé l’algorithme de détection
- Créé un robot basé sur cet algorithme
Le robot est disponible ici.
Traduit de PRICE ACTION. AUTOMATING THE ENGULFING PATTERN TRADING STRATEGY
Catégories
- Analyse Forex (410)
- Analyse marchés (803)
- Analyse matières premières (116)
- MQL (7)
- MT4 (2)
- Trading (2)
Disclaimer
Les informations de marchés et les analyses fournies restent à titre indicatif et ne doivent pas être interprétées comme un conseil, une recommandation ou une sollicitation d’investissement. QuantInvest ne peut être tenu responsable de l’utilisation qui en est faite et des conséquences qui en résultent, l’investisseur final restant le seul décisionnaire quant à la prise de position sur son compte de trading.




