pixel coordinates to time/price coordinates

To add comments, please log in or register
Matthias De Paolis
490
Matthias De Paolis  

Hi,

I'm new to mql4 and I need some help: is possible convert pixel coordinates to time/price coordinates?

I'll do code for get mouse pointer coordinate at left mouse click, now, I'll want use that pixel coordinates to "select" a bar on my chart, but bars are only selected by time or index and I don't find a way to do this!

I've just test:

1) create a VLine to 0 time and 0 price, move to my pixel coodinates and read new time, but don't work the move by pixel coordinates

2) create a Label to my pixel coodinates and read Time1/ Price1, but time and price properties value on label aren't set.

2) generate a new drag and drop event on left mouse click to my coordinates and read TimeOnDropped() result, but don't work, because it save only pixel coordinates to script are initial dropped on chart

please help me!!!

Simon Gniadkowski
17205
Simon Gniadkowski  
Use WindowBarsPerChart PriceMax and PriceMin and you should be able to work out when and what price you are at.
Matthias De Paolis
490
Matthias De Paolis  

Hi RaptorUK,

thank's a lot for your answer!

But I don't understand very well how I can use that functions to calculate time and price from pixel coordinates?

I think to use that functions I need to know height and width of chart windows but I don't know. And if can calculate height and width (but I don't know how) for zoomed and traslated charts?

Simon Gniadkowski
17205
Simon Gniadkowski  

Try/Search on . . .

#import "user32.dll"
int GetWindowRect(int hWnd, int rect[4]); 
#import


.
.
.
.


if (IsDllsAllowed()) 
   {
   GetWindowRect(WindowHandle(Symbol(), Period()), WindowDims);
   size_x = WindowDims[2] - WindowDims[0];
   size_y = WindowDims[3] - WindowDims[1];
   }
   else Print("DLLs not allowed ! !");
Matthias De Paolis
490
Matthias De Paolis  

Thank's you si much RaptorUk,

That function return window chart dimension!

For price coordinate I use that formula:

pixelprice= (WindowPriceMax()-WindowPriceMin())/size_y;

selectedprice= WindowPriceMax() - (selected_y_pixel*pixelprice);

and with some little adjustement (remove from size_y the pixel height of board) it's precise enough.

But for time coordiante I can't understand how I can determine selected time using WindowBarsPerChart and size_x. There's the translation of chart and zoom to consider. I do some test but the result is not acceptable :-( Have you just resolv this problem??

Simon Gniadkowski
17205
Simon Gniadkowski  
dema:

Have you just resolv this problem??

Nope . . . try a few things find what works . . . get creative and imaginative.
Matthias De Paolis
490
Matthias De Paolis  

...well, so I'll continue with my experiment.

If I'll find something good I'll post it here!

Thank's

Matthias De Paolis
490
Matthias De Paolis  

I'm happy to report that I found the solution to my problem!! I use 2 line for calculate the pixel/time-price conversion

Simon Gniadkowski
17205
Simon Gniadkowski  
Well done :-)
To add comments, please log in or register