Ea pending order


I’m editing an ea base on pending order buy stop and sell stop

can someone pls help me with the error occurred which i cant identified. im not so good in coding.

principles of this ea:

  1. place buy and sell stop simultaneously for every minute
  2. i can set TP and Sl manually

i really appreaciate if someone can help me with this
really need it.


ea_pending_order.mq5 24 kb

What error ?..

Obviously he cant identify the problem as he wrote :wink:

how do you count the open orders include the pendingsorder before one is close , I need that value
thanks a lot
I will just only the maximum of all the open orders that value I need


The EA must be able to isolate its trades from all others - Same or other EAs on the same or other charts.

Adding a magic number filter to the order select loop is sufficient if all EAs on all charts are using a unique one.

If you add the EA to another pair and forget to change the magic number, they’ll interfere with each other. Adding a symbol filter to the order select loop over comes the human’s forgetfulness.

If you add the EA to the same pair but different timeframe then again you have the same problem. I have the EA use a range of numbers to over come this.

extern int     Magic.Number.Base          = 20130213;
int init(){
   int      chrt.tf[]={ 0, PERIOD_M1, PERIOD_M5, PERIOD_M15, PERIOD_M30,
                           PERIOD_H1, PERIOD_H4, PERIOD_D1,  PERIOD_W1        };
   string   text.tf[]={ "n/a",   "M1",      "M5",      "M15",      "M30",
                                 "H1",      "H4",      "D1",       "W1"       };
   if(Chart.iTF == 0)   while(period.chart > chrt.tf[Chart.iTF])  Chart.iTF++;
   period.market  = chrt.tf[Chart.iTF];
   magic.number   = Magic.Number.Base + Chart.iTF;
bool     MySelect(int iWhat, int eSelect, int ePool=MODE_TRADES){
   if(!OrderSelect(iWhat, eSelect, ePool) )  return (false);
   if(OrderMagicNumber() != magic.number  )  return (false);
   if(OrderSymbol()      != symbol.chart  )  return (false);
   if(ePool != MODE_HISTORY               )  return (true);
   return(OrderType() <= OP_SELL);  // Avoid cr/bal https://www.mql5.com/en/forum/126192
                                    // https://www.mql5.com/en/forum/124726
                                    // Never select canceled orders.
      for(int iPos = OrdersTotal()-1; iPos >= 0; iPos--) if(
         MySelect(iPos, SELECT_BY_POS)
      ){ oo.ticket   = OrderTicket(); ..

I need only the maximum when one is closed I don’t need than the value

and how do I use them , which give me the value of the counting orders

I have only once nescensarry that value when orders are close it is not nessencary