Hot keys, keyboard input, user input...

AnotherBrian

Hot keys, keyboard input, user input...

Post by AnotherBrian »

Since this is a coders forum, I'd like to discuss the different ways of getting user input into an EA, such as from a keyboard or other device.

The ones I am familiar with are;
  • Expert Advisor->Properties (the typical pop-up window we use)
    Double click a script which may or may not asked a question(s)
    Hot keys used to assign an EA, script, or indicator (right click on the script and select "Set hot key"). So if you assign a script called "close_pending" to Alt-C, when you hit Alt-C the script executes.

    Add something like the code below to your EA to use keyboard input;

Code: Select all

#import "user32.dll"   
bool      GetAsyncKeyState(int nVirtKey);
#import
#define KEYEVENTF_EXTENDEDKEY          0x0001
#define KEYEVENTF_KEYUP                0x0002
#define VK_P   80
#define VK_Q   81

#include <stdlib.mqh>
#include <stderror.mqh>
#include <WinUser32.mqh>
I've used all of them so far, I think the hot key is the most reliable (with the exception of the EA properties)

The dll isn't great because some traders don't want to load in a dll if they aren't sure what it's all about. Also, I've noticed it it isn't perfectly stable due to the incoming ticks not always being present.

I guess I started to toy around with this because I was looking for a "one shot" input to the EA. For example, I wanted to reset a stop back to a previous level with a confirmation pop up box, I don't think I can do this with EA code and the properties box (even if I could figure it out it is operationally clumsy).

I used the code above to allow user input with the keyboard.....
When the user presses Q and P together I have a pop-up fire off but when ticks are few, and the "Yes" button is clicked, the answer isn't always respected by the EA. This is how I currently reset a stop to previous value, in one of y EA's.

So I`m going to move away from this dll, now I will code the reset stop to previous location`` with a script and a hot key..... unless you guys have any better ideas.... :geek:
User avatar
RedLineFred
Trader
Posts: 52
Joined: Wed May 01, 2013 6:15 am
Location: Brisbane, Australia

Re: Hot keys, keyboard input, user input...

Post by RedLineFred »

Brian,

Did you manage to get any further on this one?

I am toying with the keyboard entry code and have managed to receive input, but my problem is that as my EA is running on various pairs (charts) I cant seem to direct the keyboard entry to the chart i am looking at.

The input is applied randomly across all incarnations of the EA running at the time.

Have you figured out a way to stay focussed on the one chart? so that any input is limited to the chart currently on view?

cheers,
Fred
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: Hot keys, keyboard input, user input...

Post by gaheitman »

RedLineFred wrote:Brian,

Did you manage to get any further on this one?

I am toying with the keyboard entry code and have managed to receive input, but my problem is that as my EA is running on various pairs (charts) I cant seem to direct the keyboard entry to the chart i am looking at.

The input is applied randomly across all incarnations of the EA running at the time.

Have you figured out a way to stay focussed on the one chart? so that any input is limited to the chart currently on view?

cheers,
Fred
You need to have your code check and see if the window it is running in is actually the active window. If it isn't, it needs to ignore keyboard input. Check out the code here: http://www.forexfactory.com/showthread. ... ost5803610

George
AnotherBrian

Re: Hot keys, keyboard input, user input...

Post by AnotherBrian »

RedLineFred wrote:Brian,

Did you manage to get any further on this one?

I am toying with the keyboard entry code and have managed to receive input, but my problem is that as my EA is running on various pairs (charts) I cant seem to direct the keyboard entry to the chart i am looking at.

The input is applied randomly across all incarnations of the EA running at the time.

Have you figured out a way to stay focussed on the one chart? so that any input is limited to the chart currently on view?

cheers,
Fred
I stopped using keyboard input - one of the main reasons is that you need a tick to trigger it, and you finger needs to stay on the keyboard (from what I recall). I see some others have put buttons on the screen, to activate you move the object with your mouse, the code detects this.
User avatar
RedLineFred
Trader
Posts: 52
Joined: Wed May 01, 2013 6:15 am
Location: Brisbane, Australia

Re: Hot keys, keyboard input, user input...

Post by RedLineFred »

Thanks gentlemen, appreciate your responses, and will try both the code George points to and the mouse over idea.
User avatar
RedLineFred
Trader
Posts: 52
Joined: Wed May 01, 2013 6:15 am
Location: Brisbane, Australia

Re: Hot keys, keyboard input, user input...

Post by RedLineFred »

I've had some success with the mouse button idea, but I have run into a slight problem and was wondering if there is a solution.

It comes back to the chart updates being applied on the next tick. While ok it would be great to have my code segment executed sooner, so that its ready for action when the next tick comes in rather than wait.

Has anyone got a solution for forcing a start() without a tick, say every 1sec?

The idea of continuously looping sounds too resource intensive.
AnotherBrian

Re: Hot keys, keyboard input, user input...

Post by AnotherBrian »

RedLineFred wrote:I've had some success with the mouse button idea, but I have run into a slight problem and was wondering if there is a solution.

It comes back to the chart updates being applied on the next tick. While ok it would be great to have my code segment executed sooner, so that its ready for action when the next tick comes in rather than wait.

Has anyone got a solution for forcing a start() without a tick, say every 1sec?

The idea of continuously looping sounds too resource intensive.
Don't leave the start function. I don't know how to do that, or what the new issues would be but I've read that somewhere.
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: Hot keys, keyboard input, user input...

Post by gaheitman »

AnotherBrian wrote:
RedLineFred wrote:I've had some success with the mouse button idea, but I have run into a slight problem and was wondering if there is a solution.

It comes back to the chart updates being applied on the next tick. While ok it would be great to have my code segment executed sooner, so that its ready for action when the next tick comes in rather than wait.

Has anyone got a solution for forcing a start() without a tick, say every 1sec?

The idea of continuously looping sounds too resource intensive.
Don't leave the start function. I don't know how to do that, or what the new issues would be but I've read that somewhere.
Just have a while loop in your start() procedure. Something like:

Code: Select all

while (true && !IsStopped()) {
  
  //do stuff
  
  Sleep(333);  //sleep for 1/3 of a second
  }
I don't like this method because you miss incoming ticks. What I prefer is using the normal start() response to incoming ticks, but supplementing the ticks by sending fake ticks every 1/3 of a second from an external program or script on another chart.

George
User avatar
RedLineFred
Trader
Posts: 52
Joined: Wed May 01, 2013 6:15 am
Location: Brisbane, Australia

Re: Hot keys, keyboard input, user input...

Post by RedLineFred »

George, could you elaborate on how to generate fake ticks as it sounds like the way to go.
User avatar
gaheitman
Trader
Posts: 655
Joined: Tue Nov 15, 2011 10:55 pm
Location: Richmond, VA, US

Re: Hot keys, keyboard input, user input...

Post by gaheitman »

RedLineFred wrote:George, could you elaborate on how to generate fake ticks as it sounds like the way to go.
I use offline range bar charts, so my needs aren't exactly normal. I use the attached script on the main chart and have it send ticks to the offline 4M chart that holds my range bars. There is an external program floating around that will send ticks as well, that others swear by. I'll see if I can find that one as well.

(FOUND IT: http://www.stevehopwoodforex.com/phpBB3 ... f=47&t=337)

This works for me, but your mileage may vary....

George
You do not have the required permissions to view the files attached to this post.
Post Reply

Return to “Coders Hangout”