//+------------------------------------------------------------------+
//|                                             EA Pending Order.mq4 |
//|                        Copyright 2021, MetaQuotes Software Corp. |
//|                                             https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2021"
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict

extern string  Name_EA                 = "PendingOrder";
extern int     Start_Hour              = 2;
extern int     End_Hour                = 23;
extern int     SL                      = 0;
extern double  Lots1                   = 0.01;

extern double QuotePrice1              =0;
extern int     TP1                     =200;

extern double QuotePrice2              =0;
extern int     TP2                     =200;

extern double QuotePrice3              =0;
extern int     TP3                     =200;

extern double QuotePrice4              =0;
extern int     TP4                     =200;

extern double QuotePrice5              =0;
extern int     TP5                     =200;

extern double QuotePrice6              =0;
extern int     TP6                     =200;

extern double QuotePrice7              =0;
extern int     TP7                     =200;

extern double QuotePrice8              =0;
extern int     TP8                     =200;

extern double QuotePrice9              =0;
extern int     TP9                     =200;

extern double QuotePrice10              =0;
extern int     TP10                     =200;

extern double QuotePrice11              =0;
extern int     TP11                     =200;

extern double QuotePrice12              =0;
extern int     TP12                     =200;

extern double QuotePrice13              =0;
extern int     TP13                     =200;

extern double QuotePrice14              =0;
extern int     TP14                     =200;

extern double QuotePrice15              =0;
extern int     TP15                     =200;

extern double QuotePrice16              =0;
extern int     TP16                     =200;

extern int     Distance                = 15;
extern int     Magic                   = 1269;

string BuySell1="";
string BuySell2="";
string BuySell3="";
string BuySell4="";
string BuySell5="";
string BuySell6="";
string BuySell7="";
string BuySell8="";
string BuySell9="";
string BuySell10="";
string BuySell11="";
string BuySell12="";
string BuySell13="";
string BuySell14="";
string BuySell15="";
string BuySell16="";
string BuySell17 ="";

