How to program pressing a button from the Line Studies (HL, VL, Trendline)?

 

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 ->

  1. the cursor has changed to the icon of the selected button and when I move the mouse this new cursor is visible.
  2. when I press the left mouse button, the line is drawn

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:

  • a) ObjectCreate() alone (or script with a hotkey) is not enough, because I want to see the corresponding cursor change, see 1).
  • b) Maybe I could use win32 functions, to trigger pressing "Alt+I+L" and then "V", "H", or "T" which would simulate the user selecting lines throught the menu. Not sure if programming it would work as intended.
 

Use the OnChartEvent() handler to detect Mouse or Keyboard events and then Create or Move Chart Objects as you wish:

https://docs.mql4.com/basis/function/events#onchartevent

 
Hi FMIC, I am aware that I can detect events and create objects, but how can I change the cursor? The changed cursor is the visual feedback for the user that by pressing the left mouse button the desired action will take please, different than the default cursor.
 

What cursor? If you are talking about shifting the chart left or right, then use the ChartNavigate() function.

https://docs.mql4.com/chart_operations/chartnavigate

 
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:

  1. 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.
  2. 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.
 
No, I don't know of any MQL4 functions to control the mouse cursor icon!
 
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.
 
nikolaygmt:
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.

UnTested.
#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.
I've only use these two
/*                                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
 

@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.

Reason: