Skip to content

Custom Indicators

Custom Indicators

This is the group functions used in the creation of custom indicators. These functions can’t be used when writing Expert Advisors and Scripts.

FunctionAction
HideTestIndicatorsThe function sets a flag hiding indicators called by the Expert Advisor
IndicatorSetDoubleSets the value of an indicator property of the double type
IndicatorSetIntegerSets the value of an indicator property of the int type
IndicatorSetStringSets the value of an indicator property of the string type
SetIndexBufferBinds the specified indicator buffer with one-dimensional dynamic array of the double type
IndicatorBuffersAllocates memory for buffers used for custom indicator calculations
IndicatorCountedReturns the amount of bars not changed after the indicator had been launched last
IndicatorDigitsSets precision format to visualize indicator values
IndicatorShortNameSets the “short” name of a custom indicator to be shown in the DataWindow and in the chart subwindow
SetIndexArrowSets an arrow symbol for indicators line of the DRAW_ARROW type
SetIndexDrawBeginSets the bar number from which the drawing of the given indicator line must start
SetIndexEmptyValueSets drawing line empty value
SetIndexLabelSets drawing line description for showing in the DataWindow and in the tooltip
SetIndexShiftSets offset for the drawing line
SetIndexStyleSets the new type, style, width and color for a given indicator line
SetLevelStyleSets a new style, width and color of horizontal levels of indicator to be output in a separate window
SetLevelValueSets a value for a given horizontal level of the indicator to be output in a separate window

Indicator properties can be set using the compiler directives or using functions. To better understand this, it is recommended that you study indicator styles in examples.

All the necessary calculations of a custom indicator must be placed in the predetermined function OnCalculate().

What’s new in MQL5

MQL4 programmers have 8 buffers and 6 drawing styles to develop custom indicators. In MQL5, this set has been significantly increased up to 512 indicator buffers and 18 drawing styles. In addition, timeseries indexing (calculation from present to past) is not necessary to calculate indicator values. Such an approach is very convenient for developing EAs, but it causes difficulties when working with indicator buffers in loops. Now you are able to set the indexing direction in the arrays on your own, which greatly simplifies the development of indicators.

Another notable feature of MQL5 is the dynamic change of the drawing style using the PlotIndexSetXXX functions. For example, an indicator’s color, style, line width, as well as an arrow’s color and code can be changed on the fly if a certain condition occurs.

color_ma

Also, added the OnCalculate() handler allowing to calculate indicator values based on another indicator. Thus, in MQL5, custom indicators can be superimposed on other indicators (for example, TEMA from MACD) allowing users to receive new combinations of indicators to quickly test ideas without programming.

Last updated on