コード例 #1
0
        public void Add(DateTime TradeDate, decimal HighPrice, decimal LowPrice, decimal Price)
        {
            try
            {
                var trade = new CCISignal()
                {
                    CloseDate = TradeDate, ClosePrice = Price, HighPrice = HighPrice, LowPrice = LowPrice
                };

                trade.TypicalPrice = Math.Round((trade.HighPrice + trade.LowPrice + trade.ClosePrice) / 3, 4);

                if (this.Values.Count >= 19)
                {
                    //calculate SMA
                    decimal sumOfPrices = trade.TypicalPrice;

                    this.Values.GetRange(this.Values.Count - 19, 19).ForEach(i => sumOfPrices += i.TypicalPrice);

                    trade.SMA = Math.Round((double)(sumOfPrices / 20), 4);

                    //calculate MAD
                    double mad = Math.Abs(trade.SMA - (double)trade.TypicalPrice);
                    this.Values.GetRange(this.Values.Count - 19, 19).ForEach(i => mad += Math.Abs(trade.SMA - ((double)i.TypicalPrice)));

                    trade.MAD = Math.Round(mad / 20, 4);

                    //calculate 20-period CCI
                    trade.CCI = Math.Round(((double)trade.TypicalPrice - trade.SMA) / (0.015 * trade.MAD), 4);

                    //calc trend based on the inclination
                    double y1, y2;
                    double x1, x2;

                    x2 = this.Values.Count;
                    x1 = x2 - 19;

                    y2 = this.Values[this.Values.Count - 1].CCI;
                    y1 = this.Values[this.Values.Count - 19].CCI;

                    trade.Inclination = (y2 - y1) / (x2 - x1);

                    trade.UpTrend = trade.Inclination > 0;
                }

                Values.Add(trade);

                if (this.Values.Count >= 19)
                {
                    IndicatorReady?.Invoke(this, trade);
                }
            }
            catch (Exception ex)
            {
                if (this.OnError != null)
                {
                    OnError(this, ex.Message);
                }
            }
        }
コード例 #2
0
        private static void tickerHndl_CCI_IndicatorReady(object sender, CCISignal e)
        {
            Console.ForegroundColor = ConsoleColor.Gray;

            if (!e.UpTrend && (e.CCI <= -100))
            {
                //bearishing
                Console.ForegroundColor = ConsoleColor.Red;
            }

            if (e.UpTrend && (e.CCI >= 100))
            {
                //bullishing
                Console.ForegroundColor = ConsoleColor.Green;
            }

            Console.WriteLine($"{e.CloseDate.ToString("HH:mm:ss")} Last Trade: {e.ClosePrice} - CCI: {e.CCI}");
        }
コード例 #3
0
 private void calculateCCI(CCISignal trade)
 {
 }
コード例 #4
0
 private void _cci_IndicatorReady(object sender, CCISignal e)
 {
     CCIReady(this, e);
 }