public override void ResetsProperly()
        {
            var cci = new CommodityChannelIndex(2);

            cci.Update(new TradeBar
            {
                Symbol = Symbols.SPY,
                Time   = DateTime.Today,
                Open   = 3m,
                High   = 7m,
                Low    = 2m,
                Close  = 5m,
                Volume = 10
            });
            Assert.IsFalse(cci.IsReady);
            cci.Update(new TradeBar
            {
                Symbol = Symbols.SPY,
                Time   = DateTime.Today.AddSeconds(1),
                Open   = 3m,
                High   = 7m,
                Low    = 2m,
                Close  = 5m,
                Volume = 10
            });
            Assert.IsTrue(cci.IsReady);

            cci.Reset();
            TestHelper.AssertIndicatorIsInDefaultState(cci);
            TestHelper.AssertIndicatorIsInDefaultState(cci.TypicalPriceAverage);
            TestHelper.AssertIndicatorIsInDefaultState(cci.TypicalPriceMeanDeviation);
        }
Example #2
0
		protected override void Initialize()
		{
			trendMagic = Robot.Indicators.GetIndicator<TrendMagicIndicator>(TmCciPeriod, TmAtrPeriod);
			_cci = Robot.Indicators.CommodityChannelIndex(TmCciPeriod);


		}
Example #3
0
        public void ResetsProperly()
        {
            var cci = new CommodityChannelIndex(2);

            cci.Update(DateTime.Today, new TradeBarValue {
                Open   = 3d,
                High   = 7d,
                Low    = 2d,
                Close  = 5d,
                Volume = 10
            });
            Assert.IsFalse(cci.IsReady);
            cci.Update(DateTime.Today.AddSeconds(1), new TradeBarValue {
                Open   = 3d,
                High   = 7d,
                Low    = 2d,
                Close  = 5d,
                Volume = 10
            });
            Assert.IsTrue(cci.IsReady);

            cci.Reset();
            TestHelper.AssertIndicatorIsInDefaultState(cci);
            TestHelper.AssertIndicatorIsInDefaultState(cci.TypicalPriceAverage);
            TestHelper.AssertIndicatorIsInDefaultState(cci.TypicalPriceMeanDeviation);
        }
        public void ResetsProperly()
        {
            var cci = new CommodityChannelIndex(2);

            cci.Update(new TradeBar
            {
                Ticker   = Props.TickerSymbol,
                Occured  = DateTime.Today,
                Open     = 3m,
                High     = 7m,
                Low      = 2m,
                Close    = 5m,
                Volume   = 10,
                TimeZone = TimeZone.Utc
            });
            Assert.False(cci.IsReady);
            cci.Update(new TradeBar
            {
                Ticker   = Props.TickerSymbol,
                Occured  = DateTime.Today.AddSeconds(1),
                Open     = 3m,
                High     = 7m,
                Low      = 2m,
                Close    = 5m,
                Volume   = 10,
                TimeZone = TimeZone.Utc
            });
            Assert.True(cci.IsReady);

            cci.Reset();
            TestHelper.AssertIndicatorIsInDefaultState(cci);
            TestHelper.AssertIndicatorIsInDefaultState(cci.TypicalPriceAverage);
            TestHelper.AssertIndicatorIsInDefaultState(cci.TypicalPriceMeanDeviation);
        }
Example #5
0
        //******************************************

        protected override void Initialize()
        {
            //**************************************
            LR_Slope = Indicators.LinearRegressionSlope(MarketSeries.Close, 12);
            MA20     = Indicators.ExponentialMovingAverage(MarketSeries.Close, 20);
            MA50     = Indicators.ExponentialMovingAverage(MarketSeries.Close, 50);
            MA100    = Indicators.ExponentialMovingAverage(MarketSeries.Close, 100);

            LTF_Candle = MarketData.GetSeries(LTF);
            MTF_Candle = MarketData.GetSeries(MTF);
            STF_Candle = MarketData.GetSeries(STF);
            //**************************************

            ///////////////////////////////////////////////////////////

            // Initialize and create nested indicators

            MA = Indicators.MovingAverage(MarketSeries.Close, MA_Periods, MovingAverageType.Exponential);
            // Initalize RSI
            RSI = Indicators.RelativeStrengthIndex(MarketSeries.Close, RSI_Periods);

            // Initalize CCI
            CCI = Indicators.CommodityChannelIndex(MarketSeries, CCI_Periods);

            thecount = MarketSeries.Close.Count;
            Print("theCount = " + thecount);
        }
