Пример #1
0
        public override void OnUpdateValue(int index)
        {
            IndicatorValue max = (IndicatorValue)MaxIndicator.Calculate(index);
            IndicatorValue min = (IndicatorValue)MinIndicator.Calculate(index);

            double k = (GetValueBySource(index) - min.Value) / (max.Value - min.Value) * 100;

            ((StochasticValue)Result[index]).K = k;

            IndicatorValue ma = (IndicatorValue)MaIndicator.Calculate(index);

            ((StochasticValue)Result[index]).D = ma.Value;
        }
Пример #2
0
        public override TimeBaseValue Calculate(int forIndex)
        {
            IndicatorValue max = (IndicatorValue)MaxIndicator.Calculate(forIndex);

            MaxIndicator.Result.Add(max);
            IndicatorValue min = (IndicatorValue)MinIndicator.Calculate(forIndex);

            MinIndicator.Result.Add(min);

            IndicatorValue ma = null;

            if (forIndex < Length)
            {
                StochasticValue nullValue = new StochasticValue()
                {
                    Time = GetTime(forIndex), K = double.NaN, D = double.NaN, Source = GetValueBySource(forIndex)
                };
                Result.Push(nullValue);
                ma = (IndicatorValue)MaIndicator.Calculate(forIndex);
                MaIndicator.Result.Add(ma);
                Result.Pop();
                return(nullValue);
            }

            double          k   = (GetValueBySource(forIndex) - min.Value) / (max.Value - min.Value) * 100;
            StochasticValue res = new StochasticValue()
            {
                Time   = GetTime(forIndex),
                K      = k,
                D      = 0,
                Source = GetValueBySource(forIndex)
            };

            Result.Push(res);
            ma = (IndicatorValue)MaIndicator.Calculate(forIndex);
            MaIndicator.Result.Add(ma);
            res.D = ma.Value;
            Result.Pop();

            return(res);
        }