public class MyCrossOverIndicator : Indicator {
private IndicatorBase _ib;
protected override void OnStateChange() {
if (State == State.SetDefaults) {
Name = "MyCrossOverIndicator";
Calculate = Calculate.OnBarClose;
AddPlot(Brushes.Orange, "plot");
}
else if (State == State.Configure) {
ClearOutputWindow();
}
else if (State == State.DataLoaded) {
// Attempt to find an EMA indicator already applied on the chart
_ib = FindIndicator(IndicatorName, typeof(EMA));
}
}
protected override void OnBarUpdate() {
if (_ib != null) {
EMA ema = (EMA)_ib;
Values[0][0] = ema[0];
Print($"name: {ema.Name}/{ema.Count}, value: {ema[0]}");
}
}
private IndicatorBase FindIndicator(string indicatorName, Type indicatorType) {
foreach (IndicatorBase indicator in ChartControl.Indicators) {
if (indicator.GetType() == indicatorType && indicator.Name == indicatorName)
return indicator;
}
return null;
}
[NinjaScriptProperty]
[Display(Name = "Indicator Name", GroupName = "Setup")]
public string IndicatorName { get; set; }
}

Comment