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
#import

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
#import


ENUM_TIMEFRAMES TFMigrate(int tf)
  {
   switch(tf)
     {
      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;
   while(i<limit)
     {
      currChart=ChartNext(prevChart);
      if(currChart<0) break;
      if(ChartSymbol(currChart)==symbol
         && ChartPeriod(currChart)==timeframe)
         return((int)currChart);
      prevChart=currChart;
      i++;
     }
   return(0);
  }  

Any suggestions or ideas?

 

A simpler attempt (that didn't work either) based on a suggestion of Alain Verleyen was: 


#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));
   Print(hMDI);
   PostMessageW(hMDI,WM_COMMAND,MT5_WMCMD_EXPERTS,0);
  }
 
carlosduna:

A simpler attempt (that didn't work either) based on a suggestion of Alain Verleyen was: 


What suggestion ?

 
Alain Verleyen:

What suggestion ?

I tried to solve my problem (unfortunately without success) using part of your answer  in this post https://www.mql5.com/en/forum/38132. The part I used from your answer worked! I guess de handler is ok, and the problem is probably on the PostMessageW or on the defines


About this one, and advice on how to make it work?

how to programmatically arrange windows as non-overlapping tiles
how to programmatically arrange windows as non-overlapping tiles
  • 2014.12.03
  • www.mql5.com
Dear all, May i know how to programmatically arrange windows as non-overlapping tiles? Since MT5 provide a toolbar(by pressing ALT+R) for or this...
 
carlosduna:

I tried to solve my problem (unfortunately without success) using part of your answer  in this post https://www.mql5.com/en/forum/38132. The part I used from your answer worked! I guess de handler is ok, and the problem is probably on the PostMessageW or on the defines


About this one, and advice on how to make it work?

I see.

Auto Trader
Auto Trader
  • www.mql5.com
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...
 
Alain Verleyen:

I see.

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

 
Alain Verleyen:

What suggestion ?

Hello,

How can I to know the flags for differents events using PostMessageW?

Example: I need open MQL5\logs using PostMessageW. I know for MT4 the flag is 35435, but Which it is for MT5?

Thanks!