I would like to create a new Indicator from two existing ones.
For example, I would like to build a sum by adding two indicators (see code below).
Having more than one ISeries as input is a problem because only one of them can be set as base input for the UserIndicator. UserIndicator will have its Calculate() method called for each change in its base input. However, the second ISeries serving as input will not notify UserIndicator of its change.
I would like to know how I can notify UserIndicator of a change in a second input ISeries. Is that possible?
Code:
public class Addition: UserIndicator {
private ISeries summand2;
public Addition(String name, ISeries summand1, ISeries summand2) : base(summand1) {
this.Name = name;
this.summand2 = summand2;
}
public override double Calculate(int index) {
if ((index >= 0) && (Input.Count > index) && (summand2.Count > index)) {
return Input[index, BarData.Close] + summand2[index, BarData.Close];
}
else {
return Double.NaN;
}
}
public ISeries getSummand1() {
return Input;
}
public ISeries getSummand2() {
return summand2;
}
}