Forex



Go Back   Forex Trading > Training > Metatrader > Metatrader 4 mql 4 - Development course






Register in Forex TSD!
Trading Systems Leaders in this forum (automated trading systems) are winning more than 3000 pips in a month (30000$ investing one lot every time).
Click here to register and get more information

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 09-23-2006, 12:15 PM
Member
 
Join Date: Mar 2006
Posts: 49
pipeline is on a distinguished road
Key event within mq4 programs

Hi Codersguru,

I would like an indicator(/EA) that reacts to users' commands: the indicator would do a task upon the striking of "F5", "Ctrl+P", or of any assigned key of my choice:

start
{
...
if ("Key event") function(x1,x2);
...
}

function(x1,x2)
{
...
Print("Hey it's Saturday for goodness sake");
...
}

Is there such a possibility in mql?

Thanks for your help and all your tutorials/tips!

pipeline
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #2 (permalink)  
Old 09-23-2006, 03:07 PM
codersguru's Avatar
Senior Member
 
Join Date: Oct 2005
Posts: 994
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Thumbs up Good idea!

Quote:
Originally Posted by pipeline
Hi Codersguru,

I would like an indicator(/EA) that reacts to users' commands: the indicator would do a task upon the striking of "F5", "Ctrl+P", or of any assigned key of my choice:

start
{
...
if ("Key event") function(x1,x2);
...
}

function(x1,x2)
{
...
Print("Hey it's Saturday for goodness sake");
...
}

Is there such a possibility in mql?

Thanks for your help and all your tutorials/tips!

pipeline
pipeline,

This is very good idea! Let me check how could it be done! (of course as c++ dll).
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #3 (permalink)  
Old 09-23-2006, 04:28 PM
codersguru's Avatar
Senior Member
 
Join Date: Oct 2005
Posts: 994
codersguru has a spectacular aura aboutcodersguru has a spectacular aura aboutcodersguru has a spectacular aura about
Thumbs up Get keyboard keys to MetaTrader!

Hi !

Done sir!

Please give this article a look:

http://www.metatrader.info/node/167
__________________
Hope it helps !
Coders' Guru
Senior MQL programmer:
www.xpworx.com/custom.htm
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #4 (permalink)  
Old 10-19-2006, 12:07 PM
Junior Member
 
Join Date: Oct 2006
Posts: 20
Ogeima is on a distinguished road
Quote:
Originally Posted by codersguru
Hi !

Done sir!

Please give this article a look:

http://www.metatrader.info/node/167
Hi Codersguru,

it's pipeline (now I use the nickname 'Ogeima' so that I have the same nickname on forex-tsd and strategybuilderfx).

Yes, I had looked at your "Get keyboard keys to metatrader" tool already, but I couldn't make it work.

Here's what I did, could you tell me if anything 's wrong?


In the include directory: Keyboard.mqh file:
------------------------------------------
#import "Keyboard.mq4"

int Keyboard();
------------------------------------------
(Note: it didn't work either when I typed "Keyboard.ex4" instead of "Keyboard.mq4" The error was:
2006.10.19 12:58:12 Error reading file 'C:\Program Files\PFG FX Trader\experts\libraries\Keyboard.ex4'
2006.10.19 12:58:12 Cannot open file 'C:\Program Files\PFG FX Trader\experts\Keyboard.ex4' on the GBPUSD,M15)



In the Library directory: Keyboard.mq4 file:
-----------------------------------------
#import "user32.dll"
bool GetAsyncKeyState(int nVirtKey);
#import

#define KEYEVENTF_EXTENDEDKEY 0x0001
#define KEYEVENTF_KEYUP 0x0002

