- Functions for getting the basic properties of the current chart
- Chart identification
- Getting the list of charts
- Getting the symbol and timeframe of an arbitrary chart
- Overview of functions for working with the complete set of properties
- Descriptive chart properties
- Checking the status of the main window
- Getting the number and visibility of windows/subwindows
- Chart display modes
- Managing the visibility of chart elements
- Horizontal shifts
- Horizontal scale (by time)
- Vertical scale (by price and indicator readings)
- Colors
- Mouse and keyboard control
- Undocking chart window
- Getting MQL program drop coordinates on a chart
- Translation of screen coordinates to time/price and vice versa
- Scrolling charts along the time axis
- Chart redraw request
- Switching symbol and timeframe
- Managing indicators on the chart
- Opening and closing charts
- Working with tpl chart templates
- Saving a chart image
Vertical scale (by price and indicator readings)
Properties related to the vertical scale are set and parsed using the elements of two enumerations: ENUM_CHART_PROPERTY_INTEGER and ENUM_CHART_PROPERTY_DOUBLE. In the following table, the properties are listed along with their value type.
Some properties allow you to access not only the main window but also a subwindow, for which ChartSet and ChartGet functions should use the parameter window (0 means the main window and is the default value for the short form of ChartGet).
Identifier |
Description |
Value type |
---|---|---|
CHART_SCALEFIX |
Fixed scale mode |
bool |
CHART_FIXED_MAX |
Fixed maximum of the window subwindow or the initial maximum of the main window |
double |
CHART_FIXED_MIN |
Fixed minimum of the window subwindow or the initial minimum of the main window |
double |
CHART_SCALEFIX_11 |
Scale mode 1:1 |
bool |
CHART_SCALE_PT_PER_BAR |
Scale indication mode in points per bar |
bool |
CHART_POINTS_PER_BAR |
Scale value in points per bar |
double |
CHART_PRICE_MIN |
Minimum values in the window window or subwindow (r/o) |
double |
CHART_PRICE_MAX |
Maximum values in the window window or subwindow (r/o) |
double |
CHART_HEIGHT_IN_PIXELS |
Fixed height of window or subwindow in pixels, window parameter required |
int |
CHART_WINDOW_YDISTANCE |
Distance in pixels along the vertical Y-axis between the top frame of the window subwindow and the upper frame of the main chart window. (r/o) |
int |
By default, charts support adaptive scale so that quotes or indicator lines fit completely vertically on a visible time period. For some applications, it is desirable to fix the scale, for which the terminal offers several modes. In them, the chart can be scrolled with the mouse or with the keys (Shift + arrow) not only left/right, but also up/down, and a slider bar appears at the right scale, using which you can quickly scroll the chart with the mouse.
The fixed mode is set by turning on the CHART_SCALEFIX flag and specifying the required maximum and minimum in the CHART_FIXED_MAX and CHART_FIXED_MIN fields (in the main window, the user will be able to move the chart up or down, due to which the CHART_FIXED_MAX and CHART_FIXED_MIN values will change synchronously, but the vertical scale will remain the same). The user will also be able to change the vertical scale by pressing the mouse button on the price scale and, without releasing it, moving it up or down. Subwindows do not provide interactive editing of the vertical scale. In this regard, we will later present an indicator SubScaler.mq5 (see keyboard events section), which will allow the user to control the range of values in the subwindow using the keyboard, rather than from the settings dialog, using the fields on the Scale tab.
The CHART_SCALEFIX_11 mode provides an approximate visual equality of the sides of the square on the screen: X bars in pixels (horizontally) will be equal to X points in pixels (vertically). The equality is approximate, because the size of the pixels, as a rule, is not the same vertically and horizontally.
Finally, there is a mode for fixing the ratio of the number of points per bar, which is enabled by the CHART_SCALE_PT_PER_BAR option, and the required ratio itself is set using the CHART_POINTS_PER_BAR property. Unlike the CHART_SCALEFIX mode, the user will not be able to interactively change the scale with the mouse on the chart. In this mode, a horizontal distance of one bar will be displayed on the screen in the same ratio to the specified number of vertical points as the aspect ratio of the chart (in pixels). If the timeframes and sizes of the two charts are equal, one will look compressed in price compared to the other according to the ratio of their CHART_POINTS_PER_BAR values. Obviously, the smaller the timeframe, the smaller the range of bars, and therefore, with the same scale, small timeframes look more "flattened".
Programmatically setting the CHART_HEIGHT_IN_PIXELS property makes it impossible for the user to edit the window/subwindow size. This is often used for windows that host trading panels with a predefined set of controls (buttons, input fields, etc.). In order to remove the fixation of the size, set the value of the property to -1.
The CHART_WINDOW_YDISTANCE value is required to convert the absolute coordinates of the main chart into local coordinates of the subwindow for correct work with graphical objects. The point is that when mouse events occur, cursor coordinates are transferred relative to the main chart window, while the coordinates of graphical objects in the indicator subwindow are set relative to the upper left corner of the subwindow.
Let's prepare the ChartScalePrice.mq5 script for analyzing changes in vertical scales and sizes.
void OnStart()
|
It reacts to chart manipulation in the following way:
Initial state:
|