コード例 #1
0
        public override TimeBaseValue Calculate(int forIndex)
        {
            CheckCreateInnerIndicators();

            FastEmaIndicator.Result.Add(FastEmaIndicator.Calculate(forIndex));
            SlowEmaIndicator.Result.Add(SlowEmaIndicator.Calculate(forIndex));

            if (forIndex < SlowLength)
            {
                IndicatorValue nullValue = new IndicatorValue()
                {
                    Time = GetTime(forIndex), Value = double.NaN, Source = GetValueBySource(forIndex)
                };
                Result.Push(nullValue);
                SignalMaIndicator.Result.Add(SignalMaIndicator.Calculate(forIndex));
                Result.Pop();
                return(nullValue);
            }

            IndicatorValue value = new IndicatorValue()
            {
                Time = GetTime(forIndex), Value = ((IndicatorValue)FastEmaIndicator.Result[forIndex]).Value - ((IndicatorValue)SlowEmaIndicator.Result[forIndex]).Value, Source = GetValueBySource(forIndex)
            };

            Result.Push(value);
            IndicatorValue signal = (IndicatorValue)SignalMaIndicator.Calculate(forIndex);

            SignalMaIndicator.Result.Add(signal);
            Result.Pop();
            return(value);
        }
コード例 #2
0
        public override void OnUpdateValue(int index)
        {
            IndicatorValue fast  = (IndicatorValue)FastEmaIndicator.Calculate(index);
            IndicatorValue slow  = (IndicatorValue)SlowEmaIndicator.Calculate(index);
            double         value = fast.Value - slow.Value;

            ((IndicatorValue)Result[index]).Value = value;
            IndicatorValue signal = (IndicatorValue)SignalMaIndicator.Calculate(index);

            ((IndicatorValue)SignalMaIndicator.Result[index]).Value = signal.Value;
        }