A Simple Yet Effective Contrarian Indicator

Creating the Chande Momentum Oscillator in Python

Sofien Kaabar, CFA

--

Momentum oscillators are numerous and their added-value ranges between very bad to acceptable. It is normal that we will not find something very predictive if we are just applying a lag over the price but we can find insights on the recent behavior of the market price. This article discusses one known oscillator called the Chande Momentum Oscillator.

If you are interested by trend following indicators and strategies then my book could interest you. It features advanced trend-following indicators and strategies with a GitHub page dedicated to the continuously updated code. Also, this book features the original colors after having optimized for printing costs. If you feel that this interests you, feel free to visit the below Amazon link, or if you prefer to buy the PDF version, you could contact me on LinkedIn.

Fetching Historical OHLC Data

Let us start by fetching historical OHLC data before seeing how to code the indicator in Python. One of the most famous trading platforms in the retail community is the MetaTrader5 software. It is a powerful tool that comes with its own programming language and its huge online community support. It also offers the possibility to export its historical short-term and long-term FX data.

The first thing we need to do is to simply download the platform from the official website. Then, after creating the demo account, we are ready to import the library in Python that allows to import the OHLC data from MetaTrader5.

A library is a group of structured functions that can be imported into our Python interpreter from where we can call and use the ones we want.

The easiest way to install the MetaTrader5 library is to go to the Python prompt on our computer and type:

pip install MetaTrader5

--

--