Beispiel #1
0
        public override double Update(StockAnalysis.Share.Bar bar)
        {
            double cost = ((bar.ClosePrice - bar.LowestPrice)
                           - (bar.HighestPrice - bar.ClosePrice))
                          / (bar.HighestPrice - bar.LowestPrice)
                          * bar.Volume;

            return(_sumCost.Update(cost) / _sumVolume.Update(bar.Volume));
        }
        public override double Update(StockAnalysis.Share.Bar bar)
        {
            double truePrice = (bar.HighestPrice + bar.LowestPrice + 2 * bar.ClosePrice) / 4;

            double sumCost   = _msCost.Update(bar.Volume * truePrice);
            double sumVolume = _msVolume.Update(bar.Volume);

            return(sumCost / sumVolume);
        }
        public override double Update(double dataPoint)
        {
            double uc = _firstData
                ? 0.0
                : Math.Max(0.0, dataPoint - _prevData);

            double dc = _firstData
                ? 0.0
                : Math.Max(0.0, _prevData - dataPoint);

            double msuc = _msUc.Update(uc);
            double msdc = _msDc.Update(dc);

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

            return((msuc + msdc == 0.0) ? 0.0 : msuc / (msuc + msdc) * 100.0);
        }
Beispiel #4
0
        public override double Update(StockAnalysis.Share.Bar bar)
        {
            const double SmallValue = 1e-10;

            double pv, nv, zv;

            if (_firstBar)
            {
                pv = nv = SmallValue;
                zv = bar.Volume;
            }
            else
            {
                if (bar.ClosePrice > _prevClosePrice)
                {
                    pv = bar.Volume;
                    nv = zv = 0.0;
                }
                else if (bar.ClosePrice < _prevClosePrice)
                {
                    nv = bar.Volume;
                    pv = zv = 0.0;
                }
                else
                {
                    zv = bar.Volume;
                    pv = nv = 0.0;
                }
            }

            double msPv = _msPv.Update(pv) + SmallValue;
            double msNv = _msNv.Update(nv) + SmallValue;
            double msZv = _msZv.Update(zv) + SmallValue;

            double result = (msPv + msZv / 2.0) / (msNv + msZv / 2.0) * 100.0;

            // update status
            _prevClosePrice = bar.ClosePrice;
            _firstBar       = false;

            // return result;
            return(result);
        }
Beispiel #5
0
        public override double Update(StockAnalysis.Share.Bar bar)
        {
            const double SmallValue = 1e-10;

            double truePrice = (bar.HighestPrice + bar.LowestPrice + bar.ClosePrice) / 3;

            double positiveMoneyFlow;
            double negativeMoneyFlow;

            if (_firstData)
            {
                positiveMoneyFlow = truePrice * bar.Volume;
                negativeMoneyFlow = SmallValue;
            }
            else
            {
                if (truePrice > _prevTruePrice)
                {
                    positiveMoneyFlow = truePrice * bar.Volume;
                    negativeMoneyFlow = 0.0;
                }
                else if (truePrice < _prevTruePrice)
                {
                    positiveMoneyFlow = 0.0;
                    negativeMoneyFlow = truePrice * bar.Volume;
                }
                else
                {
                    positiveMoneyFlow = negativeMoneyFlow = SmallValue;
                }
            }

            double sumPmf = _msPmf.Update(positiveMoneyFlow);
            double sumNmf = _msNmf.Update(negativeMoneyFlow);

            // update status
            _prevTruePrice = truePrice;
            _firstData     = false;

            // return result
            return(100.0 / (1.0 + sumPmf / sumNmf));
        }
Beispiel #6
0
        public override double[] Update(StockAnalysis.Share.Bar bar)
        {
            // calculate AR
            double up   = _sumUp.Update(bar.HighestPrice - bar.OpenPrice);
            double down = _sumDown.Update(bar.OpenPrice - bar.LowestPrice);

            double ar = down == 0.0 ? 0.0 : up / down * 100.0;

            // calculate BR
            double tempBrBs = _firstBar ? 0.0 : Math.Max(0.0, bar.HighestPrice - _prevBar.ClosePrice);
            double tempBrSs = _firstBar ? 0.0 : Math.Max(0.0, _prevBar.ClosePrice - bar.LowestPrice);

            double brbs = _sumBrBs.Update(tempBrBs);
            double brss = _sumBrSs.Update(tempBrSs);

            double br = brss == 0.0 ? 0.0 : brbs / brss * 100.0;

            // calculate CR
            double tp = Tp(_prevBar);

            double tempCrBs = _firstBar ? 0.0 : Math.Max(0.0, bar.HighestPrice - tp);
            double tempCrSs = _firstBar ? 0.0 : Math.Max(0.0, tp - bar.LowestPrice);

            double crbs = _sumCrBs.Update(tempCrBs);
            double crss = _sumCrSs.Update(tempCrSs);

            double cr = crss == 0.0 ? 0.0 : crbs / crss * 100.0;

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

            // return results;
            return(new double[3] {
                ar, br, cr
            });
        }
Beispiel #7
0
        public override double Update(double dataPoint)
        {
            double sum = _movingSum.Update(dataPoint);

            return(sum / _movingSum.Data.Length);
        }
        public override double Update(StockAnalysis.Share.Bar bar)
        {
            double index = (bar.ClosePrice - bar.OpenPrice) * bar.Volume / (bar.HighestPrice - bar.LowestPrice);

            return(_ms.Update(index));
        }
        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
            });
        }