Esempio n. 1
0
        public override double Update(double newValue)
        {
            double oldMACD   = Fast.Value - Slow.Value;
            double oldSignal = Signal.Value;

            Fast.Update(newValue);
            Slow.Update(newValue);

            double newMACD = Fast.Value - Slow.Value;

            Signal.Update(newMACD);
            double newSignal = Signal.Value;

            MACDCrossedSignal   = (Math.Sign(oldSignal - oldMACD) != Math.Sign(newSignal - newMACD));
            MACDCrossedZero     = (Math.Sign(oldMACD) != Math.Sign(newMACD));
            MACDStockDivergence = Math.Sign(maxValue - newValue) != Math.Sign(maxMACDValue - newMACD);

            if (newValue > maxValue)
            {
                maxValue = newValue;
            }

            if (newMACD > maxMACDValue)
            {
                maxMACDValue = newMACD;
            }

            MACDValue   = newMACD;
            SignalValue = newSignal;

            return(Value);
        }
Esempio n. 2
0
        public static object EMA(object[] Data, double DecayFactor, object FullSeriesOpt, object ReverseDataOpt)
        {
            bool fullSeries  = Utils.GetOptionalParameter(FullSeriesOpt, false);
            bool reverseData = Utils.GetOptionalParameter(ReverseDataOpt, false);

            double[] data = Utils.GetVector <double>(Data);

            if (reverseData)
            {
                data = data.Reverse().ToArray();
            }

            EMA em = new CommonTypes.EMA(DecayFactor);

            double[,] ret = new double[data.Length, 1];
            for (int i = 0; i < ret.Length; ++i)
            {
                int index = (reverseData ? ret.Length - i - 1 : i);
                ret[index, 0] = em.Update(data[i]);
            }

            if (fullSeries)
            {
                return(ret);
            }
            else
            {
                return(reverseData ? ret[0, 0] : ret[data.Length - 1, 0]);
            }
        }
Esempio n. 3
0
        public ATR(int windowLength)
        {
            WindowLength = windowLength;
            if (WindowLength < 3)
            {
                throw new Exception("Error, ATR calculation requires at least 2 full bars! (WindowLength must be greater than 2)");
            }

            Cache = new CircularBuffer <Tuple <double, double, double> >(WindowLength);

            ATRValue = new EMA(1D / WindowLength);
            ATRValue.Update(0);
        }
Esempio n. 4
0
        public MACD(double fastSmoothingFactor, double slowSmoothingFactor, double signalSmoothingFactor)
        {
            FastSmoothingFactor = fastSmoothingFactor;
            Fast = new EMA(FastSmoothingFactor);

            SlowSmoothingFactor = slowSmoothingFactor;
            Slow = new EMA(SlowSmoothingFactor);

            SignalSmoothingFactor = signalSmoothingFactor;
            Signal = new EMA(SignalSmoothingFactor);

            Signal.Update(0);

            MACDCrossedSignal   = false;
            MACDCrossedZero     = false;
            MACDStockDivergence = false;

            maxValue     = 0;
            maxMACDValue = 0;
        }
Esempio n. 5
0
        public double Update(double newClose, double newLow, double newHigh)
        {
            Cache.Insert(new Tuple <double, double, double>(newClose, newLow, newHigh));

            if (Cache.Length == WindowLength)
            {
                double highLowRange = newHigh - newLow;

                double TR = highLowRange;
                Tuple <double, double, double> previous = Cache.FromLast(-1);
                double previousClose = previous.Item1;
                double previousLow   = previous.Item2;
                double previousHigh  = previous.Item3;

                double highCloseRange = Math.Abs(newHigh - previousClose);
                double lowCloseRange  = Math.Abs(newLow - previousClose);

                TR = Math.Max(highLowRange, Math.Max(highCloseRange, lowCloseRange));
                ATRValue.Update(TR);
            }

            return(Value);
        }