Пример #1
0
 public override double Update(double dataPoint)
 {
     return((_ma1.Update(dataPoint) +
             _ma2.Update(dataPoint) +
             _ma3.Update(dataPoint) +
             _ma4.Update(dataPoint)) / 4.0);
 }
Пример #2
0
        public override double Update(Bar bar)
        {
            double trueRange =
                Math.Max(
                    Math.Max(bar.HighestPrice - bar.LowestPrice, bar.HighestPrice - _prevClosePrice),
                    _prevClosePrice - bar.LowestPrice);

            _prevClosePrice = bar.ClosePrice;

            return(_maTrueRange.Update(trueRange));
        }
Пример #3
0
        public override double[] Update(double dataPoint)
        {
            double ma     = _ma.Update(dataPoint);
            double stddev = _sd.Update(dataPoint);

            double upperBound = ma + _alpha * stddev;
            double lowerBound = ma - _alpha * stddev;

            return(new double[3] {
                upperBound, ma, lowerBound
            });
        }
Пример #4
0
        public override double Update(double dataPoint)
        {
            double up = _firstData
                ? 0.0
                : (dataPoint > _prevData)
                    ? 100.0
                    : 0.0;

            // update status
            _prevData  = dataPoint;
            _firstData = false;

            // return result
            return(_ma.Update(up));
        }
Пример #5
0
        public override double Update(StockAnalysis.Share.Bar bar)
        {
            double truePrice = (bar.HighestPrice + bar.LowestPrice + 2 * bar.ClosePrice) / 4;

            _truePrices.Add(truePrice);

            double maTruePrice = _maTruePrice.Update(truePrice);

            double sum = 0.0;

            for (int i = 0; i < _truePrices.Length; ++i)
            {
                sum += Math.Abs(_truePrices[i] - maTruePrice);
            }

            double d = sum / _truePrices.Length;

            return(d == 0.0 ? 0.0 : (truePrice - maTruePrice) / d / Alpha);
        }
Пример #6
0
 public override double Update(double dataPoint)
 {
     return(dataPoint - _ma.Update(dataPoint));
 }
Пример #7
0
        public override double Update(double dataPoint)
        {
            double average = _ma.Update(dataPoint);

            return((dataPoint - average) / average);
        }
Пример #8
0
 public override double Update(double dataPoint)
 {
     return(_maShort.Update(dataPoint) - _maLong.Update(dataPoint));
 }
        public override double[] Update(StockAnalysis.Share.Bar bar)
        {
            // calculate +DM and -DM
            double pdm, ndm;

            if (_firstBar)
            {
                pdm = 0.0;
                ndm = 0.0;
            }
            else
            {
                pdm = Math.Max(0.0, bar.HighestPrice - _prevBar.HighestPrice);
                ndm = Math.Max(0.0, _prevBar.LowestPrice - bar.LowestPrice);

                if (pdm > ndm)
                {
                    ndm = 0.0;
                }
                else if (pdm < ndm)
                {
                    pdm = 0.0;
                }
                else
                {
                    pdm = ndm = 0.0;
                }
            }

            // Calculate +DI and -DI
            double tr, pdi, ndi;

            if (_firstBar)
            {
                tr = bar.HighestPrice - bar.LowestPrice;
            }
            else
            {
                tr = Math.Max(Math.Abs(bar.HighestPrice - bar.LowestPrice),
                              Math.Max(Math.Abs(bar.HighestPrice - _prevBar.ClosePrice), Math.Abs(bar.LowestPrice - _prevBar.ClosePrice)));
            }

            pdi = pdm * 100.0 / tr;
            ndi = ndm * 100.0 / tr;

            // calculate +DIM and -DIM
            double mspdm = _msPdm.Update(pdm);
            double msndm = _msNdm.Update(ndm);
            double mstr  = _msTr.Update(tr);

            double pdim = mspdm * 100.0 / mstr;
            double ndim = msndm * 100.0 / mstr;

            // calculate DX and ADX
            double dx = (pdim + ndim) == 0.0 ? 0.0 : Math.Abs(pdim - ndim) / (pdim + ndim);

            double adx = _maDx.Update(dx);

            // calculate ADXR
            _adx.Add(adx);
            double adxr = (_adx[_adx.Length - 1] + _adx[0]) / 2.0;

            // update internal status
            _prevBar  = bar;
            _firstBar = false;

            // return result
            return(new double[4] {
                pdim, ndim, adx, adxr
            });
        }