- 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
Colors
An MQL program can recognize and change colors to display all chart elements. The corresponding properties are part of the ENUM_CHART_PROPERTY_INTEGER enumeration.
Identifier |
Description |
---|---|
CHART_COLOR_BACKGROUND |
Chart background color |
CHART_COLOR_FOREGROUND |
Color of axes, scales, and OHLC lines |
CHART_COLOR_GRID |
Grid color |
CHART_COLOR_VOLUME |
Color of volumes and position opening levels |
CHART_COLOR_CHART_UP |
The color of the up bar, the shadow, and the edging of the body of a bullish candle |
CHART_COLOR_CHART_DOWN |
The color of the down bar, the shadow, and the edging of the body of a bearish candle |
CHART_COLOR_CHART_LINE |
The color of the chart line and of the contours of Japanese candlesticks |
CHART_COLOR_CANDLE_BULL |
Bullish candlestick body color |
CHART_COLOR_CANDLE_BEAR |
Bearish candlestick body color |
CHART_COLOR_BID |
Bid price line color |
CHART_COLOR_ASK |
Ask price line color |
CHART_COLOR_LAST |
Color of the last traded price line (Last) |
CHART_COLOR_STOP_LEVEL |
Color of stop order levels (Stop Loss and Take Profit) |
As an example of working with these properties, let's create a script ChartColorInverse.mq5. It will change all the colors of the graph to inverse, that is, for the bit representation of the color in the format RGB XOR ('^',XOR). Thus, after restarting the script on the same chart, its settings will be restored.
#define RGB_INVERSE(C) ((color)C ^ 0xFFFFFF)
|
The following image combines the images of the chart before and after applying the script.
Inverting chart colors from an MQL program
Now let's finish editing IndSubChart.mq5. We need to read the colors of the main chart and apply them to our indicator chart. There is a function for these purposes: SetPlotColors, whose call was commented out in the OnChartEvent handler (see the last example in the section Chart Display Modes).
void SetPlotColors(const int index, const ENUM_CHART_MODE m)
|
In this new function, we get, depending on the chart drawing mode, either the color of the contours and bodies of bullish and bearish candlesticks, or the color of the lines, and apply the colors to the charts. Of course, do not forget to call this function during initialization.
int OnInit()
|
The indicator is ready. Try running it in the window and changing the colors in the chart properties dialog. The chart should automatically adapt to the new settings.