Pending open

Author: © 2023, Alexey Viktorov
Orders Execution
It automatically opens orders when conditions are reached
0 Views
0 Downloads
0 Favorites
Pending open
ÿþ/********************************************************************\

|                                                   Pending open.mq5 |

|                                            © 2023, Alexey Viktorov |

|                       https://www.mql5.com/ru/users/alexeyvik/news |

\********************************************************************/

#property copyright "© 2023, Alexey Viktorov"

#property link      "https://www.mql5.com/ru/users/alexeyvik/news"

#property version   "1.00"

#property script_show_inputs

#property description "buy stop limit - > 4>AB865=88 F5=K >@45@0 2KAB02;O5BAO >B;>65==K9 >@45@ Buy Limit ?> F5=5 F5=_>@45@0 - gepStopLimit"

#property description "sell stop limit - > 4>AB865=88 F5=K >@45@0 2KAB02;O5BAO >B;>65==K9 >@45@ Sell Limit ?> F5=5 F5=_>@45@0 + gepStopLimit"

#define zz " ***** "

//#include <Trade\Trade.mqh>

//CTrade trade;



enum PENDING_UP

 {

  stop          = ORDER_TYPE_BUY_STOP,                                //  Buy Stop & Sell Stop

  limit         = ORDER_TYPE_BUY_LIMIT,                               //  Buy Limit & Sell Limit

  stop_limit    = ORDER_TYPE_BUY_STOP_LIMIT                           //  buy stop limit & sell stop limit

 };

input PENDING_UP                  Orders          = stop_limit;       //  B8? >B;>65==KE >@45@>2  %

input int                         gep             = 150;              //  >BABC? >B B5:CI59 F5=K, 4;O >B;>65==KE >@45@>2  % 8  2 ?C=:B0E

input int                         step            = 300;              //  H03 <564C >@45@0<8  % 8  2 ?C=:B0E

input int                         gepStopLimit    = 250;              //  >BABC? >B F5=K >@45@0 4;O StopLimit

input int                         quantity        = 3;                //  :>;8G5AB2> >@45@>2 225@E 8 2=87

input double                      lots            = 0.01;             //  Lots

input int                         stopLoss        = 200;              //  Stop Loss 2 ?C=:B0E

input int                         takeProfit      = 200;              //  Take Profit 2 ?C=:B0E

input int                         magic           = 12;               //  845=B8D8:0B>@ M:A?5@B0

//long chart_id = ChartID();

/********************Script program start function*******************/

void OnStart()

 {

  MqlTick tick;

  MqlTradeRequest request;

  MqlTradeResult result;

  MqlTradeCheckResult checkResult;

  ZeroMemory(request);

  ZeroMemory(result);

//---

  request.action        =  TRADE_ACTION_PENDING;

  request.magic         =  magic;

  request.symbol        =  _Symbol;

  request.volume        =  lots;

  request.deviation     =  ULONG_MAX;

  request.type_filling  =  ORDER_FILLING_RETURN;

//request.type_time     =  ;

//request.expiration    =  ;

//---

  SymbolInfoTick(_Symbol, tick);

  int i = 0;

  while(i < quantity && !IsStopped())

   {

    double priceUP = normalizePrice(tick.ask+(gep+step*i)*_Point),

           priceDN = normalizePrice(tick.bid-(gep+step*i)*_Point),

           price = Orders == limit ? priceDN : priceUP,

           sl = 0.0,

           tp = 0.0;



    request.type        = (ENUM_ORDER_TYPE)Orders;

    request.price       =  price;

    request.stoplimit   =  Orders == stop_limit ? normalizePrice(price-gepStopLimit*_Point) : 0.0;

    request.sl          =  normalizePrice((Orders == stop_limit ? request.stoplimit : price)-stopLoss*_Point);

    request.tp          =  normalizePrice((Orders == stop_limit ? request.stoplimit : price)+takeProfit*_Point);

    if(OrderCheck(request, checkResult))

      if(!OrderSend(request, result))

        Print(zz, result.retcode);

    //---

    price = Orders == limit ? priceUP : priceDN;

    request.type        = ENUM_ORDER_TYPE(Orders+1);

    request.price       =  price;

    request.stoplimit   =  Orders == stop_limit ? normalizePrice(price+gepStopLimit*_Point) : 0.0;

    request.sl          =  normalizePrice((Orders == stop_limit ? request.stoplimit : price)+stopLoss*_Point);

    request.tp          =  normalizePrice((Orders == stop_limit ? request.stoplimit : price)-takeProfit*_Point);

    if(OrderCheck(request, checkResult))

      if(!OrderSend(request, result))

        Print(zz, result.retcode);

    //---

    i++;

   }

//---

 }/******************************************************************/



/********************************************************************/

double normalizePrice(double price)

 {

  double tickSize = SymbolInfoDouble(_Symbol, SYMBOL_TRADE_TICK_SIZE);

  price = round(price/tickSize)*tickSize;

  return(price);

 }/******************************************************************/

/*****************************End program****************************/

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