Ejemplo n.º 1
0
        //cci
        public static void CalculateCCI(out string key, StockPoints data, Dictionary<DateTime, Dictionary<string, double>> indicators, int period, out int offset, out int min, out int max)
        {
            key = string.Format("CCI({0})", period.ToString("00"));
            offset = period - 1;

            min = int.MaxValue;
            max = int.MinValue;

            // cci = (Typical Price  -  20-period SMA of TP) / (.015 x Mean Deviation)
            double cci;

            // Typical Price (TP) = (High + Low + Close)/3
            double typicalPrice;

            double constant = 0.015;

            SimpleMovingAverage sma = new SimpleMovingAverage(period);
            int i = 0;

            foreach (StockPoint point in data)
            {
                typicalPrice = (point.High + point.Close + point.Low) / 3D;
                sma.AddValue(typicalPrice);

                if (i < period - 1)
                {
                    i++;
                }
                else
                {
                    cci = (typicalPrice - sma.MovingAverage())/ (constant * sma.MeanDeviation());
                    AddValue(point.PointDateTime, key, cci, indicators);

                    if (min > cci)
                        min = (int)Math.Floor(cci);

                    if (max < cci)
                        max = (int)Math.Ceiling(cci);
                }
            }
        }