Example #6
0
 protected override void Initialize()
 {
     // Initialize and create nested indicators
     CCI = Indicators.CommodityChannelIndex(CCI_Period);
     atr = CreateDataSeries();
     tr = CreateDataSeries();
     tri = Indicators.TrueRange();
 }
Example #7
0
        /// <summary>
        /// Creates a new CommodityChannelIndex indicator. The indicator will be automatically
        /// updated on the given resolution.
        /// </summary>
        /// <param name="symbol">The symbol whose CCI we want</param>
        /// <param name="period">The period over which to compute the CCI</param>
        /// <param name="movingAverageType">The type of moving average to use in computing the typical price averge</param>
        /// <param name="resolution">The resolution</param>
        /// <param name="selector">Selects a value from the BaseData to send into the indicator, if null defaults to casting the input value to a TradeBar</param>
        /// <returns>The CommodityChannelIndex indicator for the requested symbol over the specified period</returns>
        public CommodityChannelIndex CCI(string symbol, int period, MovingAverageType movingAverageType = MovingAverageType.Simple, Resolution?resolution = null, Func <BaseData, TradeBar> selector = null)
        {
            var name = CreateIndicatorName(symbol, "CCI" + period, resolution);
            var cci  = new CommodityChannelIndex(name, period, movingAverageType);

            RegisterIndicator(symbol, cci, resolution, selector);
            return(cci);
        }
Example #8
0
 protected override void Initialize()
 {
     // Initialize and create nested indicators
     CCI = Indicators.CommodityChannelIndex(CCI_Period);
     atr = CreateDataSeries();
     tr  = CreateDataSeries();
     tri = Indicators.TrueRange();
 }
Example #9
0
        public override void Initialize()
        {
            SetCash(10000);
            SetStartDate(2007, 1, 1);
            SetEndDate(DateTime.Now);

            // Request SPY data with minute resolution
            AddSecurity(SecurityType.Equity, Symbol, Resolution.Daily);

            _ama = new KaufmanAdaptiveMovingAverage(Symbol, 5);

            _cci = new CommodityChannelIndex(5, MovingAverageType.Kama);

            _atr = new AverageTrueRange(Symbol, 14, MovingAverageType.Kama);

            SetWarmup(3);
        }
Example #10
0
        protected override void Init()
        {
            _period = Timeframe;
            commodt = Instrument.Name;

            CCIindSlow = GetIndicator <CommodityChannelIndex>(
                Instrument.Id,
                _period,
                A_period,
                _priceMode
                );

            CCIindFast = GetIndicator <CommodityChannelIndex>(
                Instrument.Id,
                _period,
                B_period,
                _priceMode
                );
        }
