Example Close all profit

 

Code:

//+------------------------------------------------------------------+
//| Close profit position                                                                 |
//+------------------------------------------------------------------+
void CloseAllProfit()
  {
   double Balance = AccountInfoDouble(ACCOUNT_BALANCE);
   double Equity  = AccountInfoDouble(ACCOUNT_EQUITY);
   double profit  = (Balance * 105) / 100; // 10% of balance
   if(Equity >= profit)
   {
     for(int i=0; i < PositionsTotal(); i++)
     {
        if(PositionSelect(_Symbol))
        {
           eatrade.PositionClose(PositionGetTicket(i));
        }
     }
   }
  }
//+------------------------------------------------------------------+
 
 Please insert the code correctly: when editing a message, press the button   Codeand paste your code into the pop-up window. (The first time I corrected your message)
 
Thank you  Karputov
Vladimir Karputov
Vladimir Karputov
  • 2021.09.10
  • www.mql5.com
Trader's profile