A Professional with an Expert Help is needed URGENTLY!

 
Hi, Can anyone assist me to write a simple code that would close All open orders and delete All pending orders
when  a condition is fulfilled ( equity>=balance*1.2||equity<=balance*0. 8). Thanks in advance.
 
See sample

int  Duration=1;
 
int MagicExpert=666666;
 
int CheckForClose(int type)
 {
  if (Duration!=0)
   { //Lenght of time a postion is held 
 
    for(int i2=OrdersTotal()-1;i2>=0;i2--)
     {
     if(!OrderSelect(i2,SELECT_BY_POS,MODE_TRADES))        continue;
      if(OrderMagicNumber()!=MagicExpert) continue;
       if (OrderOpenTime()<TimeCurrent()-Duration*60*720)
        {//Duration*60*720 
         if (OrderType()==OP_BUY)
          {
          OrderClose(OrderTicket(),OrderLots(),Bid,3,Yellow);
          }
         if (OrderType()==OP_SELL)
          {
          OrderClose(OrderTicket(),OrderLots(),Ask,3,Violet);
          }
        }// end if(OrderOpenTime()<TimeCurrent()-Duration*60*720)
     }// end for(int i2=OrdersTotal();i2>=0;i2--)
   }   //end duration check
 }//end check for close
Reason: