Author: Safe-Forex.ru
Orders Execution
It can change open orders parameters, due to possible stepping strategyIt automatically opens orders when conditions are reached
Indicators Used
MACD Histogram
0 Views
0 Downloads
0 Favorites
MACD_v4
ÿþ//+-------------------------------------------------------------------------------------------------------------------+

//|  07@01>BG8::   =4@59 8=052                                                                                      |

//| !>25B=8::      MACD                                                                                               |

//| >GB0:         minaev.work@mail.ru                                                                                |

//| !:09?:         live:minaev.work                                                                                   |

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

#property copyright "Safe-Forex.ru"

#property link      "http://safe-forex.ru"

#property version   "1.0"

#property strict



input string             expSettings  = "";            // 0AB@>9:8 A>25B=8:0

input int                expMagic     = 123;           // 038:

input double             posVolume    = 0.1;           // 1J5<

input int                posProfit    = 50;            // @81K;L

input int                posLoss      = 50;            // #1KB>:



input string             indSettings  = "";            // 0AB@>9:8 8=48:0B>@0 MACD

input int                fastPeriod   = 12;            // KAB@>5 EMA

input int                slowPeriod   = 26;            // 54;5==>5 EMA

input int                signalPeriod = 9;             // MACD SMA

input ENUM_APPLIED_PRICE priceType    = PRICE_CLOSE;   // "8? F5=K



datetime newCandle;           // =>20O A25G0

int      posTicket;           // B8:5B ?>78F88

bool     permOpenBuy;         // true - @07@5H5=> >B:@KBL ?>78F8N =0 ?>:C?:C

bool     permOpenSell;        // true - @07@5H5=> >B:@KBL ?>78F8N =0 ?@>406C

bool     permSetOrdersStop;   // true - @07@5H5=> CAB0=>28BL AB>? >@45@0

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

int OnInit(void)

{

   return INIT_SUCCEEDED;

}

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

void OnDeinit(const int reason)

{   

}

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

void OnTick(void)

{

   //--- ?@>25@8< =0;8G85 A83=0;0 =0 =>2>9 A25G5

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

   newCandle = Time[0];

   //--- >B:@>5< ?>78F8N

   if(permOpenBuy)  OpenPosition(OP_BUY,  posVolume, Ask);

   if(permOpenSell) OpenPosition(OP_SELL, posVolume, Bid);

   //--- CAB0=>28< AB>? >@45@0

   if(permSetOrdersStop) SetOrdersStop();

}

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

//| $C=:F8O CAB0=02;8205B AB>? >@45@0                                                                                 |

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

void SetOrdersStop(void)

{

   double oop = 0;

   double sl  = 0;

   double tp  = 0;

   //--- 2K15@5< ?>78F8N ?> B8:5BC

   if(OrderSelect(posTicket, SELECT_BY_TICKET))

   {

      oop = OrderOpenPrice();

      //--- @0AG8B05< F5=K CAB0=>2:8 AB>? >@45@>2

      if(OrderType() == OP_BUY)

      {

         tp = oop + posProfit * _Point;

         sl = oop - posLoss   * _Point;

      }

      if(OrderType() == OP_SELL)

      {

         tp = oop - posProfit * _Point;

         sl = oop + posLoss   * _Point;

      }

      //--- <>48D8F8@C5< ?>78F8N

      if(OrderModify(posTicket, oop, sl, tp, 0)) permSetOrdersStop = false;   // 70?@5B8< CAB0=02;820BL AB>? >@45@0

      else PrintFormat("!B>? >@45@0 =5 CAB0=>2;5=K, B8:5B: %i, >H81:0: %i", posTicket, GetLastError());

   }

   else PrintFormat(">78F8O =5 2K1@0=0, B8:5B: %i, >H81:0: %i", posTicket, GetLastError());

}

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

//| $C=:F8O >B:@K205B ?>78F8N                                                                                         |

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

void OpenPosition(int type, double volume, double price)

{

   posTicket = OrderSend(_Symbol, type, volume, price, 0, 0, 0, "", expMagic, 0);

   

   if(posTicket > 0)

   {

      permSetOrdersStop = true;   // @07@5H8< CAB0=02;820BL AB>? >@45@0

      

      if(type == OP_BUY)  permOpenBuy  = false;   // 70?@5B8< >B:@K20BL ?>78F8N =0 ?>:C?:C

      if(type == OP_SELL) permOpenSell = false;   // 70?@5B8< >B:@K20BL ?>78F8N =0 ?@>406C

   }

   if(posTicket < 0) PrintFormat(">78F8O =5 >B:@K;0AL, >H81:0: %i", GetLastError());

}

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

//| $C=:F8O ?@>25@O5B =0;8G85 A83=0;0                                                                                 |

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

void CheckSignalExist(void)

{

   //--- ?>;CG8< 7=0G5=8O 8=48:0B>@0

   double mainLine1 = iMACD(_Symbol, PERIOD_CURRENT, fastPeriod, slowPeriod, signalPeriod, priceType, MODE_MAIN, 1);

   double mainLine2 = iMACD(_Symbol, PERIOD_CURRENT, fastPeriod, slowPeriod, signalPeriod, priceType, MODE_MAIN, 2);

   

   if(mainLine1 > 0 && mainLine2 < 0) permOpenBuy  = true;   // @07@5H8< >B:@K20BL ?>78F8N =0 ?>:C?:C

   if(mainLine1 < 0 && mainLine2 > 0) permOpenSell = true;   // @07@5H8< >B:@K20BL ?>78F8N =0 ?@>406C

}

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

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