Tutorial: Moving Average
In this tutorial, we will look at an example implementation of the MovingAverage
indicator.
To get acquainted with the implementation example, download the archive with the indicator example and open it in IDE of your choice, we suggest you use Cursor IDE.
You can download the archive of Moving Average from here
Indicator structure
A custom indicator is built by extending the IndicatorImplementation
class, provided by the forex-tester-custom-indicator-api
library.
You can find this implementation in the source code of the Moving Average example described in the Setup and Installation section.
Indicator parameters
These parameters can be of different types, they are determined by the TOptValue class, and they will be displayed in the indicator addition/editing window

For this, they need to be registered in the Init function.
You can see the methods for registering parameters in the external parameters definition
Buffers setup
Buffers are used to store and display indicator values on the chart.
They need to be declared with all class fields and initialized in the Init function
After their creation, you need to tell how many buffers will be displayed on the chart and bind them by index, starting from 0 (the indices must be unique) In this case, there is one buffer
Each registered buffer can be configured
Other settings
Also, other methods for configuring the indicator are used in the Init function. To ensure the indicator recalculates on each tick, use the function RecalculateMeAlways. If this setting is not used, each buffer index will be calculated only once to save resources, but some indicators may be calculated inaccurately. If the calculations do not heavily load the processor, we recommend always using it.
Set the indicator name, which will be displayed in the indicator settings window and in the context menu: IndicatorShortName.
We want the Moving Average indicator to be displayed on the main chart, so we use SetOutputWindow.
Using this call, specify that values equal to 0 will not be drawn on the chart: SetEmptyValue.
Indicator's main function
The main function of the indicator is the Calculate function, where the indicator values are calculated on each tick.
Changing parameters
To add custom logic after changing the indicator parameters, we use the OnParamsChange method. In Moving average, it is applied to the horizontal shift of the indicator. This method is often used to work with custom objects or to shift the indicator.
Last updated