Download MetaTrader 5

Libraries: Capture MouseEvents on Chart

To add comments, please log in or register
MetaQuotes Software Corp.
MetaQuotes Software Corp.  

Capture MouseEvents on Chart:

This set of functions enables one to capture mouse events on your trading chart. One can simmulate buttons to trigger actions in the EA.

Author: Russell

MQL4 Comments
MQL4 Comments  
This is something I looked for a very long time. Thank you for sharing.

Nice, its a very good program, but I see a little bug: When I cklick somewhere in the chart, outside of the button!! and then I draw the mousepointer on the button (without click! on the button) then is triggered the message "right away!" Thats wrong! The message should appear only after click on the button! Where is the solution that this message appears only! after click the button!?

Nice day!


Bambang Sugianto
Bambang Sugianto  

 Hello.. thanks to the   Author:   Russell

i've been looking for this  function for so long 

i've try to modify the code.. this is a simple EA that i create.

but there is 1 problem..  the button still executed even the MT4 window is in background.

as example..when i browsing.. suddenly  the button is working if  i click the right cordinates   


//|                                                    mousetest.mq4 |
//|                                Copyright © 2008, Berkers Trading |
//|                               |
#property copyright "Copyright © 2008, Berkers Trading"
#property link      ""
#include <WinUser32.mqh> //adjusted!!
#include <cfunctions_v1.0.1.mqh>
#import "user32.dll"
#define VK_LBUTTON   0x01 //Left mouse button
#define VK_RBUTTON   0x02 //Right mouse button
int init(){
int deinit(){ ObjectDelete("t"); 
int start()
   int iCoords[2], iCoordsPrevious[2],hWin,liKS;
   static double ldBid, ldPollTime;
   int liTC, liCompareTime;
     bool clicked=0;  bool ok;
   Print("Start Polling Mouse");
        Comment(" x = "+iCoords[0] +" \n y ="+iCoords[1] );
    ObjectCreate("t", OBJ_LABEL, 0, 0,0); 
    ObjectSet("t", OBJPROP_CORNER,4);
    ObjectSet("t", OBJPROP_XDISTANCE ,200);
    ObjectSet("t", OBJPROP_YDISTANCE ,60);
    ObjectSet("t", OBJPROP_BACK ,0);     
    ObjectSetText("t","g" ,10,"Webdings",Red);
         hWin = WindowHandle( Symbol(), Period()); 
         MT4_ScreenToClient(hWin, iCoords);    
         string sym="";
         if ( !clicked && iCoords[0] > 200 && iCoords[0] < 215 && iCoords[1] > 60 && iCoords[1] < 75 ) 
         {ok=1; sym=Symbol();  ObjectSetText("t","g" ,10,"Webdings",Yellow);   } 
             if(ok &&GetAsyncKeyState(VK_RBUTTON)>0||GetAsyncKeyState(VK_LBUTTON)>0)   
               {PlaySound("ok.wav"); Sleep (100);   
                if( GetAsyncKeyState(VK_RBUTTON)>0||GetAsyncKeyState(VK_LBUTTON)>0) clicked=1; else clicked=0;   


Rudi Susanto
Rudi Susanto  

Very Interested, but I have an error at this line

liKS = GetAsyncKeyState(VK_LBUTTON);

(function not defined)

To add comments, please log in or register