Example #11
0
        protected override void OnStart()
        {
            base.OnStart();
            botLabel = string.Format("{0}-{1} {2}", botPrefix, Symbol.Code, TimeFrame);

            Print(this.botName());


            wpr = Indicators.GetIndicator <WilliamsPercentRange>(wprSource, wprPeriod, wprOverbuyCeil, wprOversellCeil, WprMagicNumber, wprMinMaxPeriod, wprExceedMinMax);

            // ZigZag Kwan MBFX Timing ou Beta
            zigzagKwanMBFXTiming = Indicators.GetIndicator <ZigzagKwanMBFXTiming>(mbfxLen, mbfxFilter);

            zigZag = Indicators.GetIndicator <ZigZag>(ZzDepth, ZzDeviation, ZzBackStep);

            trendMagic = Indicators.GetIndicator <TrendMagic>(TMCciPeriod, TMAtrPeriod);

            _cci = Indicators.CommodityChannelIndex(TMCciPeriod);

            Positions.Opened += OnPositionOpened;
            Positions.Closed += OnPositionClosed;
        }
 protected override void OnStart()
 {
     _cci = Indicators.CommodityChannelIndex(Periods);
 }
        public void ComparesAgainstExternalData()
        {
            var cci = new CommodityChannelIndex(14);

            TestHelper.TestIndicator(cci, "spy_with_cci.txt", "Commodity Channel Index (CCI) 14", 1e-2);
        }
Example #14
0
 protected override void Initialize()
 {
     cci = Indicators.CommodityChannelIndex(CciPeriod);
 }
Example #15
0
 protected override void Initialize()
 {
     cci = Indicators.CommodityChannelIndex(CciPeriod);
 }
Example #16
0
 public CCISignal(CommodityChannelIndex cci, SecurityHolding securityHolding)
 {
     _cci             = cci;
     _securityHolding = securityHolding;
 }
Example #17
0
 protected override void Initialize()
 {
     trendMagic = Robot.Indicators.GetIndicator <TrendMagicIndicator>(TmCciPeriod, TmAtrPeriod);
     _cci       = Robot.Indicators.CommodityChannelIndex(TmCciPeriod);
 }
Example #18
0
 protected override void Initialize()
 {
     cci = Indicators.CommodityChannelIndex(Period);
     value1 = CreateDataSeries();
 }
Example #19
0
 protected override void OnStart()
 {
     _cci = Indicators.CommodityChannelIndex(Periods);
 }
Example #20
0
        public override void Calculate(IDataSet dataSet)
        {
            DataSet = dataSet;

            // Reading the parameters
            var basePrice       = (BasePrice)IndParam.ListParam[2].Index;
            var referencePeriod = (int)IndParam.NumParam[2].Value;
            int previous        = IndParam.CheckParam[0].Checked ? 1 : 0;

            // Calculation

            // ---------------------------------------------------------
            var cci = new CommodityChannelIndex();

            cci.Initialize(SlotType);
            cci.IndParam.ListParam[1].Index    = IndParam.ListParam[1].Index;
            cci.IndParam.ListParam[2].Index    = IndParam.ListParam[2].Index;
            cci.IndParam.NumParam[0].Value     = IndParam.NumParam[0].Value;
            cci.IndParam.NumParam[2].Value     = IndParam.NumParam[1].Value;
            cci.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked;
            cci.Calculate(DataSet);

            double[] indicatorMa = MovingAverage(referencePeriod, previous, MAMethod.Simple, cci.Component[0].Value);
            double[] marketMa    = MovingAverage(referencePeriod, previous, MAMethod.Simple, Price(basePrice));
            // ----------------------------------------------------------

            int firstBar = cci.Component[0].FirstBar + referencePeriod + 2;
            var cd       = new double[Bars];

            if (IndParam.ListParam[0].Text == "Convergence")
            {
                for (int bar = firstBar; bar < Bars; bar++)
                {
                    cd[bar] = IsConvergence(indicatorMa, marketMa, bar);
                }
            }
            else if (IndParam.ListParam[0].Text == "Divergence")
            {
                for (int bar = firstBar; bar < Bars; bar++)
                {
                    cd[bar] = IsDivergence(indicatorMa, marketMa, bar);
                }
            }

            // Saving the components
            Component = new IndicatorComp[4];

            Component[0] = new IndicatorComp
            {
                CompName   = "CCI",
                DataType   = IndComponentType.IndicatorValue,
                ChartType  = IndChartType.Line,
                ChartColor = Color.RoyalBlue,
                FirstBar   = firstBar,
                Value      = cci.Component[0].Value
            };

            Component[1] = new IndicatorComp
            {
                CompName   = "CCI MA",
                DataType   = IndComponentType.IndicatorValue,
                ChartType  = IndChartType.Line,
                ChartColor = Color.Red,
                FirstBar   = firstBar,
                Value      = indicatorMa
            };

            Component[2] = new IndicatorComp
            {
                ChartType = IndChartType.NoChart,
                FirstBar  = firstBar,
                Value     = cd
            };

            Component[3] = new IndicatorComp
            {
                ChartType = IndChartType.NoChart,
                FirstBar  = firstBar,
                Value     = cd
            };

            // Sets the Component's type
            if (SlotType == SlotTypes.OpenFilter)
            {
                Component[2].DataType = IndComponentType.AllowOpenLong;
                Component[2].CompName = "Is long entry allowed";
                Component[3].DataType = IndComponentType.AllowOpenShort;
                Component[3].CompName = "Is short entry allowed";
            }
            else if (SlotType == SlotTypes.CloseFilter)
            {
                Component[2].DataType = IndComponentType.ForceCloseLong;
                Component[2].CompName = "Close out long position";
                Component[3].DataType = IndComponentType.ForceCloseShort;
                Component[3].CompName = "Close out short position";
            }
        }
