Close All Trades at percentage of profit/loss EA

 

I would be grateful if anyone could point me to a simple EA that could close all trades on a platform when the floating profit meets a certain percentage target (profit or loss). Thank you!

 

int CloseAll()
{
    int   iCheck = 1 ;
    bool  bResponse  ; 
 
    int   N = OrdersTotal () - 1    ;
    for ( int i = N ; i >= 0 ; i -- )
        {
          OrderSelect ( i , SELECT_BY_POS , MODE_TRADES ) ;
      
          if      ( ( OrderType () == OP_BUY  ) || ( OrderType () == OP_SELL ) )
                    {
                      bResponse  = OrderClose ( OrderTicket () , OrderLots () , OrderClosePrice () , 0 , White ) ;
                    }
  
          else if ( ( OrderType () == OP_SELLLIMIT )
                 || ( OrderType () == OP_SELLSTOP  )
                 || ( OrderType () == OP_BUYLIMIT  )
                 || ( OrderType () == OP_BUYSTOP   ) )
                    {
                      bResponse  = OrderDelete ( OrderTicket () ) ;
                    }
 
          if        ( bResponse == false )
                      iCheck     = -1    ;
 
        } // for
 
    return ( iCheck ) ;
}
 
 
int start ()
{
//< Initialization >
    static bool bCloseCondition = false ;
    static int  iCloseResponse  = EMPTY ;
//</Initialization >
  
//< TO DO : Change condition >
    bCloseCondition = ( OrdersTotal () > 0 ) ;
//</TO DO : Change condition >
 
//< Main routine >
    if ( bCloseCondition == true ) 
       {
         iCloseResponse = CloseAll () ;
 
         Alert ( "Close All response code : " , iCloseResponse ) ;
       }
//</Main routine >
}
 
 

Reason: