EA_Parabolic_SAR

Author: Copyright 2017, Andrey Minaev
Orders Execution
It automatically opens orders when conditions are reachedChecks for the total of open ordersIt Closes Orders by itself
Indicators Used
Parabolic Stop and Reverse system
0 Views
0 Downloads
0 Favorites
EA_Parabolic_SAR
ÿþ//+-----------------------------------------------------------------------------------------------+

//|                                                                          EA_Parabolic_SAR.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 bool   reverse = false;   // Reverse

extern int    magic   = 123;     // Magic



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

extern string paramInd = "";     // Parameters Parabolic SAR

extern double step     = 0.02;   // Step

extern double maximum  = 0.2;    // Maximum



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

int OnInit()

{

   

   return(INIT_SUCCEEDED);

}

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

void OnDeinit(const int reason)

{

   

}

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

void OnTick()

{

   double sar = iSAR(_Symbol, PERIOD_CURRENT, step, maximum, 0);

   if(GetNumberOrders() == 0)

   {

      if(!reverse)

      {

         if(sar < Bid) OpenOrder(OP_BUY);

         if(sar > Bid) OpenOrder(OP_SELL);

      }

      if(reverse)

      {

         if(sar > Bid) OpenOrder(OP_BUY);

         if(sar < Bid) OpenOrder(OP_SELL);

      }

   }

   if(GetNumberOrders() > 0)

   {

      if(!reverse)

      {

         if(sar < Bid) CloseOrder(OP_SELL);

         if(sar > Bid) CloseOrder(OP_BUY);

      }

      if(reverse)

      {

         if(sar > Bid) CloseOrder(OP_SELL);

         if(sar < Bid) CloseOrder(OP_BUY);

      }

   }

}

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

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)) return;

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

}

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

void CloseOrder(int type)   // 0:@>5< >B:@KBK9 >@45@

{

   if(type == OP_BUY)

      for(int i = OrdersTotal(); i >= 0; i--)

         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

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

               if(OrderClose(OrderTicket(), OrderLots(), Bid, 0)) return;

               

   if(type == OP_SELL)

      for(int i = OrdersTotal(); i >= 0; i--)

         if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

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

               if(OrderClose(OrderTicket(), OrderLots(), Ask, 0)) return;

}

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

int GetNumberOrders()   // >;CG8< :>;8G5AB2> >B:@KBKE >@45@>2

{

   int number = 0;

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

      if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))

         if(OrderSymbol() == _Symbol && OrderMagicNumber() == magic)

            number++;

   return(number);

}

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

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 ---