예제 #1
0
        /// <summary>
        /// Relatives the index of the strength.
        /// </summary>
        /// <returns>The strength index.</returns>
        /// <param name="candleSticks">Candle sticks.</param>
        /// <param name="period">Period.</param>
        public static RelativeStrengthIndex RelativeStrengthIndex(CandleStickCollection candleSticks, int period = 14,
                                                                  PriceSource priceSource = PriceSource.Close)
        {
            int count = candleSticks.Count;

            double[] priceArray = priceSource.GetArrayFromCandleStickCollection(candleSticks);
            double[] rsi        = new double[count];

            double[] up   = new double[count];
            double[] down = new double[count];
            double[] rs   = new double[count];

            for (int i = 1; i < count; i++)
            {
                if (priceArray[i] > priceArray[i - 1])
                {
                    up[i] = priceArray[i] - priceArray[i - 1];
                }
                else
                {
                    down[i] = priceArray[i - 1] - priceArray[i];
                }
            }

            for (int i = period; i < count; i++)
            {
                rs[i]  = MovingAverages.SMMA(up, period, i - period, period).MA[i] / MovingAverages.SMMA(down, period, i - period, period).MA[i];
                rsi[i] = 100 - 1 / (1 + rs[i]);
            }

            return(new RelativeStrengthIndex(rsi));
        }
예제 #2
0
        public static MovingAverageConvergenceDivergence MACD(CandleStickCollection candleSticks, int fast = 12,
                                                              int slow = 26, int length = 9,
                                                              PriceSource priceSource = PriceSource.Close)
        {
            MovingAverage fastMA = MovingAverages.EMA(candleSticks, fast, priceSource);
            MovingAverage slowMA = MovingAverages.EMA(candleSticks, slow, priceSource);

            double[] macd = fastMA.MA.SubtractArray(slowMA.MA);
            return(new MovingAverageConvergenceDivergence(macd, length));
        }