Example #1
0
        public override void Calculate()
        {
            Result.Clear();
            HistorySig.Clear();
            if (Ticker == null)
            {
                return;
            }
            EmaIndicator emaFast = new EmaIndicator()
            {
                Ticker = Ticker, Length = FastLength, SuppressUpdateOnDataChanged = true
            };
            EmaIndicator emaSlow = new EmaIndicator()
            {
                Ticker = Ticker, Length = SlowLength, SuppressUpdateOnDataChanged = true
            };

            emaFast.Calculate();
            emaSlow.Calculate();

            for (int i = 0; i < Ticker.CandleStickData.Count; i++)
            {
                DateTime time = Ticker.CandleStickData[i].Time;
                if (i < SlowLength)
                {
                    Result.Add(new IndicatorValue()
                    {
                        Time = time, Value = double.NaN, Source = GetValueBySource(i)
                    });
                    continue;
                }
                Result.Add(new IndicatorValue()
                {
                    Time = time, Value = ((IndicatorValue)emaFast.Result[i]).Value - ((IndicatorValue)emaSlow.Result[i]).Value, Source = GetValueBySource(i)
                });
            }

            MaIndicator ma = new MaIndicator()
            {
                Length = Length, InputData = Result, SuppressUpdateOnDataChanged = true
            };

            ma.Calculate();

            FastEmaIndicator  = emaFast;
            SlowEmaIndicator  = emaSlow;
            SignalMaIndicator = ma;
        }
Example #2
0
        protected void CheckCreateInnerIndicators()
        {
            if (FastEmaIndicator != null)
            {
                return;
            }
            EmaIndicator emaFast = new EmaIndicator()
            {
                Ticker = Ticker, Length = FastLength, SuppressUpdateOnDataChanged = true
            };
            EmaIndicator emaSlow = new EmaIndicator()
            {
                Ticker = Ticker, Length = SlowLength, SuppressUpdateOnDataChanged = true
            };
            MaIndicator ma = new MaIndicator()
            {
                Length = Length, InputData = Result, SuppressUpdateOnDataChanged = true
            };

            FastEmaIndicator  = emaFast;
            SlowEmaIndicator  = emaSlow;
            SignalMaIndicator = ma;
        }