Use the OnChartEvent() handler to detect Mouse or Keyboard events and then Create or Move Chart Objects as you wish:
What cursor? If you are talking about shifting the chart left or right, then use the ChartNavigate() function.
nikolaygmt: instead of using my mouse to press the buttons from the line studies - I want to press a key and come to the same result after pressing the button ->
| Why? after you press the button you still have to use the mouse to place the object. |
@FMIC, the mouse cursor. Notice that when you press the button, the mouse cursor changes. This is what I want because this gives a visual clue to the user what will happen if he left clicks. Basically I want: 1) press a defined key 2) mouse cursor changes the same as the desired button 3) If the user left clicks and holds without releasing the mouse, then the line works the same way as pressing the button 4) on release the line is created. So pressing the key should trigger exactly the same results as pressing the button.
@WHRoeder, because of:
- speed of execution - if I use my right hand on the mouse and my left hand on the keyboard, I can place a line more quickly by a) pressing a key while moving the cursor to my desired position and finally left clicking to create the line than b) moving the cursor to the button (needs first conginitive recongition/filtration where the button is and time to move the cursor to the button), then moving the cursor to the desired position and left clicking. It is one step quicker.
- easy - basically the user watches the chart and wants to place a line, so the most intuitive way would be if the line is placed as easily and as quickly as possible without the attention of the user to be spent with other thoughts and visual observations.
but isn't there a way to program clicking the button? or MT4 API that I can call? I need on keypress to trigger the same results as clicking the button.
As far as I know, there are no hot-keys for the Chart Objects such as Horizontal and Vertical lines which are usually "activated" by selecting the icons in the Toolbar or via the menu selection.
There are however ways to use Win32 functions to call the menu options provided they don't change much between builds. Unfortunately, I have never done that. Maybe someone else here has more experience calling the menu options this way.
There are no hot keys, but you sending a post message should work to simulate a button click.
#define MT4_WMCMD_HLINE 33244 /* horizontal line */ #define MT4_WMCMD_TRENDLINE 33257 /* trend line */ #define MT4_WMCMD_VLINE 33260 /* Vertical Line */ #include <WinUser32.mqh> // SendMessageA/PostMessageA/WM_COMMAND #import "user32.dll" int GetAncestor(int, int); // instead of four GetParent calls. #import #define GA_ROOT 2 int main = GetAncestor(WindowHandle(_Symbol, _Period), GA_ROOT); PostMessageA(main, WM_COMMAND, MT4_WMCMD_VLINE, 0);Untested.
/* PauseTest // http://forum.mql4.com/35112 // Each chart consists of two windows (i.e. two hWnds): the drawing area (WH,) // and a container (GA.) There is then a standard MDI container which holds all // the chart windows (GA1.) And that sits inside the main MT4 window (GA2.) */ #include <WinUser32.mqh> // SendMessageA/PostMessageA/WM_COMMAND #import "user32.dll" int GetAncestor(int, int); // instead of four GetParent calls. #import void pause_visual_mode(){ if(get_modus_operandi() == MODE_VISUAL && IsDllsAllowed() ){ datetime now = TimeCurrent(); static datetime oncePerTick; if(oncePerTick != now){ oncePerTick = now; #define GA_ROOT 2 int main = GetAncestor(WindowHandle(_Symbol, _Period), GA_ROOT); SendMessageA(main, WM_COMMAND, 0x57a, 0); // 1402. Pause } } } void enable_all_history(){ // #define GA_ROOT 2 // http://forum.mql4.com/ru/14463/page5#401551 #define MT4_WMCMD_ALL_HISTORY 33058 int main = GetAncestor(WindowHandle(Symbol(), Period()), GA_ROOT); PostMessageA(main, WM_COMMAND, MT4_WMCMD_ALL_HISTORY, 0); }Reference
- #define's for known commands that can be used for PostMessageA() (Arnd) - MQL4 forum
- strategy tester mt4, is a automatic paus function possible? (Matthias) - MQL4 forum
- research по теме кодов к PostMessageA (Mikhail Chistyakov) - MQL4 форум
- Fastest way to change profiles? (Adolph Kavorkian) - MQL4 forum
@WHRoeder :))))))))) it works!!! I feel so relieved that finally I can speed up lines creation :))) Thank you very much!
What are the values for the other buttons (all shapes, all arrows, cursor and crosshair)? Are they documented somewhere? Similar to MT4_WMCMD_HLINE 33244.
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everyone,
instead of using my mouse to press the buttons from the line studies - horizontal/vertical line, trendline, etc - I want to press a key and come to the same result after pressing the button ->
The ideas is to speed up the process of creating lines by using keys presses/shortcuts.
Do you know how can I program the pressing of such a button?
My current thoughts: