The function is called in the indicators when the Calculate event occurs for processing price data changes. There are two function types. Only one of them can be used within a single indicator.
Calculation based on data array
Calculations based on the current timeframe timeseries
[in] Size of the price array or input series available to the indicator for calculation. In the second function type, the parameter value corresponds to the number of bars on the chart it is launched at.
[in] Contains the value returned by the OnCalculate() function during the previous call. It is designed to skip the bars that have not changed since the previous launch of this function.
[in] Index value in the price array meaningful data starts from. It allows you to skip missing or initial data, for which there are no correct values.
[in] Array of values for calculations. One of the price timeseries or a calculated indicator buffer can be passed as the price array. Type of data passed for calculation can be defined using the _AppliedTo predefined variable.
[in] Array with bar open time values.
[in] Array with Open price values.
[in] Array with High price values.
[in] Array with Low price values.
[in] Array with Close price values.
[in] Array with tick volume values.
[in] Array with trade volume values.
[in] Array with spread values for bars.
int type value to be passed as the prev_calculated parameter during the next function call.
If the OnCalculate() function is equal to zero, no indicator values are shown in the DataWindow of the client terminal.
If the price data have been changed since the last call of the OnCalculate() function (a deeper history has been loaded or gaps in the history have been filled), the value of the prev_calculated input parameter is set to zero by the terminal itself.
To define the indexing direction in the time, open, high, low, close, tick_volume, volume and spread arrays, call the ArrayGetAsSeries() function. In order not to depend on defaults, call the ArraySetAsSeries() function for the arrays to work with.
When using the first function type, a necessary timeseries or indicator is selected by a user as the price array in the Parameters tab when launching the indicator. To do this, specify the necessary element in the drop-down list of the "Apply to" field.
To get custom indicator values from other mql5 programs, the iCustom() function is used. It returns the indicator handle for subsequent operations. It is also possible to specify the required price  array or the handle of another indicator. This parameter should be passed the last in the list of input variables of a custom indicator.
It is necessary to use the connection between the value returned by the OnCalculate() function and the prev_calculated second input parameter. When calling the function, the prev_calculated parameter contains the value returned by the OnCalculate() function during the previous call. This makes it possible to implement resource-saving algorithms for calculating a custom indicator in order to avoid repetitive calculations for the bars that have not changed since the previous launch of this function.