How to Disable / Enable Expert programmably ?

 

Hello

I want to Disable / Enable Expert (Auto Trading) button programmably as if i click on it to enable or disable Expert according to condition. I am searching MQL4 code to do that but i did not find.

Any help please.

 
fx2013:

Hello

I want to Disable / Enable Expert (Auto Trading) button programmably as if i click on it to enable or disable Expert according to condition. I am searching MQL4 code to do that but i did not find.

Any help please.

Not possible with mql4.
 
fx2013:

Hello

I want to Disable / Enable Expert (Auto Trading) button programmably as if i click on it to enable or disable Expert according to condition. I am searching MQL4 code to do that but i did not find.

Any help please.


What so hard doing that ?

void OnTick(void)
  {
  if ( whatever == happen )    
     {
     Print("Whatever has happen. Expert is disabled");

     return; //<<-- here's the secret, this return simulated that the EA is disabled, the rest of EA code will never executed
     }


  }


If you're need button on EA, there's a sample on MetaEditor called SamplePanel.mq4 found on Indicators/Examples/SimplePanel that I think can be use on EA as well.


 
angevoyageur:
Not possible with mql4.

But i need to close EA at certain condition, because i am using the same EA as basket, so if i use condition for stopping one EA the others will not stop. for this reason i want one EA disable auto trading as if i click on Auto trading
 
fx2013:
But i need to close EA at certain condition, because i am using the same EA as basket, so if i use condition for stopping one EA the others will not stop. for this reason i want one EA disable auto trading as if i click on Auto trading

You cannot disable auto trading by mql4 code, as I already said. You can follow onewithzachy suggestion by using a GlobalVariable to disable your EAs.
 
Yes, Global Variables would really helps.
 

I found solution as following codes

 #include <WinUser32.mqh>
 #import "user32.dll"
 
 int GetAncestor(int, int);
 #define MT4_WMCMD_EXPERTS  33020 

 #import
 extern bool Run=true;


 void OnTick()
  {
 
 int main = GetAncestor(WindowHandle(Symbol(), Period()), 2/*GA_ROOT*/);
 
 if(!Run)
  {
 PostMessageA(main, WM_COMMAND,  MT4_WMCMD_EXPERTS, 0 ) ;    // // Toggle Expert Advisor button 
 
Run=true;
  }
 
 

I did make Run=true to stop toggling the auto trading button from on to off and so on.

But i want to toggle Run after change it from true to false, to true again without click on Run to select true again on the EA.

So how to do that with MQL4 ?

 
We have given you the sample of how to make it happen but you choose to do it the hard way. No point in helping you if you don't even listen (read) properly on previous posts.
 
wadi2014:

I found solution as following codes

I did make Run=true to stop toggling the auto trading button from on to off and so on.

But i want to toggle Run after change it from true to false, to true again without click on Run to select true again on the EA.

So how to do that with MQL4 ?


Hello,


Using this Code Disables the Expert button, Its ok.

But I want to Re-Enable it, How to do it..?

 
Shantappa Kapase:

Hello,

Using this Code Disables the Expert button, Its ok.

But I want to Re-Enable it, How to do it..?

Opposite to all the denying postings here this has been possible *from* MQL since more than 10 years (not *with* pure MQL). To re-enable disabled experts just call the function again.

PostMessageA(main, WM_COMMAND,  MT4_WMCMD_EXPERTS, 0 ) ;

In fact the command toggles the EA status: enabled => disabled => enabled => disabled and so on.

 
You'll want to be using PostMessageW (not PostMessageA) - a change from ansi to unicode came in with build 600.
Reason: