EA_Three_Candles

Author: Copyright 2017, Andrey Minaev
Orders Execution
It automatically opens orders when conditions are reachedChecks for the total of open ordersIt can change open orders parameters, due to possible stepping strategy
0 Views
0 Downloads
0 Favorites
EA_Three_Candles
ÿþ//+-----------------------------------------------------------------------------------------------+

//|                                                                          EA_Three_Candles.mq4 |

//|                                                                 Copyright 2017, Andrey Minaev |

//|                                                     https://www.mql5.com/ru/users/id.scorpion |

//|                                                                     Mail: id.scorpion@mail.ru |

//+-----------------------------------------------------------------------------------------------+

#property copyright "Copyright 2017, Andrey Minaev"

#property link      "https://www.mql5.com/ru/users/id.scorpion"

#property version   "1.00"

#property strict



//--- ?0@0<5B@K A>25B=8:0

extern string paramEA    = "";     // Parameters EA

extern double volume     = 0.01;   // Volume

extern double stopLoss   = 5;      // StopLoss

extern double takeProfit = 2;      // TakeProfit

extern double maxCandle  = 100;    // MaxCandle

extern double minCandle  = 10;     // MinCandle

extern int    magic      = 123;    // Magic



//--- 3;>10;L=K5 ?5@5<5==K5

datetime newCandle;



//+-----------------------------------------------------------------------------------------------+

int OnInit()

{

   

   return(INIT_SUCCEEDED);

}

//+-----------------------------------------------------------------------------------------------+

void OnDeinit(const int reason)

{

   

}

//+-----------------------------------------------------------------------------------------------+

void OnTick()

{

   if(newCandle != Time[0]) FindPattern();

   newCandle = Time[0];

}

//+-----------------------------------------------------------------------------------------------+

void OpenOrder(int type)   // B:@>5< @K=>G=K9 >@45@

{

   if(type == OP_BUY)  if(OrderSend(_Symbol, OP_BUY,  volume, Ask, 0, 0, 0, "", magic, 0)) SetSLTP(OP_BUY);

   if(type == OP_SELL) if(OrderSend(_Symbol, OP_SELL, volume, Bid, 0, 0, 0, "", magic, 0)) SetSLTP(OP_SELL);

}

//+-----------------------------------------------------------------------------------------------+

void SetSLTP(int type)   // #AB0=>28< AB>? ?@8:07K

{

   double sl = 0;

   double tp = 0;

   

   if(type == OP_BUY)

      for(int i = 0; i < OrdersTotal(); i++)

         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

            if(OrderSymbol() == _Symbol && OrderMagicNumber() == magic && OrderType() == OP_BUY && OrderStopLoss() == 0)

            {

               sl = NormalizeDouble(Low[3] - stopLoss * _Point, _Digits);

               tp = NormalizeDouble(OrderOpenPrice() + (OrderOpenPrice() - Low[3]) * takeProfit, Digits);

               if(OrderModify(OrderTicket(), OrderOpenPrice(), sl, tp, 0)) return;

            }

   if(type == OP_SELL)

      for(int i = 0; i < OrdersTotal(); i++)

         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

            if(OrderSymbol() == _Symbol && OrderMagicNumber() == magic && OrderType() == OP_SELL && OrderStopLoss() == 0)

            {

               sl = NormalizeDouble(High[3] + stopLoss * _Point, _Digits);

               tp = NormalizeDouble(OrderOpenPrice() - (High[3] - OrderOpenPrice()) * takeProfit, Digits);

               if(OrderModify(OrderTicket(), OrderOpenPrice(), sl, tp, 0)) return;

            }

}

//+-----------------------------------------------------------------------------------------------+

void FindPattern()   // I5< ?0BB5@=K 4;O >B:@KB8O >@45@>2

{

   if(Open[1] < Close[1] && Open[2] < Close[2] && Open[3] < Close[3])

   {

      double size1 = NormalizeDouble((Close[1] - Open[1]) / _Point, 0);

      double size2 = NormalizeDouble((Close[2] - Open[2]) / _Point, 0);

      double size3 = NormalizeDouble((Close[3] - Open[3]) / _Point, 0);

      

      if(maxCandle >= size1 && minCandle <= size1 && maxCandle >= size2 && minCandle <= size2 && maxCandle >= size3 && minCandle <= size3)

         OpenOrder(OP_BUY);

   }

   if(Open[1] > Close[1] && Open[2] > Close[2] && Open[3] > Close[3])

   {

      double size1 = NormalizeDouble((Open[1] - Close[1]) / _Point, 0);

      double size2 = NormalizeDouble((Open[2] - Close[2]) / _Point, 0);

      double size3 = NormalizeDouble((Open[3] - Close[3]) / _Point, 0);

      

      if(maxCandle >= size1 && minCandle <= size1 && maxCandle >= size2 && minCandle <= size2 && maxCandle >= size3 && minCandle <= size3)

         OpenOrder(OP_SELL);

   }

}

//+-----------------------------------------------------------------------------------------------+

Comments

Markdown supported. Formatting help

Markdown Formatting Guide

Element Markdown Syntax
Heading # H1
## H2
### H3
Bold **bold text**
Italic *italicized text*
Link [title](https://www.example.com)
Image ![alt text](image.jpg)
Code `code`
Code Block ```
code block
```
Quote > blockquote
Unordered List - Item 1
- Item 2
Ordered List 1. First item
2. Second item
Horizontal Rule ---