Can I code in MQL to turn on and off an already running EA?

 
Thanks.
 

You can put code in your EA that tells it when to abandon or continue processing after it is started by a tick.

 
phy:

You can put code in your EA that tells it when to abandon or continue processing after it is started by a tick.

Thanks. However, I am working for a person and he wants me to creat an EA controller to be used it as clicking the Expert Advisors icon on the MT4's interface. I have no access to the already running EAs.

 

VF

> I have no access to the already running EAs...?

Oh yes you do :)

Check out Global variables, see https://book.mql4.com/variables/globals

All the EA's could see a global variable set by one EA to 'stop trading'

Good luck

-BB-

 
BarrowBoy:

VF

> I have no access to the already running EAs...?

Oh yes you do :)

Check out Global variables, see https://book.mql4.com/variables/globals

All the EA's could see a global variable set by one EA to 'stop trading'

Good luck

-BB-

Thanks, but i don't have right to modify all the EAs(they cannot see a global variable set by one EA). I just want to one EA to stop or restart all the running EAs.

 

Ahhh - what an odd one!

OK - OTTOMH

You have a 'Stopper' EA running with the other EA's in a named profile.

The Stopper EA calls a DLL to execute a batch file that:-

1) Uses %WINDIR%\SYSTEM32\taskkill.exe to kill the active MT instance (taskkill comes with XP Pro or WinServer 2003)

2) Starts another instance of MT from a different folder with a different named Profile but connected to the right account, with just the 'Starter' EA loaded

..

The Starter waits until the signal then calls an different batch file that reverses the process

Phew!

Rather you than me matey!

See examples of starting MT here 'Command line options for terminal.exe'

and DLL calls here https://www.mql5.com/en/forum/110839

Good luck - you'll need it

-BB-

 

keybd_event API function is used to send keystrokes


#import "user32.dll"

void keybd_event(int bVk,int bScan,int dwFlags,int dwExtraInfo);


...


keybd_event(19,0,0,0); //Pause button


read MSDN about usage

 
nickbilak:

keybd_event API function is used to send keystrokes


#import "user32.dll"

void keybd_event(int bVk,int bScan,int dwFlags,int dwExtraInfo);


...


keybd_event(19,0,0,0); //Pause button


read MSDN about usage

Thanks, your method works.

the function keybd_event is defined in the WinUser32.mqh, so we can do as this:

#include <WinUser32.mqh>

I use Ctrl+E to enable and disable the Expert Advisors, so the code is:

keybd_event(17,0,0,0); // 17=Ctrl
keybd_event(69,0,0,0); // 69=E
keybd_event(69,0,KEYEVENTF_KEYUP,0);
keybd_event(17,0,KEYEVENTF_KEYUP,0);

 

firstly - I am not a Windows programmer. Secondly - what I say below is from a first quick read of MSDN Windows User Interface and related sections... ie, Keyboard Input Model...

My requirement is not to emulate keystrokes so that Client Terminal handles them: ie, Ctrl+E seen so that Expert Advisors ON/OFF state toggled.

I wish to capture keystrokes inside my script/indicator/EA when the program chart window has focus.

.

Further to this topic - keybd_event(), as I understand it this function synthesizes a keystroke.... and the window with focus also has keyboard focus so that keyboard messages are sent to this window - iow, Client Terminal gets whatever keybd_event() stuffs into the keyboard's input stream. [I also read that SendInput() is latest function for this keystroke stuffing process]

.

Anyway,

Is it required to hijack Client Terminal's focus via [Get/Set]Focus() or the like?

I'd hazard a guess that via API calls the program can get it's Window id? and then [temporarily] take over handling of keyboard messages from the Window's msg queue?

How handle non-system keyboard messages that program has no interest in?

As above, what about system keyboard messages eg, ALT+...

Too many questions and not enough knowledge!


.

Would really appreciate you Windows programmers giving advice + MQL4 examples etc.

btw, any schemes must be non-clever in that not want to cause issues with Client Terminal's normal handling of keyboard input handling.

.

Thank you


================

edit:

1. just saw another thread "please help on capturing word or ASCII from the keyboard"

RickD 2006.11.16 03:47

Create a script, run a loop and periodically call user32.dll GetKeyState function.

So... off to MSDN "GetKeyState Function" under Keyboard Input Reference > Functions and see:

GetKeyState Function

The GetKeyState function retrieves the status of the specified virtual key.

The status specifies whether the key is up, down, or toggled (on, off—alternating each time the key is pressed).

2. but - would not Client Terminal get their before my program?

damn - those questions again!

 
fbj:

firstly - I am not a Windows programmer. Secondly - what I say below is from a first quick read of MSDN Windows User Interface and related sections... ie, Keyboard Input Model...

My requirement is not to emulate keystrokes so that Client Terminal handles them: ie, Ctrl+E seen so that Expert Advisors ON/OFF state toggled.

I wish to capture keystrokes inside my script/indicator/EA when the program chart window has focus.

[...]

I'd hazard a guess that via API calls the program can get it's Window id? and then [temporarily] take over handling of keyboard messages from the Window's msg queue?


What you're describing is possible. The MQL function WindowHandle(Symbol(), 0) will give you the raw hWnd for the current chart window. You could then do bespoke handling of messages, in a DLL, using the time-honoured technique of subclassing the window by altering its GWL_WNDPROC. That gives you access to pretty much everything: keyboard events, mouse clicks, the works.


The big problem you eventually hit with this route is if you want the EA (rather than the DLL) to do something in response to e.g. a keyboard event. You've got to find a way of passing back information from the DLL to the EA, which isn't pretty, and more or less has to imply some system whereby the EA repeatedly polls the DLL to ask if anything relevant has happened. The only possible alternative is giving the DLL a pointer to a global variable in the EA, and hoping that the pointer remains valid...


However, I'm afraid that if you're "not a Windows programmer" then what I'm describing is possible, but hopelessly impractical.

 

jjc - thanks for the response. yessss - even tho I have 5th ed. Petzold and am many years programmer - have never ever done any Windows stuff beyond a few API calls in MQL to satisfy self that yes... is possible to get info from Windows, but just play and not work.

Interesting nevertheless. The EAs window handle hWnd is the key. The lock, as you say, would need more than the key when the knowledge to know how to turn it is missing!

Hummm, I am cheered up by this bit of info and will spend those idle moments when suffering from MQL'ers block and snoop further inside MSDN and the web at large.

Actually, I'll look for code that achieves what you have described.

Once I have that, I can self-tutor until understand how it works. That is hard but very fun - especially when have a reason for getting dirty hands :-)


I will endeavor to [sometime this century!] post my working code - I will consider that is possible within MQL4 + #import "..."

If nothing else, bound to pick up some knowledge... I like to hammer and chisel away. The fun of what may be around the corner is worth the sweat and blisters!


Thanks a lot - your post contains many keywords for me to pursue.

Reason: