11 Dec 2023, 14:51

I messed with creating it a different way and this worked just as well with less code . The if statement just checks the current status and if its on, then it toggles the button. Otherwise it does nothing. There is no custom function to make or anything.

Screenshot 2023-12-11 084504.png

// Global Variables, includes

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

//  Main Code

if (IsTradeAllowed()){
int main = GetAncestor(WindowHandle(Symbol(), Period()), 2/*GA_ROOT*/);
PostMessageA(main, WM_COMMAND, MT4_WMCMD_EXPERTS, 0);
}