Would like to close all open positions when equity has increase 10%

 

Hello, I think I would need to use a global variable to do this.

If my starting balance was $500 and equity increased by 10% to $550, I would like to close all postions

The new balance would be $550

Then if equity increased by 10% to $605, close all positions

new balance $605

Then if equity increased 10% to morethan or equal to $660.50, close all positions

and so on...

 

Try this:

int start()
{ 
if(AccountEquity()-AccountBalance()>=AccountBalance()*0.1) CloseAllTrades();
return(0);
}
 
// insert the following after int start() {} section of EA code. 
void CloseAllTrades() {
   for (int i=0; i<OrdersTotal(); i++) { 
      if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { 
         if (OrderSymbol()==Symbol()) { 
            if (OrderType()==OP_BUY) 
               OrderClose(OrderTicket(),OrderLots(),Bid,GetSlippage(),clCloseBuy);
            if (OrderType()==OP_SELL) 
               OrderClose(OrderTicket(),OrderLots(),Ask,GetSlippage(),clCloseSell);
            if (OrderType()==OP_SELLSTOP || OrderType()==OP_SELLLIMIT || 
                OrderType()==OP_BUYSTOP || OrderType()==OP_BUYLIMIT) 
               OrderDelete(OrderTicket());
         }
      }
   }
}
Reason: