コード例 #1
0
        private void UpdateInternal(Bar bar)
        {
            Data.Add(bar);

            _lowestMetric.Update(bar.LowestPrice);
            _lowestPrice = _lowestMetric.Value;

            _highestMetric.Update(bar.HighestPrice);
            _highestPrice = _highestMetric.Value;
        }
コード例 #2
0
        public override void Update(Bar bar)
        {
            _highest.Update(bar.HighestPrice);
            var highest = _highest.Value;

            _lowest.Update(bar.LowestPrice);
            var lowest = _lowest.Value;

            var rsv = (bar.ClosePrice - lowest) / (highest - lowest) * 100;

            SetValue(100.0 - rsv);
        }
コード例 #3
0
ファイル: QuickKDJ.cs プロジェクト: wukan1986/StockAnalysis
        public override void Update(Bar bar)
        {
            _lowest.Update(bar.LowestPrice);
            var lowestPrice = _lowest.Value;

            _highest.Update(bar.HighestPrice);
            var highestPrice = _highest.Value;

            var rsv = (bar.ClosePrice - lowestPrice) / (highestPrice - lowestPrice) * 100.0;

            var k = rsv;
            var d = ((_kDecay - 1) * _prevD + k) / _kDecay;
            var j = _jCoeff * d - (_jCoeff - 1) * k;

            // update status;
            _prevD = d;

            SetValue(k, d, j);
        }
コード例 #4
0
        public override void Update(Bar bar)
        {
            if (_secondHalfHighest.Data.Length < _halfPeriod)
            {
                // second half is not full yet
                if (_firstHalfHighest.Data.Length < _halfPeriod)
                {
                    // first half is not full yet
                    _firstHalfHighest.Update(bar.HighestPrice);
                    _firstHalfLowest.Update(bar.LowestPrice);
                }
                else
                {
                    // first half is full
                    _secondHalfHighest.Update(bar.HighestPrice);
                    _secondHalfLowest.Update(bar.LowestPrice);
                }
            }
            else
            {
                _firstHalfHighest.Update(_secondHalfHighest.Data[0]);
                _firstHalfLowest.Update(_secondHalfLowest.Data[0]);

                _secondHalfHighest.Update(bar.HighestPrice);
                _secondHalfLowest.Update(bar.LowestPrice);
            }

            // warming up stage
            if (double.IsNaN(_lastFrama))
            {
                _initialFrama.Update(bar.ClosePrice);

                if (_initialFrama.Data.Length >= _h)
                {
                    _lastFrama = _initialFrama.Value;
                }

                SetValue(_initialFrama.Value);

                return;
            }

            // calculation stage
            double firstHalfHighestValue  = _firstHalfHighest.Value;
            double firstHalfLowestValue   = _firstHalfLowest.Value;
            double secondHalfHighestValue = _secondHalfHighest.Value;
            double secondHalfLowestValue  = _secondHalfLowest.Value;

            double highestValue = Math.Max(firstHalfHighestValue, secondHalfHighestValue);
            double lowestValue  = Math.Min(firstHalfLowestValue, secondHalfLowestValue);

            var hl1 = (firstHalfHighestValue - firstHalfLowestValue) / _halfPeriod;
            var hl2 = (secondHalfHighestValue - secondHalfLowestValue) / _halfPeriod;
            var hl  = (highestValue - lowestValue) / _period;

            var fractalDimension = (Math.Log(hl1 + hl2) - Math.Log(hl)) / _log2;
            var alpha            = Math.Exp(_w * (fractalDimension - 1.0));

            if (alpha < _minAlpha)
            {
                alpha = _minAlpha;
            }

            if (alpha > _maxAlpha)
            {
                alpha = _maxAlpha;
            }

            var originalNEma = (2.0 - alpha) / alpha;
            var newNEma      = ((_sc - _fc) * ((originalNEma - 1.0) / (_sc - 1.0))) + _fc;
            var newAlpha     = 2.0 / (newNEma + 1.0);

            var newFrama = _lastFrama + newAlpha * (bar.ClosePrice - _lastFrama);

            SetValue(newFrama);

            _lastFrama = newFrama;
        }