People are going crazy about algo trading, thanks to the extremely ambitious stories on the internet. But one thing that stood out for me is that almost 90% of these stories are about creating algo trading strategies for stocks. In reality, stocks are not the only viable option in the market. In fact, there are better alternatives for a lot of scenarios.
Keeping that in mind, today, we’ll be focusing on creating an algo trading strategy to trade commodities. We’ll first gain some background about our trading strategy along with the technical indicator we’re going to use in our strategy. Then, we’ll move on to the coding part where we’ll be extracting FinancialModelingPrep’s (FMP) end-of-day commodities data and backtesting the trading strategy on the same.
It’s going to be an exciting journey and without further ado, let’s dive into the article!
As regards the choice of commodity, we are going to go with a highly-traded agricultural commodity. Why agri commodities? It’s because it’s less volatile which gives us a lot of room to capitalize on that characteristic. So, we’ll be going with Wheat as our choice of commodity.
Coming to the trading strategy, we are going to create one using a technical indicator that better handles the less volatile or choppy market of agri commodities. In that case, it’s best to go with any one of the Volatility indicators since they are highly capable of signaling entries and exits in a sideways market.
So, we are going to create a strategy using a popular indicator known as the Keltner Channel, and here are the strategy conditions for entry and exit:
- We enter the market if: the close price crosses below the Keltner Channel lower band.
- We exit the market if: the close price crosses above the Keltner Channel upper band.
This is honestly a very generic strategy but sometimes, it’s better to keep it simple instead of overcomplicating things.
I know you might wondering about what these lower and upper bands are, and what actually is Keltner Channel. Don’t worry, in the next section, we are going in-depth about this specific indicator to know its ins and outs. It will also make you feel comfortable working with this indicator and enable you to create your own strategies.
I know you might be thinking about where this indicator came from all of a sudden. The thing is, this indicator plays a very important role in the calculation of the Keltner Channel. So it is essential to know what the Average True Range (ATR) is.
Founded by Wilder Wiles (creator of the most popular indicator, the RSI), the Average True Range is a technical indicator that measures how much an asset moves on average. It is a lagging indicator meaning that it takes into account the historical data of an asset to measure the current value but it’s not capable of predicting the future data points. This is not considered a drawback while using ATR as it’s one of the indicators to track the volatility of a market more accurately. Along with being a lagging indicator, ATR is also a non-directional indicator meaning that the movement of ATR is inversely proportional to the actual movement of the market.
To calculate ATR, it is requisite to follow two steps:
- Calculate True Range (TR): A True Range of an asset is calculated by taking the greatest values of three price differences which are: market high minus market low, market high minus previous market close, and previous market close minus market low. It can be represented as follows:
MAX [ {HIGH - LOW}, {HIGH - P.CLOSE}, {P.CLOSE - LOW} ]where,
MAX = Maximum values
HIGH = Market High
LOW = Market Low
P.CLOSE = Previous market close
- Calculate ATR: The calculation for the Average True Range is simple. We just have to take a smoothed average of the previously calculated True Range values for a specified number of periods. The smoothed average is not just any SMA or EMA but its own type of smoothed average created by Wilder Wiles himself which is nothing but subtracting one from the Exponential Moving Average of the True Range for a specified number of periods and multiplying the difference with two. The calculation of ATR for a specified number of periods can be represented as follows:
ATR N = EMA N [ TR ] - 1 * 2where,
ATR N = Average True Range of 'N' period
SMA N = Simple Moving Average of 'N' period
TR = True Range
While using ATR as an indicator for trading purposes, traders must ensure that they are more cautious than ever as the indicator is very lagging. Now that we have an understanding of what the Average True Range is all about, let’s dive into the main concept of this article, the Keltner Channel.
Founded by Chester Keltner, the Keltner Channel is a technical indicator that is…
Read More: Forget Stocks, This Commodity Algo Trading Strategy Made +260% Returns | by