Example #21
0
 protected override void OnStart()
 {
     i_MACD  = Indicators.MacdHistogram(MarketSeries.Close, (int)_MACD_Slow_EMA, (int)_MACD_Fast_EMA, (int)_MACD_Signal);
     i_CCI_0 = Indicators.CommodityChannelIndex((int)_CCI_Period);
     i_CCI_1 = Indicators.CommodityChannelIndex((int)_CCI_Period);
 }
Example #22
0
 protected override void Initialize()
 {
     cci    = Indicators.CommodityChannelIndex(Period);
     value1 = CreateDataSeries();
 }
Example #23
0
 protected override void Initialize()
 {
     cci     = Indicators.CommodityChannelIndex(CCI_period);
     cciline = Indicators.CommodityChannelIndex(CCI_period);
 }
Example #24
0
        public override void Calculate(IDataSet dataSet)
        {
            DataSet = dataSet;

            // Reading the parameters
            var maMethod  = (MAMethod)IndParam.ListParam[2].Index;
            var periodCci = (int)IndParam.NumParam[0].Value;
            var periodMa  = (int)IndParam.NumParam[1].Value;
            var level     = (int)IndParam.NumParam[2].Value;
            int previous  = IndParam.CheckParam[0].Checked ? 1 : 0;

            SpecialValues = new double[] { -level, level };

            // Calculation
            int firstBar = periodCci + periodMa + 2;

            var cciIndicator = new CommodityChannelIndex();

            cciIndicator.Initialize(SlotType);
            cciIndicator.IndParam.ListParam[1].Index    = IndParam.ListParam[1].Index;
            cciIndicator.IndParam.ListParam[2].Index    = IndParam.ListParam[3].Index;
            cciIndicator.IndParam.NumParam[0].Value     = IndParam.NumParam[0].Value;
            cciIndicator.IndParam.CheckParam[0].Checked = IndParam.CheckParam[0].Checked;
            cciIndicator.Calculate(DataSet);

            double[] cci      = cciIndicator.Component[0].Value;
            double[] maCci    = MovingAverage(periodMa, 0, maMethod, cci);
            double[] buyZone  = new double[Bars];
            double[] sellZone = new double[Bars];

            for (int bar = firstBar; bar < Bars; bar++)
            {
                if (buyZone[bar - 1] > Epsilon && maCci[bar] < -level)
                {
                    // Continue Buy zone
                    buyZone[bar] = 1;
                    continue;
                }

                if (sellZone[bar - 1] > Epsilon && maCci[bar] > level)
                {
                    // Continue Sell zone
                    sellZone[bar] = 1;
                    continue;
                }

                if (cci[bar] > maCci[bar] + Epsilon && cci[bar - 1] <= maCci[bar - 1] &&
                    maCci[bar] < -level)
                {
                    // Start Buy zone
                    buyZone[bar] = 1;
                    continue;
                }

                if (cci[bar] < maCci[bar] - Epsilon && cci[bar - 1] >= maCci[bar - 1] &&
                    maCci[bar] > level)
                {
                    // Start Sell zone
                    sellZone[bar] = 1;
                }
            }

            // Shift signal if it is necessary
            if (previous > 0)
            {
                for (int bar = Bars - 1; bar >= firstBar; bar--)
                {
                    buyZone[bar]  = buyZone[bar - 1];
                    sellZone[bar] = sellZone[bar - 1];
                }
            }

            // Saving the components
            Component = new IndicatorComp[4];

            Component[0] = new IndicatorComp
            {
                CompName   = "CCI",
                DataType   = IndComponentType.IndicatorValue,
                ChartType  = IndChartType.Line,
                ChartColor = Color.RoyalBlue,
                FirstBar   = firstBar,
                Value      = cci
            };

            Component[1] = new IndicatorComp
            {
                CompName   = "MA CCI",
                DataType   = IndComponentType.IndicatorValue,
                ChartType  = IndChartType.Line,
                ChartColor = Color.Red,
                FirstBar   = firstBar,
                Value      = maCci
            };

            Component[2] = new IndicatorComp
            {
                ChartType = IndChartType.NoChart,
                FirstBar  = firstBar
            };

            Component[3] = new IndicatorComp
            {
                ChartType = IndChartType.NoChart,
                FirstBar  = firstBar
            };

            // Sets the Component's type
            if (SlotType == SlotTypes.OpenFilter)
            {
                Component[2].DataType = IndComponentType.AllowOpenLong;
                Component[2].CompName = "Is long entry allowed";
                Component[2].Value    = buyZone;
                Component[3].DataType = IndComponentType.AllowOpenShort;
                Component[3].CompName = "Is short entry allowed";
                Component[3].Value    = sellZone;
            }
            else if (SlotType == SlotTypes.CloseFilter)
            {
                Component[2].DataType = IndComponentType.ForceCloseLong;
                Component[2].CompName = "Close out long position";
                Component[2].Value    = sellZone;
                Component[3].DataType = IndComponentType.ForceCloseShort;
                Component[3].CompName = "Close out short position";
                Component[3].Value    = buyZone;
            }
        }
