How to Disable / Enable Expert programmably ? - page 2

 
Shantappa Kapase: But I want to Re-Enable it, How to do it..?
You stopped the EAs, they are not running, therefor you can't add any code to start them.
 
alphatrading:

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.

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


Hello,

You are correct, the command toggles the EA status: enabled => disabled => enabled => disabled and so on.

I want, disable the Button only if it Enabled. or vice versa.

Thnx!

 
wadi2014:

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.


Hello, 

Regarding the Enable/Disable the Expert Button on MT4.

I want Disable the Button only if Its Already Enabled.

The Function 

PostMessageA(main, WM_COMMAND,  MT4_WMCMD_EXPERTS,0);

Only toggles like Enable->Disable->Enable->Disable.

I dont want toggle, want to Disable the Button only if Its Already Enabled.


Thanking you.!
 
Shantappa Kapase: I dont want toggle, want to Disable the Button only if Its Already Enabled.
You already know that it's enabled -- the code is running. After you disable it, nothing will run again.
 
whroeder1:
You already know that it's enabled -- the code is running. After you disable it, nothing will run again.
This is not exact, enable/disable only concern trading operations, for all the rest EA is continuing to run.
 
Hello,

How to do the same for MT5?
(Programmatically enable and disable AutoTrading)
 
alphatrading:

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.

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

Great!

Thank you.

I use this on a indicator to enable/disable the auto trade.

 
Shantappa Kapase:

Hello, 

Regarding the Enable/Disable the Expert Button on MT4.

I want Disable the Button only if Its Already Enabled.

The Function 

PostMessageA(main, WM_COMMAND,  MT4_WMCMD_EXPERTS,0);

Only toggles like Enable->Disable->Enable->Disable.

I dont want toggle, want to Disable the Button only if Its Already Enabled.


Thanking you.!


Use this code:

int hterminal = GetAncestor(WindowHandle(Symbol(),Period()),GA_ROOT);
if( hterminal !=0 )
{
           if (TerminalInfoInteger(TERMINAL_TRADE_ALLOWED))
           {
              PostMessageA(hterminal,WM_COMMAND,MT4_WMCMD_EXPERTS,0);
              Print("AutoTrading disabled.");
           }
           else Print("AutoTrading already disabled.");
}          
else Print("GetAncestor error:",GetLastError());
 
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 ?

//modified it sir so it can be used on buttons for click events as well

#include <WinUser32.mqh>

#import "user32.dll"

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int GetAncestor(int, int);
#define MT4_WMCMD_EXPERTS  33020

#import
extern bool Run=true;
#import
extern bool ExpertEnabled=true; // Expert is Enabled


//+------------------------------------------------------------------+
//| ChartEvent function                                              |
//+------------------------------------------------------------------+
void OnChartEvent(const int id,
                  const long &lparam,
                  const double &dparam,
                  const string &sparam)
  {
//---

   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;
     }
   else
     {
      PostMessageA(main, WM_COMMAND,  MT4_WMCMD_EXPERTS, 0) ;     // // Toggle Expert Advisor button
      Run=false;
     }
  }
 
Salvador Ursua

I have no programming idea, and I need the autotrading button to be disabled when I have a float of more than x%. And then lower the float of that x% to activate the autotrading button again.

Reason: