This script is made to disable the EA on the chart from trading, Its made to click the following buton on the image, automatically :
In the following code, its getting the handle of the main Metatrader and open the Expert tab (command 33048 is in mt4, for mt5 It’s different)
int hMetaTrader = GetAncestor(WindowHandle(Symbol(),Period()),2);Â Â Â Â Â Â Â Â Â Â PostMessageA (hMetaTrader, WM_COMMAND , 33048, 0); Sleep(200); //It's important to keep at least 0.2 secs to let the window open correctly
Then we need to check what tab we are currently on, we get the name of the tab and auto correct to go to the right one :
int kid=get(hMetaTrader);     string top=name(kid);     if(top=="Common "){//if the window is already the right one (Common section tab), just find the button, click it and click OK       kid=avance(kid);             int is_checked=check_state(kid);             if(is_checked){Print("button is currently checked");}       else{Print("button is currently NOT checked");}             Sleep(10);       PostMessageW(kid,WM_LBUTTONDOWN,1,0);//press the left mouse button       Sleep(10);       PostMessageW(kid,WM_LBUTTONUP ,1,0);//release it       Sleep(10);       PostMessageA(kid,WM_KEYDOWN,0x0D,0);//pressing enter to validate the selection       return 0;             }   else if(top==""){//if the tab is the "About" section, press ctrl+tab (to go 1 tab forward)       Print("first");       Sleep(10);       keybd_event(17,0,0,0);       Sleep(10);       keybd_event(9,0,0,0);       Sleep(10);       keybd_event(9,0,KEYEVENTF_KEYUP,0);       Sleep(10);       keybd_event(17,0,KEYEVENTF_KEYUP,0);       Sleep(10);       }   else{//if the tab is "Inputs" then press ctrl+maj+tab (to go 1 tab back)       keybd_event(17,0,0,0);       Sleep(10);       keybd_event(16,0,0,0);       Sleep(10);       keybd_event(9,0,0,0);       Sleep(10);       keybd_event(9,0,KEYEVENTF_KEYUP,0);       Sleep(10);       keybd_event(16,0,KEYEVENTF_KEYUP,0);       Sleep(10);       keybd_event(17,0,KEYEVENTF_KEYUP,0);       Sleep(10);       }
And then finally if the tab wasn’t the right one, find the button “allow auto trading” and press it to disable it :
  Sleep(100);   kid=get(hMetaTrader);   kid=avance(kid);   Sleep(100);   bool is_checked=check_state(kid);   if(is_checked){Print("button is currently checked");}   else{Print("button is currently NOT checked");}     Print(name(kid));   PostMessageW(kid,WM_LBUTTONDOWN,1,0);   Sleep(10);   PostMessageW(kid,WM_LBUTTONUP,1,0);   Sleep(10);   PostMessageA(kid,WM_KEYDOWN,0x0D,0);
I forgot to mention that the code is going to click this particular button even if the autotrading is already off so Its going to activate it, disable it, activate it.. Thats why I made a special function to get the current state of the button, you can modify the code as you want to change it getting the button state with this function :
int kid=<HANDLE OF THE BUTTON> bool is_checked=check_state(kid); bool check_state(int handle){ Â Â return (bool)SendMessageA(handle, 0x00F0, 0, 0); Â Â }