Close the pending order on monday

 
i have an EA that sometime on monday when market open in gap give me a proble like this:
exemple
-on friday i have a long from 1.46 and a pending long from 1.4580 not filled yet and both have target at 1.47.
-on monday morning market open at 1.48 an my "great broker close my posistion at 1.47 but still remain one pending order,
so i want if on morning the first order go at target i automatic close all the other pending order how i can do that?

i write this few code but not work


if( DayOfWeek ()==0 && Hour()>=22)
   {
      OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY);
      orderclosetime=OrderCloseTime();
      rightnow=Year()+"-"+Month()+"-"+Day()+" "+Hour()+":"+Minute()+":"+Seconds()
      rightnow2=StrToTime(rightnow);
      if(OrderCloseTime() >= 22)
             for(cnt = total-1; cnt >= 0; cnt--)
               {
               OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);
               if( OrderType()!=OP_SELL && OrderType()!=OP_BUY) //&& trail==1 && OrdersTotal() > 1  )
               int result =OrderDelete(OrderTicket());
               }
    }
 

the first part look about if it's sunday night

   if( DayOfWeek ()==0 && Hour()>=22)

but then i should look about the last close order if it close on sunday open, ad es i have 3 order 2 pending and one at market with target 1.47

market on sunday open at 1.48 so the broker close me at 1.47!!!!

i want if this order is close that all the pending is cancelled

so i should look at date time

      OrderSelect(OrdersHistoryTotal()-1, SELECT_BY_POS, MODE_HISTORY);
      
      if(OrderCloseTime() >= 22)

but this closetime 22 i know is wrong, so how i do that?

datetime give me a string like that

rightnow=Year()+"-"+Month()+"-"+Day()+" "+Hour()+":"+Minute()+":"+Seconds();
rightnow2=StrToTime(rightnow);

Reason: