How to toggle "Autotrading" button using MQL

Hello everyone, I wanted to know if there is a method or code to disable or enable the button “Autotrading” high on the MT4 thanks.

No code to over ride it no.

maybe we can push this button “auto trading” through win API? any ideas

This is possible to “click” button by WinAPI.

How to do that…?

Hello everyone and thanks for asking.

After much searching on and off the site MQL5 I managed to find this old post. http://forum.mql4.com/62896 I tried and it works. when the variable is changed Run the code enabled if it is disabled autorading and vice versa.

thank you all. (the last post in the trend is good)

Using different API tools its possible. That means stimulating mouse clicks on the area of the Autotrade button. U cant use mql for that but other eg VB, C# java etc. Your Mt4 terminal must be maximized else it will miss the clicks. U wanted to enable or disable Auto trade? That is also possible if u can read pixel colors. Windows api mouse calls can determine the pixel color at screen x,y. Check the color code of the little green arrow and the red square on the Autotrade button. Wen its red then it means it was disabled so then it will be enabled or else click again simulation to disable trade

You can’t disable autotrading but you can close all charts in the mt4/mt5, effectively eliminating all eas from execution.


void CloseAllCharts()
{
   long chid=ChartFirst();
   long pom;
   for(int i=0;i<50;i++)
   {
      pom  = ChartNext(chid);
      ChartClose(chid);
      chid=pom;
      if(chid == -1) return;
   }   
}

Hi, though it is old topic but some may looking for it.

This is the basic script, it will disable and enable autotrading every 10 seconds, you just need to change timer to 1 second and them put any condition you want inside the code with OnTimer() function, or add any options settings, like trading times, indicator signals, profit/loss percent etc.

hope this help

//±-----------------------------------------------------------------+
//| a.mq4 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//±-----------------------------------------------------------------+
#property copyright “Copyright 2020, MetaQuotes Software Corp.”
#property link “https://www.mql5.com
#property version “1.00”
#property strict
#include <WinUser32.mqh>
#import “user32.dll”
int GetAncestor(int,int);
#define MT4_WMCMD_EXPERTS 33020
#import
bool Disable=false;
bool Enable=false;
//±-----------------------------------------------------------------+
//| Expert initialization function |
//±-----------------------------------------------------------------+
int OnInit()
{
//—
EventSetTimer(10);
//—
return(INIT_SUCCEEDED);
}
//±-----------------------------------------------------------------+
//| Expert deinitialization function |
//±-----------------------------------------------------------------+
void OnDeinit(const int reason)
{
//—
EventKillTimer();
}
//±-----------------------------------------------------------------+
//| Expert tick function |
//±-----------------------------------------------------------------+
void OnTimer()
{
int main=GetAncestor(WindowHandle(Symbol(),Period()),2);
if(!Disable)
{
PostMessageA(main,WM_COMMAND,MT4_WMCMD_EXPERTS,0);
Disable=true;
Enable=false;
}
else
{
PostMessageA(main,WM_COMMAND,MT4_WMCMD_EXPERTS,0);
Enable=true;
Disable=false;
}
}
//±-----------------------------------------------------------------+

Now I am looking for MT5 version if anyone can help I would really appreciate

Plase help me to input fitur target profit equity in your coding ea. :pray:
//±-----------------------------------------------------------------+
//| a.mq4 |
//| Copyright 2020, MetaQuotes Software Corp. |
//| https://www.mql5.com |
//±-----------------------------------------------------------------+
#property copyright “Copyright 2020, MetaQuotes Software Corp.”
#property link “https://www.mql5.com
#property version “1.00”
#property strict
#include <WinUser32.mqh>
#import “user32.dll”
int GetAncestor(int,int);
#define MT4_WMCMD_EXPERTS 33020
#import
bool Disable=false;
bool Enable=false;
//±-----------------------------------------------------------------+
//| Expert initialization function |
//±-----------------------------------------------------------------+
int OnInit()
{
//—
EventSetTimer(10);
//—
return(INIT_SUCCEEDED);
}
//±-----------------------------------------------------------------+
//| Expert deinitialization function |
//±-----------------------------------------------------------------+
void OnDeinit(const int reason)
{
//—
EventKillTimer();
}
//±-----------------------------------------------------------------+
//| Expert tick function |
//±-----------------------------------------------------------------+
void OnTimer()
{
int main=GetAncestor(WindowHandle(Symbol(),Period()),2);
if(!Disable)
{
PostMessageA(main,WM_COMMAND,MT4_WMCMD_EXPERTS,0);
Disable=true;
Enable=false;
}
else
{
PostMessageA(main,WM_COMMAND,MT4_WMCMD_EXPERTS,0);
Enable=true;
Disable=false;
}
}
//±-----------------------------------------------------------------+