Beispiel #1
0
        protected override double calculate()
        {
            if (bars.count() < 6)
            {
                return(0);
            }

            if (this[1] < 0)
            {
                if (bars[0].close < bars[4].close)
                {
                    return(this[1] - 1);
                }
            }
            if (this[1] > 0)
            {
                if (bars[0].close > bars[4].close)
                {
                    return(this[1] + 1);
                }
            }
            if (bullishPriceFlip())
            {
                return(1);
            }
            if (bearishPriceFlip())
            {
                return(-1);
            }
            return(0);
        }
Beispiel #2
0
        protected override double calculate()
        {
            if (values.count() > 1)
            {
                noise.set(Math.Abs(values[0] - values[1]));
            }
            if (values.count() <= calcBars)
            {
                return(values[0]);
            }

            var signal               = Math.Abs(values[0] - values[calcBars]);
            var efficiencyRatio      = signal / noiseSum;
            var smoothingCoefficient = Math.Pow(efficiencyRatio * (decayFast - decaySlow) + decaySlow, 2);

            return(this[1] + smoothingCoefficient * (values[0] - this[1]));
        }
Beispiel #3
0
        protected override RegressionBar calculate()
        {
            if (isMissingData() || slope.hasNaN(1) || slope.hasInfinity(1) || slope.count() < 1)
            {
                return(RegressionBar.NAN);
            }
            var intercept = (weightedSum(y) - slope[0] * weightedSum(x)) / weightSum;

            return(new RegressionBar(intercept, slope[0], y.last(window), x.last(window), 2, weights));
        }
Beispiel #4
0
        protected override double calculate()
        {
            if (bars.count() == 1)
            {
                return(bars[0].range());
            }
            var prevClose = bars[1].close;
            var max       = Math.Max(bars[0].high, prevClose);
            var min       = Math.Min(bars[0].low, prevClose);

            return(max - min);
        }
Beispiel #5
0
        protected override double calculate()
        {
            if (values.count() < (freq * window) + (freq > 1 ?  -(freq - 1) : 0))
            {
                return(values);
            }
            double res = 0;

            if (useGoldenRatio)
            {
                zeroTo(window, i => res = res + logValues[i * freq] * Math.Pow(1 / g, i * 2 + 1));
            }
            else
            {
                zeroTo(window, i => res = res + logValues[i * freq] * sequence[2 * window - (i * 2 + 1)] / sequence[2 * window]);
            }
            return(Math.Exp(res));
        }
Beispiel #6
0
        protected override double calculate()
        {
            if (values.count() == 1)
            {
                return(double.NaN);
            }
            var changes = values[0] - values[1];

            upChanges.set(Math.Max(0.0, changes));
            dnChanges.set(-Math.Min(0.0, changes));
            double rs;

            if (dnAverage == 0)
            {
                rs = 1000000.0;
            }
            else
            {
                rs = upAverage / dnAverage;
            }

            return(100.0 - (100.0 / (1.0 + rs)));
        }
Beispiel #7
0
 protected bool isMissingData(Spud <double> values)
 {
     return(values.count() < window || hasInvalidNumbers(values));
 }
Beispiel #8
0
 public bool hasValue(DateTime time)
 {
     return(timeIndices.ContainsKey(time) && doubles.count() > timeIndices[time]);
 }
Beispiel #9
0
 protected override double calculate()
 {
     return((values.count() > 1 && !Equals(this[1], double.NaN)) ? (1.0 - lambda) * values + lambda * this[1] : values);
 }