September 25

0 comments

Crafting a Winning NG Futures Strategy with CCI and Build Alpha

By Jeff Swanson

September 25, 2023

Algorithmic Trading, Automated Trading Development, Build Alpha, EasyLanguage, no-code

About 16 years ago, I stumbled upon the world of trading, and it was a rollercoaster of emotions and experiences. Fast forward to today, and I've discovered yet another intriguing facet of trading: the Commodity Channel Index (CCI). Inspired by a thought-provoking YouTube channel from StatOasis, I felt the urge to explore the CCI's potential in the realm of natural gas futures. And, as always, I wanted to share this journey with you, my fellow traders.

Now, I'm sure many of you have dabbled with the CCI in your trading adventures. But have you ever considered building an entire strategy around it? That's precisely what we're about to do. With the help of Build Alpha, a tool I've come to trust over the years, we'll construct, refine, and put to the test a CCI-centric strategy tailored for the NG futures market.

For those of you who've been with me since the early days of my trading journey, you know the drill. We're going to dissect the CCI, understand its nuances, and then dive deep into the mechanics of strategy development. Whether you're a seasoned trader or just starting your algorithmic trading journey, I promise this exploration will be packed with insights and actionable takeaways.

So, let's roll up our sleeves and get started. Together, we'll navigate the intricacies of the CCI and the dynamic world of natural gas futures. Ready to embark on another trading adventure with me?

Understanding the Commodity Channel Index (CCI)

Years ago, when I first dipped my toes into the vast ocean of trading, I was overwhelmed by the sheer number of technical indicators available. Some were straightforward, while others seemed wrapped in layers of complexity. Among them, the Commodity Channel Index, or CCI as it's commonly known, caught my attention. And today, I want to pull back the curtain on this fascinating indicator.

A Brief History of the CCI

The CCI was introduced by Donald Lambert back in the late 1970s. Originally designed for the commodities market, its primary goal was to identify cyclical turns in commodities. But, as with many things in trading, its application soon expanded beyond its initial intent. Today, traders use the CCI across various asset classes, from stocks to forex and, of course, futures.

The Mechanics Behind the CCI

At its core, the CCI measures the current price level relative to an average price level over a specific period. Think of it as a tool that gauges how far the price has deviated from its average. A high CCI indicates prices are above their average, which can signify an overbought condition. Conversely, a low CCI suggests prices are below their average, hinting at an oversold condition.

Now, I know what some of you might be thinking: "Jeff, this sounds a lot like other oscillators!" And you're not wrong. But the CCI has its unique quirks and nuances. For instance, it uses the typical price (the average of high, low, and close) for its calculations rather than just the closing price. This gives it a slightly different flavor compared to some other indicators.

Interpreting the CCI

The CCI oscillates around a zero line. Traditionally, a reading above +100 indicates an overbought condition, suggesting a potential price reversal to the downside. On the flip side, a reading below -100 signals an oversold condition, hinting at a possible upward price move.

But here's a nugget of wisdom from my years of trading: while these traditional levels can be useful, they aren't set in stone. Different markets and different timeframes can exhibit varying behaviors. Sometimes, I've found it beneficial to adjust these thresholds to better suit the specific market conditions I'm trading in.

The Basic CCI Strategy

In the StatOasis video, the core of the strategy is to go short when the 8-period CCI rises above 130. A profit target of 2 times ATR and a stop loss of 4 times ATR are used to exit the trade.

If we code this up in EasyLanguage, we get the following results when applied to the daily chart of the natural gas futures market (@NG).

CCI Basic Strategy EQ Curve

CCI Basic Strategy EQ Curve

CCI Basic Strategy Report

CCI Basic Strategy Report

Note, these results do not take into account slippage or commissions.

The results are a great starting point. We have a rising equity curve and it's a profitable system. I think this demonstrates the CCI might be a good signal for going short the @NG market. Now, we want to improve our basic strategy.

We want to look for filters we can add to this strategy to improve it. We could use our EasyLanguage skills to test different filters, such as moving averages, volume, or price patterns, but that would take a long time. How can we do it faster?

We can use a tool like Build Alpha.

Building the CCI Strategy with Build Alpha

At its core, Build Alpha is a robust, automated strategy development platform. But to label it just as such would be an understatement. It's more like a Swiss Army knife for traders, offering a suite of features that cater to both novices and seasoned professionals.

Build Alpha is designed to assist traders in creating, testing, and optimizing trading strategies. But what sets it apart is its ability to do so without any programming knowledge required. That's right – you can craft intricate, data-driven strategies without writing a single line of code. Read more about Build Alpha here, Creating Strategies Using Build Alpha.

We have our basic CCI strategy, but we want to test different filters on our strategy. Writing the code to test additional filters will take a lot of time. However, with Build Alpha, we can "program" basic CCI strategy into software and have it search over 4,000 additional filters in a few minutes.

In Build Alpha, I "code" our basic CCI strategy with a few mouse clicks. I added the CCI trigger.

CCI Basic Strategy Configure CCI

CCI Basic Strategy Configure CCI

Next, I want to tell Build Alpha to search for an additional entry condition to act as a filter. Build Alpha has access to over 4,000 different indicators that will serve as a filter.

CCI Basic Strategy Configure Signals

CCI Basic Strategy Configure Signals

I then added my Stop Loss and Profit Target. I then also tell Build Alpha to test different ATR profit target values and ATR stop values. For example, it will explore 2xATR, 3xATR, and 4xATR for the profit target. 

CCI Basic Strategy Configure Stops & Targets

CCI Basic Strategy Configure Stops & Targets

Next, I also want to test another type of exit, and that's a maximum hold time limit. I will have Build Alpha hold for a maximum of 1, 2, or 3 days. I'm also going to set the out-of-sample to 50% of this historical data.

CCI Basic Strategy Configure OOS

CCI Basic Strategy Configure OOS

Finally, we tell Build Alpha what dates we will use for our in-sample, out-of-sample, and Validation. Did you catch that? When building strategies, you must use in-sample and out-of-sample. However, when I use a tool like Build Alpha, I like to include a third segment called Validation. This is simply a segment of history that Build Alpha does not have access to. 

I will use data from 2000-01-01 to 2020-12-31 as data for Build Alpha to use. The in-sample will be 50% of this and the out-of-sample will be the remainder.

I'm going to do something a little different. I will have Build Alpha build our strategy on the most recent price data and use the out-of-sample as the most distant price data. This is different than a lot of other people do. Traditionally, the out-of-sample data segment is the most recent. I like to have Build Alpha build on the most recent price history.

CCI Basic Strategy Configure Hisorical Data Segments

CCI Basic Strategy Configure To Use out-of-sample at Beginning of historical data


We're about ready for Build Alpha to work its magic. Below is what we have Build Alpha testing for:

  • Additional Filter
  • Profit Target ATR multiple
  • Stop Loss ATR multiple
  • Max hold 1, 2 or 3 bars

Now, we press a button and let Build Alpha work its magic.

Build Alpha Results

CCI Basic Strategy Simulation Results

CCI Basic Strategy Simulation Results

Enter your text here...The highlight light blue color is the out-of-sample. Notice that the out-of-sample occurs on the first 60 trades or so. But it looks good!

CCI Basic Strategy Simulation EQ

CCI Basic Strategy Simulation EQ

Introducing The NG CCI Alchemy Trading Systems

So, what filter did Build Alpha discover as a great filter? It's straightforward. It a moving average filter. Here is the EasyLanguage code:

  average(close,200)[0] < average(close,200)[3]

We're using a 200-bar simple moving average, and today's value must be lower than three days ago. This is the filter applied to our basic CCI strategy. 

Build Alpha also determined our stop and profit target multiples as:

  • Profit Target Multiple: 2 times daily 20-period ATR
  • Stop Loss Multiple: 3 times daily 20-period ATR

The last value optimized was the maximum hold time, which is three. Thus, we close our trades after holding for three days.

I then named this strategy the NG CCI Alchemy Strategy. Why that name? Nothing particular. I just wanted to give it a unique name so it's easier to reference. 

Build Alpha discovered this simple moving average filter and all our parameters within a few minutes of searching. Our out-of-sample equity curve looks good. Now it's time to validate our strategy to help ensure it's not curve fit to the historical data.


Build Alpha Validation

One of the excellent ways Build Alpha helps you avoid curve fitting is by comparing your strategy to randomly generated strategies. During the development phase, Build Alpha will develop thousands of random strategies based on your chosen signals. The performance of these random strategies will be collected, and they act as a baseline helping you discern whether your final generated strategies will perform better than random.

If your final strategy is based upon random chance (curve-fit), it will likely look indistinguishable from the other random strategies. However, if your strategy performs better than the thousands of random strategies, your strategy may possess some edge more significant than could be found by random chance. This is a test from Jaffray Woodriff's chapter 5 in Hedge Fund Market Wizards.

Below are two of my favorite robustness tests within Build Alpha to help quickly locate strategies that might be overfitted to the historical data. They are, Variance Testing and Noise Testing.

Let's apply these two tests to our new CCI Strategy. We'll be using a $100,000 account size and define a ruin level of $40,000. This means if few ever lose more than $40,000 from our starting capital, we'll say the strategy failed (ruin).

Here are the tests in detail.

