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 >
}
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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!