close percent ea

 
I have searched mql5 and online and cannot find an ea which will close any trading position out at x percent of loss of one trade. from another ea like you can input magic number in their.
 
Elliot Debonee:
I have searched mql5 and online and cannot find an ea which will close any trading position out at x percent of loss of one trade. from another ea like you can input magic number in their.

https://www.mql5.com/en/code/35335/248689

 

Hi Elliot Debonee


Please try use this code

void CloseProfitPartial()
  {
   for(int i = 0; i < PositionsTotal(); i ++)
     {
      if(eaposition.SelectByIndex(i))
        {
         string PosSymbol        = eaposition.Symbol();
         double Profit           = eaposition.Profit();
         ulong ticket            = eaposition.Ticket();
         double volume           = eaposition.Volume();
         string comment          = eaposition.Comment();
         if(Profit >= TargetProfit && PosSymbol == _Symbol && volume > 0.01)
           {
            eatrade.PositionClosePartial(ticket,volume / 2);
           }
        }
     }
  }
Elliot Debonee
Elliot Debonee
  • 2021.08.29
  • www.mql5.com
Trader's profile
Reason: