Chart horizontal grid line values? - page 2

 
kypa:

Squares are in pixels. You may get size of chart in pixels, divide by pixels in a square thus getting a number of squares then divide price max minus price min to number of squares and start building grid from the middle.

But there is no point, this grid is just for orientation, it doesn't mean anything and it changes every time the chart is rescaled or resized.

Problem is size of squares changes all the time so can never be 100 per cent accurate with this method unless we can find out how it changes the squares/exact in built formula for calculations or something like that that can predict the square sizes/ amount/positioning of these "squares" exactly
 
whroeder1:

Only if the size of the chart is 10 * grid size in pixels. Change the chart size, grid size does not change.



Main Chart YScale values do change in position (visually, literally from one spot of monitor to other as "squares" change sizes) on my MT4 as ticks come in. Thought I had solution, I don't.


Maybe I'm not being clear. All I need is the Y Axis values of the main chart in current view.

 
nadiawicket: Maybe I'm not being clear. All I need is the Y Axis values of the main chart in current view.

Those are grid values. You can't get them. Ignore the grid.

 
nadiawicket:All I need is the Y Axis values of the main chart in current view.

 I strongly believe you don't need even those.

Right click on chart / Properties, set Fixed Scale true, then try dragging the chart up and down and see what happens with grid values. Or click on price scale and move mouse up and down (while holding the left key pressed).

 
whroeder1:

Those are grid values. You can't get them. Ignore the grid.

OK thx!!

 
kypa:

 I strongly believe you don't need even those.

Right click on chart / Properties, set Fixed Scale true, then try dragging the chart up and down and see what happens with grid values. Or click on price scale and move mouse up and down (while holding the left key pressed).

OK thanks!
 

@kypa:


Greate insight in grid comment.

I encoutered one problem about how to caucluate the  pixels in a square as in “

Squares are in pixels. You may get size of chart in pixels, divide by pixels in a square thus getting a number of squares then divide price max minus price min to number of squares and start building grid from the middle.”


please avdise, thanks.

Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Properties
Documentation on MQL5: Constants, Enumerations and Structures / Objects Constants / Object Properties
  • www.mql5.com
Object Properties - Objects Constants - Constants, Enumerations and Structures - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Hi, if there's still interest in this thread, I have now found a way to calculate it. Basically you need to count how many vertical grid squares in the chart. In mine, there are 15.8 squares (15 same-sized squares plus 0.8 which is at the very top that's less than the normal size) - try to calculate the number of squares as accurately as possible using this method:

1. calculate price gap covered in each square using the scale shown, for example the top full-sized square has lower scale = 4470.12 and upper scale = 4472.39 (yellow arrows) so price gap for each square is 2.27

2. price_max variable in the below code shows 4474.22 and the highest scale shown in the chart is 4472.39 so the gap between top price in the chart and first full-sized square is 4474.22 - 4472.39 = 1.83

3. divide the value from #2 to the value from #1 to get the last grid square size relative to the standard size = 1.83 / 2.27 = 0.8

So there are 15.8 grid squares in the chart.

The range between price_max and price_min when divided by 15.8 will give the price range per square. Good luck!

   long   chart_id = ChartID();
   double price_max = ChartGetDouble(chart_id, CHART_PRICE_MAX);
   double price_min = ChartGetDouble(chart_id, CHART_PRICE_MIN);

   double price_range_in_chart = price_max - price_min;
   
   //there are 15.8 vertical grid boxes in the chart 
   double price_per_vertical_grid_box = price_range_in_chart / 15.8;
   
   Print("price_max, price_min, price_range_in_chart, price_per_vertical_grid_box ", 
               chart_id, " ", price_max, " ", 
               price_min, " ", 
               price_range_in_chart, " ", 
               price_per_vertical_grid_box);