
- www.mql5.com
Maybe I didn't explain my problem in detail.
CHART_WIDTH_IN_BARS only works for the current chart size. My chart width is currently 1482 pixels and by using ChartGetInteger(0,CHART_WIDTH_IN_BARS) I get the number of bars for a chart width of 1482 pixels. But I need to know how many candles this chart would have if it was 800 pixels wide. Unfortunately I can't resize the chart to 800 pixels width. Then it would be working.
Yes, that is what one can use to calculate an approximate value. if one knows the pixel width of the current visual chart and the number of bars it has, then we can calculate the approximate number of bars of another chart with a different pixel width.
In won't be an exact match, but it will be an approximation because of the price scale on the right which one does not factor into the calculation.// Pseudo code screenshot_bars = {CHART_WIDTH_IN_BARS} * screenshot_width_pixels / {CHART_WIDTH_IN_PIXELS}
Maybe I didn't explain my problem in detail.
CHART_WIDTH_IN_BARS only works for the current chart size. My chart width is currently 1482 pixels and by using ChartGetInteger(0,CHART_WIDTH_IN_BARS) I get the number of bars for a chart width of 1482 pixels. But I need to know how many candles this chart would have if it was 800 pixels wide. Unfortunately I can't resize the chart to 800 pixels width. Then it would be working.
If you get 1482 pixels using CHART_WIDTH_IN_PIXELS, it does not include the price and time scales. If you use this size in ChartScreenshot you will get a screenshot that does not match you see on your screen. If you want the correct size do this:
//+------------------------------------------------------------------+ //| Script program start function | //+------------------------------------------------------------------+ void OnStart() { //--- ulong chart = ChartID(); //--- size of the screenshot ChartSetInteger(chart, CHART_SHOW, false); int full_width = ChartGetInteger(chart, CHART_WIDTH_IN_PIXELS); int full_height = ChartGetInteger(chart, CHART_HEIGHT_IN_PIXELS); //--- size of the main window, not includng scales ChartSetInteger(chart, CHART_SHOW, true); int width = ChartGetInteger(chart, CHART_WIDTH_IN_PIXELS); int height = ChartGetInteger(chart, CHART_HEIGHT_IN_PIXELS); //--- price scale width int price_scale_width = full_width - width; //--- estimate size for a different screenshot size int desired_width = 800; int desired_height = full_height * double(desired_width) / full_width; int resulting_width = desired_width - price_scale_width; //--- the bars may be shift from the right border int right_offset = 0; if(ChartGetInteger(chart, CHART_SHIFT) != 0) right_offset = resulting_width * ChartGetDouble(chart, CHART_SHIFT_SIZE) / 100.0; //--- number of bars on the screenshot (considering the chart is not scrolled) int bar_width = pow(2, ChartGetInteger(chart, CHART_SCALE)); int half_bar_width = bar_width / 2;// only half of the first bar (from left to right) is visible int bars = (resulting_width - right_offset + half_bar_width) / bar_width; } //+------------------------------------------------------------------+
Thank you guys,
I found out that the price scale is exactly 81 pixels wide. I take this into consideration.
I need the correct amount of candles for one reason. When a screenshot is made I want to add some space to the top and bottom of the chart because it's more pleasant to look at a chart which is not touching the upper and lower frame. I need the exact high and low of all candles in the screenshot because I use SCALE_FIX before I make the screenshot.
Metatrader should really get an update with useful functions which are all standard on other charting platforms...
Be careful! That may be the case only for a 100% Windows display scale/zoom on a normal Full HD display. It may be very different on a 4K or 8K display or when the Windows scale/zoom ratio is no longer 100%.
I also have no idea how the Windows scale/zoom ratio and the display's resolution affects how screenshots are generated.
You may need to take into consideration the following client terminal property ...
TERMINAL_SCREEN_DPI
The resolution of information display on the screen is measured as number of Dots in a line per Inch (DPI).
Knowing the parameter value, you can set the size of graphical objects so that they look the same on monitors with different resolution characteristics.
int

- www.mql5.com
Thank you guys,
I found out that the price scale is exactly 81 pixels wide. I take this into consideration.
I need the correct amount of candles for one reason. When a screenshot is made I want to add some space to the top and bottom of the chart because it's more pleasant to look at a chart which is not touching the upper and lower frame. I need the exact high and low of all candles in the screenshot because I use SCALE_FIX before I make the screenshot.
Metatrader should really get an update with useful functions which are all standard on other charting platforms...
81 pixels for the current chart that you are working. This is different for different charts based on the scale values. For example the scale width for chart with scale values from 140 to 170 will be different from a chart values from 999.05140 to 999.05200. Even on same symbol, at some point the values range from 5.10 to 9.90, then in next day price goes above 10.00 then scale width will increase a little bit.

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hey guys,
is it somehow possible to find out how many candles are shown on a 800x600 screenshot before the screenshot is made? I know there are some variables like the chart shift and the chart scale. But I have no idea how to find out the number of candles before the screenshot is made. Any help is very appreciated.