MT5 toggle AutoTrading button

Hello. Can Anybody help me? I found the following code that works on MT4 to toggle AutoTrading button:

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

void OnTick()
   int main=GetAncestor(WindowHandle(Symbol(),Period()),2/GA_ROOT/);
   PostMessageA(main,WM_COMMAND,MT4_WMCMD_EXPERTS,0);    // // Toggle Expert Advisor button 

I tried to convert to MQL5, but it didn’t work:

#include <WinAPI\winuser.mqh>
#define WM_COMMAND   0x0111
#define MT5_WMCMD_EXPERTS  32851

      case 0: return(PERIOD_CURRENT);
      case 1: return(PERIOD_M1);
      case 5: return(PERIOD_M5);
      case 15: return(PERIOD_M15);
      case 30: return(PERIOD_M30);
      case 60: return(PERIOD_H1);
      case 240: return(PERIOD_H4);
      case 1440: return(PERIOD_D1);
      case 10080: return(PERIOD_W1);
      case 43200: return(PERIOD_MN1);
      case 2: return(PERIOD_M2);
      case 3: return(PERIOD_M3);
      case 4: return(PERIOD_M4);      
      case 6: return(PERIOD_M6);
      case 10: return(PERIOD_M10);
      case 12: return(PERIOD_M12);
      case 16385: return(PERIOD_H1);
      case 16386: return(PERIOD_H2);
      case 16387: return(PERIOD_H3);
      case 16388: return(PERIOD_H4);
      case 16390: return(PERIOD_H6);
      case 16392: return(PERIOD_H8);
      case 16396: return(PERIOD_H12);
      case 16408: return(PERIOD_D1);
      case 32769: return(PERIOD_W1);
      case 49153: return(PERIOD_MN1);      
      default: return(PERIOD_CURRENT);

void OnTick()
      int main=GetAncestor(WindowHandle(Symbol(),Period()),2/*GA_ROOT*/);
      PostMessageW(main, WM_COMMAND,MT5_WMCMD_EXPERTS,0);    // // Toggle Expert Advisor button 

int WindowHandle(string symbol,int tf)
   ENUM_TIMEFRAMES timeframe=TFMigrate(tf);
   long currChart,prevChart=ChartFirst();
   int i=0,limit=100;
      if(currChart<0) break;
         && ChartPeriod(currChart)==timeframe)

Any suggestions or ideas?

A simpler attempt (that didn’t work either) based on a solution i found elsewhere:

#include <WinAPI\winuser.mqh>

#define WM_COMMAND 0x0111
#define MT5_WMCMD_EXPERTS 32851

void OnStart()
   int wHandle=(int)ChartGetInteger(0,CHART_WINDOW_HANDLE);
   long hMDI=GetParent(GetParent(wHandle));

You can find a solution for your question here. Please see this link

Auto Trader Auto Trader
ExMassV2_HTF The ExMassV2 indicator with the timeframe selection option available in input parameters. ExVolV2_HTF The ExVolV2 indicator with the timeframe selection option available in input parameters. ColorX2MA_Cloud Universal moving average which fills the chart space with a colored background. The…

Fantastic! it’s a completely different approach (it doesn’t use postmessage), but most important: it works! Thanks