namespace StockSharp.Algo.Indicators; /// /// Elder Impulse System indicator. /// [Display( ResourceType = typeof(LocalizedStrings), Name = LocalizedStrings.EISKey, Description = LocalizedStrings.ElderImpulseSystemKey)] [Doc("topics/api/indicators/list_of_indicators/elder_impulse_system.html")] public class ElderImpulseSystem : BaseIndicator { /// /// Initializes a new instance of the . /// public ElderImpulseSystem() : this(new() { Length = 13 }, new()) { } /// /// Initializes a new instance of the . /// /// /// public ElderImpulseSystem(ExponentialMovingAverage ema, MovingAverageConvergenceDivergence macd) { Ema = ema ?? throw new ArgumentNullException(nameof(ema)); Macd = macd ?? throw new ArgumentNullException(nameof(macd)); AddResetTracking(Ema); AddResetTracking(Macd); } /// /// /// [TypeConverter(typeof(ExpandableObjectConverter))] [Display( ResourceType = typeof(LocalizedStrings), Name = LocalizedStrings.EMAKey, Description = LocalizedStrings.ExponentialMovingAverageKey, GroupName = LocalizedStrings.GeneralKey)] public ExponentialMovingAverage Ema { get; } /// /// /// [TypeConverter(typeof(ExpandableObjectConverter))] [Display( ResourceType = typeof(LocalizedStrings), Name = LocalizedStrings.MACDKey, Description = LocalizedStrings.MACDDescKey, GroupName = LocalizedStrings.GeneralKey)] public MovingAverageConvergenceDivergence Macd { get; } /// public override IndicatorMeasures Measure => IndicatorMeasures.MinusOnePlusOne; /// public override int NumValuesToInitialize => Ema.NumValuesToInitialize.Max(Macd.NumValuesToInitialize); /// protected override IIndicatorValue OnProcess(IIndicatorValue input) { var prevEma = Ema.GetCurrentValue(); var prevMacd = Macd.GetCurrentValue(); var emaValue = Ema.Process(input); var macdValue = Macd.Process(input); if (Ema.IsFormed && Macd.IsFormed) { if (input.IsFinal) IsFormed = true; var ema = emaValue.ToDecimal(); var macd = macdValue.ToDecimal(); int impulse; if (ema > prevEma && macd > prevMacd) impulse = 1; // Green else if (ema < prevEma && macd < prevMacd) impulse = -1; // Red else impulse = 0; // Blue return new DecimalIndicatorValue(this, impulse, input.Time) { IsFinal = input.IsFinal, IsFormed = true }; } return new DecimalIndicatorValue(this, input.Time); } /// public override void Save(SettingsStorage storage) { base.Save(storage); storage .Set(nameof(Ema), Ema.Save()) .Set(nameof(Macd), Macd.Save()) ; } /// public override void Load(SettingsStorage storage) { base.Load(storage); Ema.Load(storage, nameof(Ema)); Macd.Load(storage, nameof(Macd)); } /// public override string ToString() => $"{base.ToString()}, EMA={Ema}, MACD={Macd}"; }