- Main characteristics of indicators
- Main indicator event: OnCalculate
- Two types of indicators: for main window and subwindow
- Setting the number of buffers and graphic plots
- Assigning an array as a buffer: SetIndexBuffer
- Plot settings: PlotIndexSetInteger
- Buffer and chart mapping rules
- Applying directives to customize plots
- Setting plot names
- Visualizing data gaps (empty elements)
- Indicators in separate subwindows: sizes and levels
- General properties of indicators: title and value accuracy
- Item-wise chart coloring
- Skip drawing on initial bars
- Waiting for data and managing visibility (DRAW_NONE)
- Multicurrency and multitimeframe indicators
- Tracking bar formation
- Testing indicators
- Limitations and advantages of indicators
- Creating an indicator draft in the MQL Wizard
Setting plot names
In the previous examples within this chapter, indicator buffers in the Data Window were designated by the name of the indicator itself. This is not informative. The MQL5 API provides the ability to set a custom name for each buffer. This can be done in two ways which we already know: by using the #property directive and by calling the special PlotIndexSetString function.
bool PlotIndexSetString(int index, ENUM_PLOT_PROPERTY_STRING property, string value)
The function prototype is similar to PlotIndexSetInteger except that the type of properties (value parameter) is string. The function supports only one PLOT_LABEL property (it is the ENUM_PLOT_PROPERTY_STRING enumeration constant). Custom chart index in the index parameter must be between 0 and N-1, where N is the total number of plots specified in #property indicator_plots N.
When using the directive, the chart index should be adjusted by 1 because the numbering of plots in directives starts from one, while in function parameters it starts from zero.
Directive |
Function |
Description |
---|---|---|
#property indicator_labelN |
PlotIndexSetString(N-1, PLOT_LABEL, string) |
Specifies a text label to display in the Data window and in tooltips |
For graphic series that require several indicator buffers (for example, DRAW_CANDLES, DRAW_FILLING, and others), label names are specified with the ';' separator.
Labels are also shown in a tooltip when hovering over a chart.
In the example of IndLabelHighLowClose.mq5, we add two directives (the difference from IndPropHighLowClose.mq5).
#property indicator_label1 "High;Low"
|
Now it is much easier to understand the values that appear when displaying the indicator in the Data Window.