stop this script from opening double pending orders

 

Hello. I have this script that works excellent. What it does is it opens 5 pending trades below and 5 below the current price. I split up the script so I have one for -buy or sell- and/or -buy and sell - as the need arises. And would like to ad a feature to it if possible. I would like for it to NOT open matching pending orders. Sometime I end up having 3 or 4 matching pending orders. so i go and delete them by hand.

If the above is not possible... then another script to close all double pending orders.

Here is the script.


Thank you.


//+------------------------------------------------------------------+
//|                                              Ty_PendingOrder.mq4 |
//|                 Copyright © 2010, tyfinity - mykautsar@gmail.com |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, tyfinity - mykautsar@gmail.com"
#property link      ""
extern int gridspace = 125;
extern int gridnum   = 5;





//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
   double pgrid = Bid*MathPow(10,Digits);
   double mgrid = MathMod(pgrid,gridspace);
   double grid  = pgrid-mgrid;

   if (mgrid>=gridspace/2)
      {
      for (int i=1;i<=gridnum;i++) {
         double midgrid = (grid+gridspace)/MathPow(10,Digits);
         double uppergrid = midgrid+gridspace*i/MathPow(10,Digits);
         double lowergrid = midgrid-gridspace*i/MathPow(10,Digits);
       //OrderSend(Symbol(),OP_BUYSTOP,0.03,uppergrid,0,0,0,"grid"+i,NULL,0,CLR_NONE);
       //ObjectCreate("bhl"+i,OBJ_HLINE,0,0,uppergrid);ObjectSet("bhl"+i,OBJPROP_COLOR,Black);
       OrderSend(Symbol(),OP_SELLSTOP,0.03,lowergrid,0,0,0,"grid"+i,NULL,0,CLR_NONE);
       //ObjectCreate("shl"+i,OBJ_HLINE,0,0,lowergrid);ObjectSet("shl"+i,OBJPROP_COLOR,Black);
         } 
      }
   else
      {
      for ( i=1;i<=gridnum;i++) {
      midgrid = grid/MathPow(10,Digits);
      uppergrid = midgrid+gridspace*i/MathPow(10,Digits);
      lowergrid = midgrid-gridspace*i/MathPow(10,Digits);
    //OrderSend(Symbol(),OP_BUYSTOP,0.03,uppergrid,0,0,0,"grid"+i,NULL,0,CLR_NONE);
    //ObjectCreate("bhl"+i,OBJ_HLINE,0,0,uppergrid);ObjectSet("bhl"+i,OBJPROP_COLOR,Black);
    OrderSend(Symbol(),OP_SELLSTOP,0.03,lowergrid,0,0,0,"grid"+i,NULL,0,CLR_NONE);
    //ObjectCreate("shl"+i,OBJ_HLINE,0,0,lowergrid);ObjectSet("shl"+i,OBJPROP_COLOR,Black);

}
}




//----
   return(0);
  }
//+------------------------------------------------------------------+
 
extern int gridnum   = 1;//5;
 
cool. I'll try that. Thank you.