double low1=iLow(NULL,0,1);
double high1=iHigh(NULL,0,1);
int ticket1a,ticket1b,ticket2a,ticket2b,ticket3a,ticket3b,ticket4a,ticket4b,ticket5a,ticket5b,ticket6a,ticket6b,ticket7a,ticket7b,ticket8a,ticket8b,ticket9a,ticket9b,ticket10a,ticket10b,ticket11a,ticket11b,ticket12a,ticket12b,ticket13a,ticket13b,ticket14a,ticket14b,ticket15a,ticket15b,ticket16a,ticket16b;
//+------------------------------------------------------------------+
//| expert initialization function                                   |
//+------------------------------------------------------------------+
int init()
  {
//----
   if(Digits==3 || Digits==5) int pt=10*Point;   else   int pt=Point;
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert deinitialization function                                 |
//+------------------------------------------------------------------+
int deinit()
  {
//----

//----
   return(0);
  }
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
label();
  
   if(Hour_trade()==1)
   {
   RefreshRates();
      if (low1>=QuotePrice1)
      {
      BuySell1="OP_BUY";
      Comment ("Pending Buy Order at",QuotePrice1);
      }
      
      if (high1<=QuotePrice1)
      {
      BuySell1="OP_SELL";
      Comment ("Pending Sell Order at",QuotePrice1);
      }

      if (low1>=QuotePrice2)
      {
      BuySell2="OP_BUY";
      Comment ("Pending Buy Order at",QuotePrice2);
      }

      if (high1<=QuotePrice2)
      {
      BuySell2="OP_SELL";
      Comment ("Pending Sell Order at",QuotePrice2);
      }

      if (low1>=QuotePrice3)
      {
      BuySell3="OP_BUY";
      Comment ("Pending Buy Order at",QuotePrice3);
      }

      if (high1<=QuotePrice3)
      {
      BuySell3="OP_SELL";
      Comment ("Pending Sell Order at",QuotePrice3);
      }

      if (low1>=QuotePrice4)
      {
      BuySell4="OP_BUY";
      Comment ("Pending Buy Order at",QuotePrice4);
      }

      if (high1<=QuotePrice4)
      {
      BuySell4="OP_SELL";
      Comment ("Pending Sell Order at",QuotePrice4);
      }

      if (low1>=QuotePrice5)
      {
      BuySell5="OP_BUY";
      Comment ("Pending Buy Order at",QuotePrice5);
      }
      
      if (high1<=QuotePrice5)
      {
      BuySell5="OP_SELL";
      Comment ("Pending Sell Order at",QuotePrice5);
      }

      if (low1>=QuotePrice6)
      {
      BuySell6="OP_BUY";
      Comment ("Pending Buy Order at",QuotePrice6);
      }

      if (high1<=QuotePrice6)
      {
      BuySell6="OP_SELL";
      Comment ("Pending Sell Order at",QuotePrice6);
      }

      if (low1>=QuotePrice7)
      {
      BuySell7="OP_BUY";
      Comment ("Pending Buy Order at",QuotePrice7);
      }

      if (high1<=QuotePrice7)
      {
      BuySell7="OP_SELL";
      Comment ("Pending Sell Order at",QuotePrice7);
      }

      if (low1>=QuotePrice8)
      {
      BuySell8="OP_BUY";
      Comment ("Pending Buy Order at",QuotePrice8);
      }

      if (high1<=QuotePrice8)
      {
      BuySell8="OP_SELL";
      Comment ("Pending Sell Order at",QuotePrice8);
      }
      
      if (low1>=QuotePrice9)
      {
      BuySell9="OP_BUY";
      Comment ("Pending Buy Order at",QuotePrice9);
      }
      
      if (high1<=QuotePrice9)
      {
      BuySell9="OP_SELL";
      Comment ("Pending Sell Order at",QuotePrice9);
      }

      if (low1>=QuotePrice10)
      {
      BuySell10="OP_BUY";
      Comment ("Pending Buy Order at",QuotePrice10);
      }

      if (high1<=QuotePrice10)
      {
      BuySell10="OP_SELL";
      Comment ("Pending Sell Order at",QuotePrice10);
      }

      if (low1>=QuotePrice11)
      {
      BuySell11="OP_BUY";
      Comment ("Pending Buy Order at",QuotePrice11);
      }

      if (high1<=QuotePrice11)
      {
      BuySell11="OP_SELL";
      Comment ("Pending Sell Order at",QuotePrice11);
      }

      if (low1>=QuotePrice12)
      {
      BuySell12="OP_BUY";
      Comment ("Pending Buy Order at",QuotePrice12);
      }

      if (high1<=QuotePrice12)
      {
      BuySell12="OP_SELL";
      Comment ("Pending Sell Order at",QuotePrice12);
      }

      if (low1>=QuotePrice13)
      {
      BuySell13="OP_BUY";
      Comment ("Pending Buy Order at",QuotePrice13);
      }
      
      if (high1<=QuotePrice13)
      {
      BuySell13="OP_SELL";
      Comment ("Pending Sell Order at",QuotePrice13);
      }

      if (low1>=QuotePrice14)
      {
      BuySell14="OP_BUY";
      Comment ("Pending Buy Order at",QuotePrice14);
      }

      if (high1<=QuotePrice14)
      {
      BuySell14="OP_SELL";
      Comment ("Pending Sell Order at",QuotePrice14);
      }

      if (low1>=QuotePrice15)
      {
      BuySell15="OP_BUY";
      Comment ("Pending Buy Order at",QuotePrice15);
      }

      if (high1<=QuotePrice15)
      {
      BuySell15="OP_SELL";
      Comment ("Pending Sell Order at",QuotePrice15);
      }

      if (low1>=QuotePrice16)
      {
      BuySell16="OP_BUY";
      Comment ("Pending Buy Order at",QuotePrice16);
      }

      if (high1<=QuotePrice16)
      {
      BuySell16="OP_SELL";
      Comment ("Pending Sell Order at",QuotePrice16);
      }
            
         
      if(BuySell1=="OP_BUY" && QuotePrice1==Ask && IsNewBUYCandle() && ticket1a<=0)
         {
         ticket1a=OrderSend(Symbol(),OP_BUY,Lots1,Ask,2,0,Ask+TP1*_Point, "", Magic, 0, Lime);
         }
      if(BuySell1=="OP_SELL" && QuotePrice1==Bid && IsNewSELLCandle() && ticket1b<=0)
         {
         ticket1b=OrderSend(Symbol(),OP_SELL,Lots1,Bid,2,0,Bid-TP1*_Point, "", Magic, 0, Red);
         }

      if(BuySell2=="OP_BUY" && QuotePrice2==Ask && IsNewBUYCandle() && ticket2a<=0)
         {
         ticket2a=OrderSend(Symbol(),OP_BUY,Lots1,Ask,2,0,Ask+TP2*_Point, "", Magic, 0, Lime);
         }
      if(BuySell2=="OP_SELL" && QuotePrice2==Bid && IsNewSELLCandle() && ticket2b<=0)
         {
         ticket2b=OrderSend(Symbol(),OP_SELL,Lots1,Bid,2,0,Bid-TP2*_Point, "", Magic, 0, Red);
         }  

      if(BuySell3=="OP_BUY" && QuotePrice3==Ask && IsNewBUYCandle() && ticket3a<=0)
         {
         ticket3a=OrderSend(Symbol(),OP_BUY,Lots1,Ask,2,0,Ask+TP3*_Point, "", Magic, 0, Lime);
         }
      if(BuySell3=="OP_SELL" && QuotePrice3==Bid && IsNewSELLCandle() && ticket3b<=0)
         {
         ticket3b=OrderSend(Symbol(),OP_SELL,Lots1,Bid,2,0,Bid-TP3*_Point, "", Magic, 0, Red);
         }  

      if(BuySell4=="OP_BUY" && QuotePrice4==Ask && IsNewBUYCandle() && ticket4a<=0)
         {
         ticket4a=OrderSend(Symbol(),OP_BUY,Lots1,Ask,2,0,Ask+TP4*_Point, "", Magic, 0, Lime);
         }
      if(BuySell4=="OP_SELL" && QuotePrice4==Bid && IsNewSELLCandle() && ticket4b<=0)
         {
         ticket4b=OrderSend(Symbol(),OP_SELL,Lots1,Bid,2,0,Bid-TP4*_Point, "", Magic, 0, Red);
         }  

      if(BuySell5=="OP_BUY" && QuotePrice5==Ask && IsNewBUYCandle() && ticket5a<=0)
         {
         ticket5a=OrderSend(Symbol(),OP_BUY,Lots1,Ask,2,0,Ask+TP5*_Point, "", Magic, 0, Lime);
         }
      if(BuySell5=="OP_SELL" && QuotePrice5==Bid && IsNewSELLCandle() && ticket5b<=0)
         {
         ticket5b=OrderSend(Symbol(),OP_SELL,Lots1,Bid,2,0,Bid-TP5*_Point, "", Magic, 0, Red);
         }  

      if(BuySell6=="OP_BUY" && QuotePrice6==Ask && IsNewBUYCandle() && ticket6a<=0)
         {
         ticket6a=OrderSend(Symbol(),OP_BUY,Lots1,Ask,2,0,Ask+TP6*_Point, "", Magic, 0, Lime);
         }
      if(BuySell6=="OP_SELL" && QuotePrice6==Bid && IsNewSELLCandle() && ticket6b<=0)
         {
         ticket6b=OrderSend(Symbol(),OP_SELL,Lots1,Bid,2,0,Bid-TP6*_Point, "", Magic, 0, Red);
         }  

      if(BuySell7=="OP_BUY" && QuotePrice7==Ask && IsNewBUYCandle() && ticket7a<=0)
         {
         ticket7a=OrderSend(Symbol(),OP_BUY,Lots1,Ask,2,0,Ask+TP7*_Point, "", Magic, 0, Lime);
         }
      if(BuySell7=="OP_SELL" && QuotePrice7==Bid && IsNewSELLCandle() && ticket7b<=0)
         {
         ticket7b=OrderSend(Symbol(),OP_SELL,Lots1,Bid,2,0,Bid-TP7*_Point, "", Magic, 0, Red);
         }

      if(BuySell8=="OP_BUY" && QuotePrice8==Ask && IsNewBUYCandle() && ticket8a<=0)
         {
         ticket8a=OrderSend(Symbol(),OP_BUY,Lots1,Ask,2,0,Ask+TP8*_Point, "", Magic, 0, Lime);
         }
      if(BuySell8=="OP_SELL" && QuotePrice8==Bid && IsNewSELLCandle() && ticket8b<=0)
         {
         ticket8b=OrderSend(Symbol(),OP_SELL,Lots1,Bid,2,0,Bid-TP8*_Point, "", Magic, 0, Red);
         }

      if(BuySell9=="OP_BUY" && QuotePrice9==Ask && IsNewBUYCandle() && ticket9a<=0)
         {
         ticket9a=OrderSend(Symbol(),OP_BUY,Lots1,Ask,2,0,Ask+TP9*_Point, "", Magic, 0, Lime);
         }
      if(BuySell9=="OP_SELL" && QuotePrice9==Bid && IsNewSELLCandle() && ticket9b<=0)
         {
         ticket9b=OrderSend(Symbol(),OP_SELL,Lots1,Bid,2,0,Bid-TP9*_Point, "", Magic, 0, Red);
         }

      if(BuySell10=="OP_BUY" && QuotePrice10==Ask && IsNewBUYCandle() && ticket10a<=0)
         {
         ticket10a=OrderSend(Symbol(),OP_BUY,Lots1,Ask,2,0,Ask+TP10*_Point, "", Magic, 0, Lime);
         }
      if(BuySell10=="OP_SELL" && QuotePrice10==Bid && IsNewSELLCandle() && ticket10b<=0)
         {
         ticket10b=OrderSend(Symbol(),OP_SELL,Lots1,Bid,2,0,Bid-TP10*_Point, "", Magic, 0, Red);
         }

      if(BuySell11=="OP_BUY" && QuotePrice11==Ask && IsNewBUYCandle() && ticket11a<=0)
         {
         ticket11a=OrderSend(Symbol(),OP_BUY,Lots1,Ask,2,0,Ask+TP11*_Point, "", Magic, 0, Lime);
         }
      if(BuySell11=="OP_SELL" && QuotePrice11==Bid && IsNewSELLCandle() && ticket11b<=0)
         {
         ticket11b=OrderSend(Symbol(),OP_SELL,Lots1,Bid,2,0,Bid-TP11*_Point, "", Magic, 0, Red);
         }

      if(BuySell12=="OP_BUY" && QuotePrice12==Ask && IsNewBUYCandle() && ticket12a<=0)
         {
         ticket12a=OrderSend(Symbol(),OP_BUY,Lots1,Ask,2,0,Ask+TP12*_Point, "", Magic, 0, Lime);
         }
      if(BuySell12=="OP_SELL" && QuotePrice12==Bid && IsNewSELLCandle() && ticket12b<=0)
         {
         ticket12b=OrderSend(Symbol(),OP_SELL,Lots1,Bid,2,0,Bid-TP12*_Point, "", Magic, 0, Red);
         }

      if(BuySell13=="OP_BUY" && QuotePrice13==Ask && IsNewBUYCandle() && ticket13a<=0)
         {
         ticket13a=OrderSend(Symbol(),OP_BUY,Lots1,Ask,2,0,Ask+TP13*_Point, "", Magic, 0, Lime);
         }
      if(BuySell13=="OP_SELL" && QuotePrice13==Bid && IsNewSELLCandle() && ticket13b<=0)
         {
         ticket13b=OrderSend(Symbol(),OP_SELL,Lots1,Bid,2,0,Bid-TP13*_Point, "", Magic, 0, Red);
         }

      if(BuySell14=="OP_BUY" && QuotePrice14==Ask && IsNewBUYCandle() && ticket14a<=0)
         {
         ticket14a=OrderSend(Symbol(),OP_BUY,Lots1,Ask,2,0,Ask+TP14*_Point, "", Magic, 0, Lime);
         }
      if(BuySell14=="OP_SELL" && QuotePrice14==Bid && IsNewSELLCandle() && ticket14b<=0)
         {
         ticket14b=OrderSend(Symbol(),OP_SELL,Lots1,Bid,2,0,Bid-TP14*_Point, "", Magic, 0, Red);
         }

      if(BuySell15=="OP_BUY" && QuotePrice15==Ask && IsNewBUYCandle() && ticket15a<=0)
         {
         ticket15a=OrderSend(Symbol(),OP_BUY,Lots1,Ask,2,0,Ask+TP15*_Point, "", Magic, 0, Lime);
         }
      if (BuySell15=="OP_SELL" && QuotePrice15==Bid && IsNewSELLCandle() && ticket15b<=0)
         {
         ticket15b=OrderSend(Symbol(),OP_SELL,Lots1,Bid,2,0,Bid-TP15*_Point, "", Magic, 0, Red);
         }

      if (BuySell16=="OP_BUY" && QuotePrice16==Ask && IsNewBUYCandle() && ticket16a<=0)
         {
         ticket16a=OrderSend(Symbol(),OP_BUY,Lots1,Ask,2,0,Ask+TP16*_Point, "", Magic, 0, Lime);
         }
      if (BuySell16=="OP_SELL" && QuotePrice16==Bid && IsNewSELLCandle() && ticket16b<=0)
         {
         ticket16b=OrderSend(Symbol(),OP_SELL,Lots1,Bid,2,0,Bid-TP16*_Point, "", Magic, 0, Red);
         }
   }
   return(0);
  }
//+------------------------------------------------------------------+

int Hour_trade()
{
   bool trade = false;
   if(Start_Hour > End_Hour)
      {
      if (Hour() >= Start_Hour || Hour() < End_Hour) trade = true;
      }
      else
      if (Hour() >= Start_Hour && Hour() < End_Hour) trade = true;

   return (trade);
}

bool IsNewBUYCandle()
   {
   static datetime saved_candle_time;
   if (Time[0]==saved_candle_time)
   return false;
   else
   saved_candle_time=Time[0];
   return true;
   }
   
bool IsNewSELLCandle()
   {
   static datetime saved_candle_time;
   if (Time[0]==saved_candle_time)
   return false;
   else
   saved_candle_time=Time[0];
   return true;
   }
      
void label()
{
Comment("\n ",
   "\n ",
   "\n ------------------------------------------------",
   "\n :: Pending+Order",
   "\n ------------------------------------------------",
   "\n :: Spread                 : ", MarketInfo(Symbol(), MODE_SPREAD),
   "\n :: Leverage               : 1 : ", AccountLeverage(),
   "\n :: Equity                 : ", AccountEquity(),
   "\n :: Hour Server             :", Hour(), ":", Minute(),
   "\n ------------------------------------------------");
}
