Download MetaTrader 5
To add comments, please log in or register
Share your programs. That will improve your rating.
MetaQuotes Software Corp.
Moderator
177298
MetaQuotes Software Corp. 2009.01.05 07:22 

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
16309
MQL4 Comments 2010.04.02 13:01  
This is something I looked for a very long time. Thank you for sharing.
programmierer
74
programmierer 2010.12.15 00:11  

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!

traderdoc

Bambang Sugianto
9831
Bambang Sugianto 2013.01.01 02:31  

 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 |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, Berkers Trading"
#property link      "http://www.metaquotes.net"
#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(){
    
  start();
   return(0);
}
int deinit(){ ObjectDelete("t"); 
   return(0);
}
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");
  
   while(true)
   { 
        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);    
         ok=0;
         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);   
                  Alert(sym);
               }
                if( GetAsyncKeyState(VK_RBUTTON)>0||GetAsyncKeyState(VK_LBUTTON)>0) clicked=1; else clicked=0;   
               Sleep(100);  
             
         }
          
}

 

Rudi Susanto
314
Rudi Susanto 2014.12.21 05:00  

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