Download MetaTrader 5

Zoom state/level

To add comments, please log in or register
Download MetaTrader 5 and start trading today!
Sean
17
Sean 2013.06.05 16:05 

Hello all,

This question has been asked a number of times in a number of ways by various people, with a conspicuous absence of answers. So I'll put it clearly in the hopes of getting an answer myself.

Consider: In order to set the width of histogram bars in a custom indicator in a separate window, such that the width of the bars (in pixels) change properly with the zoom state of the window, it is necessary to know the zoom state of the window. Now... for all those about to jump in with "solutions" involving WindowBarsPerChart() and Period() etc... go away and think about it! It cannot be done without knowing the zoom state of the window.

[More specifically... take two identical windows. Zoom one window out one click. Then stretch the other window so that it is twice as wide as it was. You now have two windows with the same number of bars in each and the same period. However, the bars in one window are twice as thick (in pixels) as the bars in the other window. (ref. attached file)]

The thickness of the bars in the main window double/half with every click of the zoom button. Wanting your histogram bars in your custom indicator to do the same, is a pretty basic expectation.

So the question is: Is there a way of retrieving the zoom state of a window in an EA/indicator/script program?

I (and I guess everyone else who has asked this question up to now) would like a clear, concise and authoritative answer to this from someone suitably knowledgeable.

Thank you very much in advance to anyone willing to spend the time to answer this one.

Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2013.06.05 16:09  
bu06034:

Hello all,

This question has been asked a number of times in a number of ways by various people, with a conspicuous absence of answers. So I'll put it clearly in the hopes of getting an answer myself.

Consider: In order to set the width of histogram bars in a custom indicator in a separate window, such that the width of the bars (in pixels) change properly with the zoom state of the window, it is necessary to know the zoom state of the window. Now... for all those about to jump in with "solutions" involving WindowBarsPerChart() and Period() etc... go away and think about it! It cannot be done without knowing the zoom state of the window.

[More specifically... take two identical windows. Zoom one window out one click. Then stretch the other window so that it is twice as wide as it was. You now have two windows with the same number of bars in each and the same period. However, the bars in one window are twice as thick (in pixels) as the bars in the other window. (ref. attached file)]

The thickness of the bars in the main window double/half with every click of the zoom button. Wanting your histogram bars in your custom indicator to do the same, is a pretty basic expectation.

So the question is: Is there a way of retrieving the zoom state of a window in an EA/indicator/script program?

Yes there is,  you need to know the width of the window in pixels.   Then from the number of bars visible,  allowing for chart shift if applicable,  you can calculate the zoom.
Alain Verleyen
Moderator
30722
Alain Verleyen 2013.06.05 16:50  
RaptorUK:
Yes there is,  you need to know the width of the window in pixels.   Then from the number of bars visible,  allowing for chart shift if applicable,  you can calculate the zoom.


for all those about to jump in with "solutions" involving WindowBarsPerChart() and Period() etc... go away and think about it!

Rejected by advance by topic starter. You don't think enough about it.

Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2013.06.05 18:22  
angevoyageur:

Rejected by advance by topic starter. You don't think enough about it.

Nope . . .  you missed my inclusion of    " . .  you need to know the width of the window in pixels."  that makes the difference,  how do I know ?  I have coded it and it works      At different zoom levels the bars are different widths in pixels . . .  go away and think about it  

This may help:  https://www.mql5.com/en/forum/141388

Alain Verleyen
Moderator
30722
Alain Verleyen 2013.06.05 18:25  
RaptorUK:
Nope . . .  you missed my inclusion of    " . .  you need to know the width of the window in pixels."  that makes the difference,  how do I know ?  I have coded it and it works      At different zoom levels the bars are different widths in pixels . . .  go away and think about it  

And how do you know "the number of bars visible" if not with WindowBarsPerChart() ?
Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2013.06.05 18:35  
angevoyageur:
And how do you know "the number of bars visible" if not with WindowBarsPerChart() ?
No argument there,  it is with WindowsBarPerChart()  . . .   I assumed the OP would prefer a correct answer rather than me taking literally what was said . . .  I can delete my posts if you think it is what would be preferred ?
Alain Verleyen
Moderator
30722
Alain Verleyen 2013.06.05 21:11  
RaptorUK:
No argument there,  it is with WindowsBarPerChart()  . . .   I assumed the OP would prefer a correct answer rather than me taking literally what was said . . .  I can delete my posts if you think it is what would be preferred ?

Let the OP decide if what you proposed is an "authoritative answer".
Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2013.06.05 21:17  
angevoyageur:
Let the OP decide if what you proposed is an "authoritative answer".

OK,  you know what the next question will be though ?  how do I find the pixel width of the window ?

 

#import "user32.dll"
int GetWindowRect(int hWnd, int rect[4]); // Get window dimensions (x,y -> x,y)
#import


int SizeX = 1340;      // screen grab width  (pixels measured from left to right)
int SizeY = 700;       // screen grab height (pixels measured from top to bottom)

if (IsDllsAllowed()) 
   {
   GetWindowRect(WindowHandle(Symbol(), Period()), WindowDims);
   SizeX = WindowDims[2] - WindowDims[0];
   SizeY = WindowDims[3] - WindowDims[1];
   }
else Print("DLLs not allowed ! !");
Alain Verleyen
Moderator
30722
Alain Verleyen 2013.06.05 21:23  
RaptorUK:

OK,  you know what the next question will be though ?  how do I find the pixel width of the window ?

Is DLL allowed by the OP ?
Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2013.06.05 22:02  
angevoyageur:
Is DLL allowed by the OP ?
Never said,  maybe OP can do it without DLL  
Sean
17
Sean 2013.06.06 05:35  
RaptorUK:

OK,  you know what the next question will be though ?  how do I find the pixel width of the window ?

 

 


Thank  you very much for this answer. It allows me to do approximately what I want to do.

BTW: You were right... The next question would have been "How do I find the pixel width of the window?"


It seems that there is no function in mql4 itself which will yield the pixel per unit scale on the x or y-axis. The requirement seems to be to rely on a call to the user32.dll.

It should be noted that the answer generates the size of the window only and will not generate the length of the x axis (the numbers on the scale and the window borders take up some space). This is more of a problem when working with the y axis, where the presence of any indicator windows mean that the height of the y-axis in the main window bears little relation to the total pixel height of the window.

Does nobody see a problem with the failure of the MetaTrader Terminal to properly "stretch" indicator histogram bars with the zoom level, as it does with the bars in the main window? Surely this should happen automatically, or at least be a simple option in the function defining the histogram.

Anyway, I'll try to work with the solution you have kindly provided.

Thank you very much for taking the time.

12
To add comments, please log in or register