A Simple and Efficient CCI Trading System

Commodity Channel Index (CCI) is an oscillator indicator which accurately identifies overbought or oversold levels. It was developed by Donald Lambert in 1980, and was originally supposed to be used exclusively for commodities trading, but later it found its application in Stocks and Futures as well.  CCI compares current price to the average price for a given time period. If the current price is greater than the average price CCI indicates Overbought condition, while if the current price is less than average price CCI indicates Oversold condition.  CCI value oscillates between two extremes, hence its is particularly useful for Mean reversion Trading systems. However CCI divergence can be used to identify trends too. In this post we’ll go through a very simple CCI Trading System. The results of this system is quite impressive and consistent when backtested on Daily timeframe.

Please visit Trading Tuitions Academy to learn AFL coding and create your own Trading systems.

CCI Trading System – AFL Overview

Parameter Value
Preferred Time-frame
Indicators Used CCI (Commodity Channel Index)
Buy Condition
  • CCI(10) crosses zero line from bottom
  • CCI(10) > CCI(30)
Short Condition
  • CCI(10) crosses zero line from top
  • CCI(10) < CCI(30)
Sell Condition
  • Same as Short
  • Stop Loss Hit
  • Target met
Cover Condition
  • Same as Buy
  • Stop Loss Hit
  • Target met
Stop Loss 2%
Targets 5%
Position Size 150 (fixed)
Initial Equity 200000
Brokerage 100 per order
Margin 10%

CCI Trading System– AFL Code

//  Formula Name:    CCI Trading system
//  Author/Uploader: Trading Tuitions
//  E-mail:          support@tradingtuitions.com
//  Website:         www.tradingtuitions.com

_SECTION_BEGIN("CCI Trading System");

SetBarsRequired( sbrAll );
_N(Title = StrFormat("{{NAME}} – {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));

//Initial Parameters
SetTradeDelays( 1,1,1, 1 );
SetOption( "InitialEquity", 200000);
SetOption("FuturesMode" ,True);
SetOption( "AllowPositionShrinking", True );

Plot( Close, "Price",colorWhite, styleCandle );

Buy = Cross( CCI(CCIFast), 0 ) AND CCI(CCIFast) > CCI(CCISlow) ;
Short = Cross( 0,CCI(CCIFast)) AND CCI(CCIFast) < CCI(CCISlow);



Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);

printf("\nBuy : " + Buy );  
printf("\nSell : " + Sell );  
printf("\nShort : " + Short );  
printf("\nCover : " + Cover );  

PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Buy, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Buy, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorGreen, 0, L, Offset=-40);
PlotShapes(IIf(Cover, shapeSquare, shapeNone),colorLime, 0,L, Offset=-50);
PlotShapes(IIf(Cover, shapeUpArrow, shapeNone),colorWhite, 0,L, Offset=-45);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Sell, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Sell, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorRed, 0, H, Offset=40);
PlotShapes(IIf(Short, shapeSquare, shapeNone),colorOrange, 0,H, Offset=50);
PlotShapes(IIf(Short, shapeDownArrow, shapeNone),colorWhite, 0,H, Offset=-45);


AFL Screenshot

CCI Trading System

CCI Trading System- Backtest Report

CCI Trading system is consistent and its moderate drawdown should be ok for mild aggressive traders. 20% CAGR over last 6 years looks good for long term capital growth.

Parameter Value
Initial Capital 200000
Final Capital 772617.80
Scrip Name NSE Nifty
Backtest Period 01-Jan-2010 to 24-Apr-2017
Timeframe Daily
Net Profit % 286.31%
Annual Return % 20.32%
Number of Trades 99
Winning Trade % 42.42%
Average holding Period 7.88 periods
Max consecutive losses 6
Max system % drawdown -27.43%
Max Trade % drawdown -37.62%

Download the detailed backtest report here.

Equity Curve

The equity curve smoother than most of the trading system we have posted. Periods of mild drawdown are inevitable for any system.

CCI Trading System - Equity Curve

Profit Table

CCI Trading System - Profit Table

Additional Amibroker settings for backtesting

Goto Symbol–>Information, and specify the lot size and margin requirement. The below screenshot shows lot size of 75 and margin requirement of 10% for NSE Nifty:

Symbol Info_Nifty


All the AFL’s posted in this section are for learning purpose. Trading Tuitions does not necessarily own these AFL’s and we don’t have any intellectual property rights on them. We might copy useful AFL’s from public forums and post it in this section in a presentable format. The intent is not to copy anybody’s work but to share knowledge. If you find any misleading or non-reproducible content then please inform us at support@tradingtuitions.com

Related Posts


  1. I’ve AFL get from free trial… but not able to sue without subscription, is it possible to edit by your and make as useful ???

  2. hi admin, can you post some intraday scalping systems ?

  3. isn’t this a repainting indicator?
    The loophole with your strategy is that, you’re assuming all the prices to be OPEN of a particular candle. But CCI crossing a particular point is only obtained during the close of a particular candle right? In that sense, is it not a flawed system?

    • Hi Shravan,

      Since the trade delays is set to 1, the strategy will buy at next days open price. Hope that makes sense?

Leave a Reply

Your email address will not be published.