Skip to main content

Unlocking Stock Market Trends with CCI Trading System

The Commodity Channel Index (CCI) is a powerful tool for spotting overbought or oversold market conditions. Created by the ingenious mind of Donald Lambert in 1980, the CCI was initially designed for commodities but has since been adapted for stocks and futures. It’s a brilliant way to gauge market conditions.

CCI’s approach is straightforward. It compares the current price to the average price over a specific period. If the current price is higher than the average, CCI shouts “Overbought!” If it’s lower, it signals “Oversold!” The CCI scale swings between two extremes, making it valuable for Mean Reversion Trading. But wait, there’s more – CCI divergence can also help identify trends.

CCI Trading System Demystified

We present to you a simplified CCI Trading System. What’s truly remarkable is that this system consistently delivers impressive results, especially when tested on daily charts.

If you’re interested in coding your trading systems using Amibroker Formula Language (AFL), check out our AFL learning resources.

Key Features of the CCI Trading System

Parameter Value
Preferred Timeframe Daily
Indicators Used CCI (Commodity Channel Index)
Buy Conditions
  • CCI(10) crosses above zero from below
  • CCI(10) > CCI(30)
Short Conditions
  • CCI(10) crosses below zero from above
  • CCI(10) < CCI(30)
Sell Conditions
  • Same as Short
  • Stop Loss is triggered
  • Target is achieved
Cover Conditions
  • Same as Buy
  • Stop Loss is triggered
  • Target is achieved
Stop Loss 2%
Targets 5%
Position Size 150 (fixed)
Initial Equity 200,000
Brokerage 100 per order
Margin 10%

CCI Trading System– AFL Code

				
					//------------------------------------------------------
//
//  Formula Name:    CCI Trading system
//  Website:         https://zerobrokerageclub.com/
//------------------------------------------------------
_SECTION_BEGIN("CCI Trading System");
SetBarsRequired( sbrAll );
SetChartOptions(0,chartShowArrows|chartShowDates);
_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("MinShares",1);
SetOption("CommissionMode",2);
SetOption("CommissionAmount",100);
SetOption("AccountMargin",10);
SetOption("RefreshWhenCompleted",True);
SetPositionSize(150,spsShares);
SetOption( "AllowPositionShrinking", True );
Plot( Close, "Price",colorWhite, styleCandle );
CCISlow=Param("CCISlow",30,30,100,10);
CCIFast=Param("CCIFast",10,5,30,5);
Buy = Cross( CCI(CCIFast), 0 ) AND CCI(CCIFast) > CCI(CCISlow) ;
Short = Cross( 0,CCI(CCIFast)) AND CCI(CCIFast) < CCI(CCISlow);
Sell=Short;
Cover=Buy; 
BuyPrice=Open;
SellPrice=Open;
ShortPrice=Open;
CoverPrice=Open;
Buy = ExRem(Buy,Sell);
Sell = ExRem(Sell,Buy);
Short=ExRem(Short,Cover);
Cover=ExRem(Cover,Short);
printf("nBuy : " + Buy );  
printf("nSell : " + Sell );  
printf("nShort : " + Short );  
printf("nCover : " + Cover );  
StopLoss=Param("SL",2,1,10,1);
Target=Param("Target",5,5,40,5);
ApplyStop(Type=0,Mode=1,Amount=StopLoss);
ApplyStop(Type=1,Mode=1,Amount=Target);
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);
_SECTION_END();

				

How to Use the CCI Trading System?

Step 1: Copy the AFL code provided and set it up in your local Amibroker software.

Step 2: Download and set up End-of-Day (EOD) data for your preferred stock exchange.

Step 3: In the Amibroker software, go to the “Analysis” menu and select “Explore.” In the “Range” dropdown, choose “1 recent bar.”

Step 4: In the results, you’ll see the Trend score for each script. A trend score above 5 indicates bullish stocks, while a score below 2 points to bearish stocks.

AFL Screenshot

CCI Trading System

Unlock the CCI Trading System’s Potential – Backtest Report

The CCI Trading System consistently delivers excellent results. With a modest drawdown rate, it’s well-suited for mildly aggressive traders. Achieving a 20% Compound Annual Growth Rate (CAGR) over the last six years bodes well for long-term capital growth.

Parameter Value
Nifty
Initial Capital 200,000
Final Capital 772,617.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.

The equity curve, smoother than most trading systems we’ve seen, experiences periods of mild drawdown, which are par for the course for any system.

Equity Curve

Equity curve for CCI Trading System

Profit Table

Profit Table for CCI Trading System

Optimizing Amibroker Settings for Backtesting

Head to “Symbol” –> “Information” and specify the lot size and margin requirement. The screenshot below shows a lot size of 75 and a margin requirement of 10% for NSE Nifty:

Leave a Reply