EA to disable expert advisor button when cummulative profit reached

 

Hi guys,


the are any EA to disable expert advisor button when cummulative profit reached?


i found this, but it describe disable expert advisor when equity reach, maybe someone can change it to "when balance is 5000 + xxx" reached so ea will disable expert advisor.

"xxx" amount of money $ xxx that can be input in option ea. 

 

This one is work, but after target in balance or equity reached,

it not immediately disable expert advisor button, so another EA keep opened trades.

and droneox keep closing another EA trades, so much losing trade made from droneox_equity_guardian.


which are the problem?

int CloseAllTrade() 

  {

   int total=OrdersTotal();

   int t;

   int cnt=0;

   for(cnt=0; cnt<=total; cnt++)

     {

      bool s=OrderSelect(0,SELECT_BY_POS,MODE_TRADES);

      if(OrderType()==OP_BUY)

         t=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_BID),5,Violet);

      if(OrderType()==OP_SELL)

         t=OrderClose(OrderTicket(),OrderLots(),MarketInfo(OrderSymbol(),MODE_ASK),5,Violet);

      if(OrderType()>OP_SELL) //pending orders

         t=OrderDelete(OrderTicket());

     }

   return(0);

  }

 
AnthonyIvan:

Hi guys,


the are any EA to disable expert advisor button when cummulative profit reached?


i found this, but it describe disable expert advisor when equity reach, maybe someone can change it to "when balance is 5000 + xxx" reached so ea will disable expert advisor.

"xxx" amount of money $ xxx that can be input in option ea. 

You can add a setting to your EA for the money amount, then call the ExpertRemove function when you want to remove the EA. You could also send yourself a notification just before the expert is removed, so that you would know your profit target is reached. There are some ways to push the button that enables and disables automated trading globally, but I have not tried them. 

ExpertRemove - Common Functions - MQL4 Reference
ExpertRemove - Common Functions - MQL4 Reference
  • docs.mql4.com
The Expert Advisor is not stopped immediately as you call ExpertRemove(); just a flag to stop the EA operation is set. That is, any next event won't be processed, OnDeinit() will be called and the Expert Advisor will be unloaded and removed from the chart. //|                                            Test_ExpertRemove.mq5 |...
 
Matthew Colter:

You can add a setting to your EA for the money amount, then call the ExpertRemove function when you want to remove the EA. You could also send yourself a notification just before the expert is removed, so that you would know your profit target is reached. There are some ways to push the button that enables and disables automated trading globally, but I have not tried them. 

wow thanks!!