#define VK_0 48
#define VK_1 49
#define VK_2 50
#define VK_3 51
#define VK_4 52
#define VK_5 53
#define VK_6 54
#define VK_7 55
#define VK_8 56
#define VK_9 57
#define VK_A 65
#define VK_B 66
#define VK_C 67
#define VK_D 68
#define VK_E 69
#define VK_F 70
#define VK_G 71
#define VK_H 72
#define VK_I 73
#define VK_J 74
#define VK_K 75
#define VK_L 76
#define VK_M 77
#define VK_N 78
#define VK_O 79
#define VK_P 80
#define VK_Q 81
#define VK_R 82
#define VK_S 83
#define VK_T 84
#define VK_U 85
#define VK_V 86
#define VK_W 87
#define VK_X 88
#define VK_Y 89
#define VK_Z 90

#define VK_LBUTTON 1 //Left mouse button
#define VK_RBUTTON 2 //Right mouse button
#define VK_CANCEL 3 //Control-break processing
#define VK_MBUTTON 4 //Middle mouse button (three-button mouse)
#define VK_BACK 8 //BACKSPACE key
#define VK_TAB 9 //TAB key
#define VK_CLEAR 12 //CLEAR key
#define VK_RETURN 13 //ENTER key
#define VK_SHIFT 16 //SHIFT key
#define VK_CONTROL 17 //CTRL key
#define VK_MENU 18 //ALT key
#define VK_PAUSE 19 //PAUSE key
#define VK_CAPITAL 20 //CAPS LOCK key
#define VK_ESCAPE 27 //ESC key
#define VK_SPACE 32 //SPACEBAR
#define VK_PRIOR 33 //PAGE UP key
#define VK_NEXT 34 //PAGE DOWN key
#define VK_END 35 //END key
#define VK_HOME 36 //HOME key
#define VK_LEFT 37 //LEFT ARROW key
#define VK_UP 38 //UP ARROW key
#define VK_RIGHT 39 //RIGHT ARROW key
#define VK_DOWN 40 //DOWN ARROW key
#define VK_PRINT 42 //PRINT key
#define VK_SNAPSHOT 44 //PRINT SCREEN key
#define VK_INSERT 45 //INS key
#define VK_DELETE 46 //DEL key
#define VK_HELP 47 //HELP key
#define VK_LWIN 91 //Left Windows key (Microsoft® Natural® keyboard)
#define VK_RWIN 92 //Right Windows key (Natural keyboard)
#define VK_APPS 93 //Applications key (Natural keyboard)
#define VK_SLEEP 95 //Computer Sleep key
#define VK_NUMPAD0 96 //Numeric keypad 0 key
#define VK_NUMPAD1 97 //Numeric keypad 1 key
#define VK_NUMPAD2 98 //Numeric keypad 2 key
#define VK_NUMPAD3 99 //Numeric keypad 3 key
#define VK_NUMPAD4 100 //Numeric keypad 4 key
#define VK_NUMPAD5 101 //Numeric keypad 5 key
#define VK_NUMPAD6 102 //Numeric keypad 6 key
#define VK_NUMPAD7 103 //Numeric keypad 7 key
#define VK_NUMPAD8 104 //Numeric keypad 8 key
#define VK_NUMPAD9 105 //Numeric keypad 9 key
#define VK_MULTIPLY 106 //Multiply key
#define VK_ADD 107 //Add key
#define VK_SEPARATOR 108 //Separator key
#define VK_SUBTRACT 109 //Subtract key
#define VK_DECIMAL 110 //Decimal key
#define VK_DIVIDE 111 //Divide key
#define VK_F1 112 //F1 key
#define VK_F2 113 //F2 key
#define VK_F3 114 //F3 key
#define VK_F4 115 //F4 key
#define VK_F5 116 //F5 key
#define VK_F6 117 //F6 key
#define VK_F7 118 //F7 key
#define VK_F8 119 //F8 key
#define VK_F9 120 //F9 key
#define VK_F10 121 //F10 key
#define VK_F11 122 //F11 key
#define VK_F12 123 //F12 key
#define VK_F13 124 //F13 key
#define VK_NUMLOCK 144 //NUM LOCK key
#define VK_SCROLL 145 //SCROLL LOCK key
#define VK_LSHIFT 160 //Left SHIFT key
#define VK_RSHIFT 161 //Right SHIFT key
#define VK_LCONTROL 162 //Left CONTROL key
#define VK_RCONTROL 163 //Right CONTROL key
#define VK_LMENU 164 //Left MENU key
#define VK_RMENU 165 //Right MENU key

int Keyboard()
{
if (GetAsyncKeyState(VK_LCONTROL) && GetAsyncKeyState(VK_B))
{
Alert ("The 'Ctrl+B' keys have been pressed");
return(1);
}
return(0);
}
-----------------------------------------

In my main program:
-------------------

#include <WinUser32.mqh>
#include <Keyboard.mqh>
...

int start
{
int answer;
...

answer = Keyboard();
if(answer == 1) Alert("Keyboard event detected");
}
-------------------

When I attach my main program to a chart, it attaches successfully, gets initialized, then says 'cannot load library "Keyboard.mq4" (error 126)' and stops.

My question is: what is error 126? What do I do wrong?

Thanks for your precious help!

Ogeima.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #5 (permalink)  
Old 03-28-2008, 09:19 AM
Junior Member
 
Join Date: Mar 2008
Posts: 1
metalorn is on a distinguished road
keyboard input

Is there a function to get user input from the keyboard? I'm just testing entry orders where the user enters the price and the script adds or substracts N number of pips for the stop loss and take profit values.

Thank you.

Metalorn.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #6 (permalink)  
Old 03-28-2008, 09:40 AM
Administrator
 
Join Date: Sep 2005
Posts: 20,017
Blog Entries: 235
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
I moved your post to this thread.
The other 2 threads related to this subject:
Hotkeys for Buy and Sell
Secrets of Meta-Trader
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #7 (permalink)  
Old 07-04-2008, 11:01 AM
Junior Member
 
Join Date: Jun 2008
Posts: 3
samuelb is on a distinguished road
Close all positions by a single keystroke?

Hi guys

I'm a newbie. I have a question, is there any scripts or tools that allow me to close all my open positions only by a single keyboard stroke?

I've try to browse threads on elite section buy i dont find any tools. Thank you for your help. I really appreciate it.

best regards

sam
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #8 (permalink)  
Old 07-04-2008, 12:26 PM
Administrator
 
Join Date: Sep 2005
Posts: 20,017
Blog Entries: 235
newdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud ofnewdigital has much to be proud of
I am not sure that I understand ...
but also look at this thread Secrets of Meta-Trader

And there is scripts and fulle explanation for that on this thread Hotkeys for Buy and Sell
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #9 (permalink)  
Old 02-14-2009, 09:03 AM
Junior Member
 
Join Date: Apr 2007
Posts: 7
pips4life is on a distinguished road
A challenge to capture mouse-position in a hotkeyed script

Hi MT4 programming experts,

Over on the MQL4 web site, several people have asked if they could capture keyboard or mouse clicks from within a program. The typical answer is no, and yet I've seen some very clever applications that use a DLL to capture or emulate keyboard events. What I want to do is capture a mouse event, for which I have found no useful MQL4 examples.

What am I trying to accomplish? I want to define hotkeys to save me some keystrokes. It's especially of interest to me because I have a Logitech G11 programmable keyboard with 18 extra buttons on the left. It sure would be nice to be able to program those readily accessible keys to create customized objects.

For example, I want to mark up my charts with Elliott Wave counts and while I can press the Text button (same as Insert->Text) to create a text, I always have to edit the Description so it says "1", and the next one "2", etc.

I wrote a simple script which can create a text object. It works, but only if you drag-and-drop the script from the Navigator window onto the chart. It makes use of the "WindowPriceOnDropped" and "WindowTimeOnDropped" functions which are specifically for this purpose.

