Download MetaTrader 5
To add comments, please log in or register
Do you want to become a well-known developer? Execute the orders of traders in the Freelance service!
wadi2014
116
wadi2014 2014.05.01 19:07 

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.

Alain Verleyen
Moderator
28522
Alain Verleyen 2014.05.01 22:51  
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.
onewithzachy
2274
onewithzachy 2014.05.01 23:26  
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.


wadi2014
116
wadi2014 2014.05.02 08:34  
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
Alain Verleyen
Moderator
28522
Alain Verleyen 2014.05.02 08:38  
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.
SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.05.02 09:07  
Yes, Global Variables would really helps.
wadi2014
116
wadi2014 2014.05.02 19:06  

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 ?

SYED NAUFAL GADDAFI
1401
SYED NAUFAL GADDAFI 2014.05.03 00:06  
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.
/
To add comments, please log in or register