Creating custom indicators

Indicators are one of the most popular types of MQL programs. They are a simple yet powerful tool for technical analysis. The main mechanism of their use is the processing of the initial price data using formulas for creating derivative timeseries. This enables the evaluation and visualization of specific characteristics of market processes. Any timeseries, including those obtained as a result of indicator calculations, can be fed into another indicator, and so on. Formulas of many well-known indicators (for example, MACD) actually consist of calls to several interrelated indicators.

Terminal users are undoubtedly familiar with many built-in indicators, and they also know that the list of available indicators can be expanded using the MQL5 language. From the user's point of view, built-in and custom indicators implemented in MQL5 work in exactly the same way.

As a rule, indicators display their operation results in the form of lines, histograms, and other graphical constructions in the price chart window. Each such chart is visualized on the basis of calculated timeseries, which are stored inside the indicators in special arrays called indicator buffers: they are available for viewing in the terminal Data Window along with the OHLC prices. However, indicators can provide extra functionality in addition to buffers or may have no buffers at all. For example, indicators are often used to solve problems where you need to create graphic objects, manage the chart and its properties, and interact with the user (see OnChartEvent).

In this chapter we will study the basic principles of creating indicators in MQL5. Such indicators are usually called "custom" because the user can write them from scratch or compile them from ready-made source codes. In the next chapter, we will turn to the issues of programmatic management of custom and built-in indicators, which will allow us to construct more complex indicators and pave the way for indicator-based trading signals and filters for Expert Advisors.

A little later, we will master the technology of introducing indicators into executable MQL programs in the form of resources.