Chaikin Oscillator Trading Strategy

How I Made A Profitable Chaikin Oscillator Trading Strategy In Python

Introduction

This tutorial will implement the Chaikin Oscillator in Python using historical financial data from the iShares Russell 1000 Growth ETF (IWF). The first part will briefly review the theory behind this indicator. The second part will code a trading strategy using this indicator in Python.

Related reading: – Many more Python trading strategies

chaikin-oscillator-indicator

Chaikin Oscillator Indicator

This indicator is an oscillator indicator because it measures the momentum of the Accumulation Distribution Line using the MACD. One aspect of the Chikin Oscillator indicator is that uses the values of another indicator as input. Marc Chaikin developed it in the 1970s.

The steps to calculate the Chaikin Oscillator are:

\begin{align*}
\text{(1)}\quad & \text{Money Flow Multiplier} = \frac{\text{Close} - \text{Low} - (\text{High} - \text{Close})}{\text{High} - \text{Low}} \\ \\
\text{(2)}\quad & \text{Money Flow Volume} = \text{Money Flow Multiplier} \times \text{Volume for the Period} \\ \\
\text{(3)}\quad & \text{ADL} = \text{Previous ADL} + \text{Current Period's Money Flow Volume} \\ \\
\text{(4)}\quad & \text{Chaikin Oscillator} = \text{3-day EMA of ADL} - \text{10-day EMA of ADL} 
\end{align*}

We will explain with historical data each step of the Chaikin Oscillator calculation in the next sections.

Python Example

Download Data

As in the previous tutorial, the first step is to import the Python libraries; and then, download the historical data associated with iShares Russell 1000 Growth ETF (IWF).

Steps to Calcualte Chaikin Oscillator Indicator

This part will go through the four steps to calculate the Chaikin Oscillator in Python.

The first step is to calculate the Money Flow Multiplier (Equation 1) as shown in the following images. The moneyFlowMultiplier function takes two parameters: a pandas data frame data and debug. The function body calculates and returns the indicator.

To provide a more in-depth explanation of the Money Flow Multiplier calculation using single dates, the following image illustrates the process when the debug = True. It prints the calculus for the rows 0, 1, 11, and 33.

The image below showcases the plot_data function, a tool for visualizing the intermediate series generated during the calculation of the Chaikin Oscillator.

After implementing the following code to plot the Money Flow Multiplier, the result will show an overcrowded image because the chart has over 20 years of daily data points.

The following image only shows one year of data.

In the previous chart, you will see how the indicator fluctuates from -1 to 1.

The second step calcualtes the Money Flow Volume (equation 2). This procedure is simple. It is Money Flow Multiplier * Volume. The following image shows the moneyFlowVolume functions.

This is the chart:

The third step calcuates the Accumulative Distribution Line (equation 3). Its calculation comprises the Money Flow Volume cumulative sum. The following image illustrate the Accumulative Distribution Line function accumulateDistributionLine. The function uses .cumsum Python.

The following image illustrates with an example .cumsum:

The Accumulative Distribution Line is:

Finally, the last step comprises the Chaikin Oscillator estimation. This indicator uses as input the values from the Accumulative Distribution Line, it does not use the price level. Therefore is an indicator of indicator. Equation 4 shows its calculation. It is the difference between two Exponential Moving averages, a short EMA minus a long EMA.

The following image shows its implementation using the chaikin_oscillator function.

The above image illustrates the default Chaikin Oscillator indicator calculation with parameters 3 and 10. Also, it implements a second version with parameters 25 and 65.

Chaikin Oscillator Trading Strategy

This section will calculate a simple trading strategy:

  • Hold a long position when the Chaikin Oscillator is higher than zero.
  • Hold a short position when the Chaikin Oscillator is lower or equal to zero.

The following image shows the plot_data1 function. It shows in one chart the closing price and the Chaikin Oscillator Indicator.

After plotting the Chaikin Oscillator indicator with parameters 3 and 10. It shows an overcrowded chart with too many data points.

It is convenient to show only the first 1000 days to illustrate how the price and the Chaikin Oscillator indicator behave jointly. The following two images show the Python code and the chart.

From the year 2000 until the first month of 2003, the closing price shows a downtrend behavior. In the same period, the indicator has different moments over zero. Most of these signals generate wrong long positions.

Values over zero represent holding a long position, and values lower or equal to zero represent a short position.

From 2003 to 2004, the price followed an upward trend, and the indicator generated mixed signals. The intuition suggests that most of the short positions generate losing trades. If the price follows an upward trend, the logical implication is to find a trading strategy that will profit from a price increase.

Let’s see the strategy with the Chaikin Oscillator parameters 25 and 65. In this scenario, most of the trades are long positions (Chaikin Oscillator > 0). The historical closing price chart has an upward trend. It is consistent to have a strategy that generates more long positions than short positions.

The next image illustrates the calculate_signal function. It indicates when there is a short position (Chaikin Oscillator indicator <= 0), and when there is a long position (Chaikin Oscillator indicator > 0).

Equity Curve

This section will show a chart with the profit of both strategies implemented in the previous section.

The following image shows the equity_curve function. It calculates and plots the equity curve (cumulative return) of a trading strategy.

The first strategy (blue line). Chaikin Oscillator with parameters 3 and 10. It lost around 80% of the initial investment.

The blue line is the performance of the strategy: Chaikin Oscillator with parameters 25 and 65. It almost doubled the returns from the buy-and-hold strategy (orange line). This strategy generates good results because it is consistent with the evolution of the historical price.

Similar Posts