Example #25
0
        /// <summary>
        /// Initialize test
        /// </summary>
        public TestIndicatorCommodityChannelIndex()
        {
            DataStream stream = new OHLCBarStream(new ForexSecurity("EURUSD"), BarInterval.FiveMin);

            _sut = new CommodityChannelIndex(Period, stream.DefaultInterval, stream);
        }
Example #26
0
		protected override void OnStart()
		{
			base.OnStart();
			botLabel = string.Format("{0}-{1} {2}", botPrefix, Symbol.Code, TimeFrame);

			Print(this.botName());


			wpr = Indicators.GetIndicator<WilliamsPercentRange>(wprSource, wprPeriod, wprOverbuyCeil, wprOversellCeil, WprMagicNumber, wprMinMaxPeriod, wprExceedMinMax);
			
			// ZigZag Kwan MBFX Timing ou Beta
			zigzagKwanMBFXTiming = Indicators.GetIndicator<ZigzagKwanMBFXTiming>(mbfxLen, mbfxFilter);

			zigZag = Indicators.GetIndicator<ZigZag>(ZzDepth, ZzDeviation, ZzBackStep);

			trendMagic = Indicators.GetIndicator<TrendMagic>(TMCciPeriod, TMAtrPeriod);

			_cci = Indicators.CommodityChannelIndex(TMCciPeriod);

			Positions.Opened += OnPositionOpened;
			Positions.Closed += OnPositionClosed;
		}