Custom Indicator
The necessity to use earlier created indicators occurs very often and allows avoiding duplication of the same logic in different scripts.
We will need two indicators; the first one will perform some simple calculation, for example, calculation of the SMA with specified period and price type. Let’s call it CustomSMA. The second indicator will get these calculated values and display them.
To provide this, at first, we need to get our Custom SMA through iCustom function:
public override void Init() { //creating of the custom MA with the specified parameters via iCustom method indicator = Indicators.iCustom("CustomSMA", CurrentData, 20, PriceType.Open); }
ICustom function allows to pass the input parameters for initialization. All indicator’s parameters for which the value isn’t passed, will have a default value. If quantity of formal parameters which are passed is more than the indicator has, the "extra" parameters will be ignored.
Now, we can get value of our indicator by a standard method:
public override void OnQuote() { double value = indicator.GetValue(); SetValue(0, value); }