- 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
Limitations and advantages of indicators
All specialized functions discussed in this chapter are available only in the indicator source codes. It makes no sense to use them in other types of MQL programs: they will return an error.
There are other functions that are prohibited in indicators:
- OrderCalcMargin
- OrderCalcProfit
- OrderCheck
- OrderSend
- SendFTP
- WebRequest
- Socket***
- Sleep
- MessageBox
- ExpertRemove
Some of them (with the prefix Order-) refer to trading calculations and are only allowed in Expert Advisors and scripts. Others are intended for executing requests that block the tread execution until the result is returned, while this is not allowed for indicators because they are executed in the terminal's interface thread. For a similar reason, the Sleep and MessageBox functions are prohibited.
Indicators are primarily responsible for visualizing data and, oddly enough, are not suitable for massive calculations. In particular, if you decide to create an indicator that trains a neural network or a decision tree in the process, this will most likely negatively affect the normal functioning of the terminal.
The effect of a long calculation is demonstrated by the indicator IndBarIndex.mq5, which in the normal mode is designed to display bar numbers in the elements of its buffer. However, using the input parameter SimulateCalculation, which should be set to true, you can start an infinite loop on a timer.
// Setting to true will freeze the drawing of indicators
|
In this mode, the indicator, as expected, begins to completely occupy 1 processor core, but another side effect also appears. Any indicators on the same symbol where IndBarIndex is placed, stop updating. For example, we can run IndBarIndex on EURUSD (any timeframe), and then on any other EURUSD chart, you can try to apply a regular moving average: it will not be displayed until you remove IndBarIndex from the first chart.
In this regard, all lengthy calculations should be placed in separate threads, that is, scripts or non-trading Expert Advisors, and only their results should be used in indicators. The MQL5 API allows you to create new charts or objects with charts, in which it is possible to apply tpl templates with the required Expert Advisor or script.