Next, I defined a hotkey to run my script. (I used Cntl-W since it wasn't already used).

When I press "Cntl-W", sure it runs my script, but the Time/Price values are both zero because I did not use the drag-and-drop method.

I want to capture the mouse position and have those coordinates be used by the MT4 functions, so...

I saw mention of the "mouse_event" function within the WinUser32.mqh library that comes with MT4. I think I figured out how to press and release the left button but it does not help, because the WindowPriceOnDropped function ignores it. Obviously it wasn't a drag-and-drop of this script onto a chart but I was hoping to get lucky.

Here's my attempt at the code (which works to create a text object with drag-and-drop, but does not work when using a hotkey):

Code:
#property copyright "Copyright © 2009, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#include <WinUser32.mqh>
//void     mouse_event(int dwFlags,int& dx,int& dy,int dwData,int dwExtraInfo);
//#define MOUSEEVENTF_LEFTDOWN           0x0002 // left button down
//#define MOUSEEVENTF_LEFTUP             0x0004 // left button up


//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----
  GetFocus();
  mouse_event(2,0,0,0,0);
  Sleep(10); // milliseconds
  mouse_event(4,0,0,0,0);
  double price = WindowPriceOnDropped();
  datetime time = WindowTimeOnDropped();
  Print("Price at drop: ",NormalizeDouble(price,2));
  
  if (price == 0 || time == 0) return(1); // If price and/or time is 0, it failed so exit early
  
  ObjectDelete("Text1");
  ObjectCreate("Text1",OBJ_TEXT,0,time,price);
  ObjectSetText("Text1","Hello",18,"Arial",Red);
//----
   return(0);
  }
//+------------------------------------------------------------------+
A picture is attached. The Experts log will print the correct price if it works.


Thanks in advance for any help trying to solve this problem!
Pips4life

P.S. Some links I found when searching for clues might be helpful:
WinUser32.mqh - MQL4 Code Base (WinUser32.mqh info)
mouse_event Function () (mouse_event doc)
Breakpoints in Tester: It's Possible! - MQL4 Articles (Breakpoints in Tester)
ind_HotKeys_v1.mq4 - MQL4 Code Base (A keybd_event simple example)
Attached Images
File Type: jpg test hotkey.jpg (90.8 KB, 577 views)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
  #10 (permalink)  
Old 02-14-2009, 04:05 PM
Junior Member
 
Join Date: Apr 2007
Posts: 7
pips4life is on a distinguished road
Re: A challenge to capture mouse-position in a hotkeyed script

Quote:
Originally Posted by pips4life View Post
Hi MT4 programming experts,

Over on the MQL4 web site, several people have asked if they could capture keyboard or mouse clicks from within a program. The typical answer is no, and yet I've seen some very clever applications that use a DLL to capture or emulate keyboard events. What I want to do is capture a mouse event, for which I have found no useful MQL4 examples.

...
I assume Newdigital moved my post into this thread... however, I have followed all of the links here and none of them solve my problem.

I need a program to capture a mouse event, not a keyboard event. The two are very different. A keyboard event can be captured to run something as it relates in general to your current chart, such as to open a Buy/Sell at market price. In contrast, a mouse event (i.e. left-mouse click) -- if this problem can be solved -- can capture a specific time & price on your current chart!

Native MT4 commands can do this with ease of course. You can execute a menu command or push an icon, and the program then prompts you to left-mouse-click on whatever spot on your chart you want for your command. I'm looking for a way that I can access this mouse control from within a script (or perhaps by an EA as well).

Still looking for a solution... anyone have any ideas?

Thanks in advance,
Pips4life
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!StumbleUpon this Post!Reddit this Post!Facebook this Post!BlinkList this Post!Google Bookmarks this Post!Yahoo! My Web this Post!
Reply With Quote
Reply

Bookmarks

Tags
scalping

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Send Email On Pre Set Time not Working, event is not firing ! icm63 Metatrader 4 2 03-26-2007 08:55 AM
Event driven programming cardio Setup Questions 1 03-25-2006 02:33 PM


All times are GMT. The time now is 03:49 AM.



Search Engine Friendly URLs by vBSEO 3.2.0 ©2008, Crawlability, Inc.