Variance Testing: This unique test simulates how well a trading strategy should do over the following N trades. It creates hypothetical equity curves into the future based on the distribution of the backtest results. This type of stress testing can help determine if a strategy has an unrealistic backtest or is part of a stable distribution poised to perform near desired expectations moving forward.

CCI Basic Strategy Simulation Variance Test

CCI Basic Strategy Simulation Variance Test

Here we can see the Variance Testing is producing hypothetical equity curves into the future. Notice they are all in positive territory. This is good! We can also see in the numbers below that the graph of our Risk of Ruin is below 1%. This is a great sign that our strategy is robust and may work on the live market.

Noise Test: This test introduces noise to the price data. Noise is accomplished by slightly changing some of the open, high, low, and close values. Build Alpha then re-trades the selected strategy on 1,000 newly generated price series with varying amounts of noise. The idea is to see if the noise in the data crashes our strategy or does it continue to do OK.

CCI Basic Strategy Simulation Noise Test

CCI Basic Strategy Simulation Noise Test

Our strategy is represented as the Blue Line. When we add noise to the price data we can see our equity curve shifts above the blue line and below the blue line. Notice all the equity curves remain profitable. This is another good sign that our strategy is robust. 

My Final Validation

Remember when I told you I like to break my historical data into three segments?

  1. In-sample
  2. Out-of-sample
  3. Validation

Well, now it's time for the final test. I want to take the strategy created in Build Alpha and apply to my Validation data segment. This is price data that was not used during the development of the strategy in Build Alpha. It's completely unseen data.

To test my strategy on the Validation segment, I'm going to have Build Alpha generate the EasyLanguage code. I will then import that code into TradeStation and see how the strategy performs on this unseen data.

Let's generate the code. We do that with a push of a button!

CCI Basic Strategy Simulation Generate EL Code

CCI Basic Strategy Simulation Generate EL Code

Below is the equity curve of the strategy on the validation segment. Remember, this is unseen data. 

The equity curve looks great! This is showing about $20,000 in profit with 31 trades. That's about $655 per trade. The drawdown is $4,870 giving us a NP/DD ratio of 4.1, which is excellent.

Summary and Conclusion: Harnessing the Power of CCI and Build Alpha for NG Futures Trading

In our exploration today, we've journeyed through the intricacies of the Commodity Channel Index (CCI) and delved into some of capabilities of Build Alpha. From understanding the mathematical underpinnings of the CCI to appreciating the robust features of Build Alpha, we've covered significant ground.

We also developed what appears to be a fully working algorithmic strategy for the NG market. Do you want a copy of the code? Jump to the bottom of this article to see how to get a copy.

The CCI, with its roots in the commodities market, offers traders a unique lens to view market momentum and potential price reversals. Its adaptability across various asset classes, including the NG futures market, makes it a versatile tool in a trader's arsenal. But as with any indicator, its true potential shines when integrated into a comprehensive trading strategy.

Enter Build Alpha, a game-changer in the realm of algorithmic trading. Its ability to craft, test, and optimize strategies without the need for programming is nothing short of revolutionary. For traders like us, who are constantly seeking an edge in the markets, Build Alpha provides the tools and framexwork to turn our trading ideas into actionable strategies.

As we wrap up, I want to leave you with a few thoughts. The world of trading is ever-evolving, with new tools and techniques emerging regularly. But the core principles remain the same: knowledge, discipline, and continuous learning. The CCI and Build Alpha are just two pieces of the puzzle. It's up to us, the traders, to fit these pieces together, creating a trading mosaic that aligns with our goals and risk tolerance.

Thank you for joining me on this exploration. I hope you've found it enlightening and that it sparks further curiosity and experimentation in your trading journey. Remember, at EasyLanguage Mastery, our mission is to empower you with the knowledge and tools to excel in the world of algorithmic trading. Let's continue this journey together, one trade at a time.

Get A Copy of Build Alpha

You can get a copy of Build Alpha over at the Build Alpha website. Let them know you read about Build Alpha here at EasyLanguage Mastery.

Let Me Show You How To Use Build Alpha

I have an exciting announcement for those eager to elevate their trading game with Build Alpha. Introducing the Alpha Compass course – a meticulously crafted program designed to navigate you through the complexities of Build Alpha. Whether you're a novice finding your way or an experienced trader aiming to refine your strategies, the Alpha Compass well help.

Enrollment is open this week! However, do note that doors close on Thursday, September 28th.

Click Here To Learn More

Here are some Build Alpha links

Jeff Swanson

About the author

Jeff has built and traded automated trading systems for the futures markets since 2008. He is the creator of the online courses System Development Master Class and Alpha Compass. Jeff is also the founder of EasyLanguage Mastery - a website and mission to empower the EasyLanguage trader with the proper knowledge and tools to become a profitable trader.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

Learn To Code & Build Strategies
Using EasyLanguage. 

>