The Rainbow Indicator, Another Way to Follow the Trend.

Presenting and Coding a Complete Trend-Following Indicator in Python.

Sofien Kaabar, CFA
The Startup
Published in
7 min readJan 31, 2021

--

The Rainbow Indicator is a mix between a trend-following and a contrarian system. It is a combination of Smoothed Moving Averages that are used together to confirm a beginning or end of a trend. In this article, we will build the Rainbow Indicator from scratch in Python.

I have just published a new book after the success of New Technical Indicators in Python. It features a more complete description and addition of complex trading strategies with a Github page dedicated to the continuously updated code. If you feel that this interests you, feel free to visit the below link, or if you prefer to buy the PDF version, you could contact me on Linkedin.

The Concept of Moving Averages

Moving averages help us confirm and ride the trend. They are the most known technical indicator and this is because of their simplicity and their proven track record of adding value to the analyses. We can use them to find support and resistance levels, stops and targets, and to understand the underlying trend. This versatility makes them an indispensable tool in our trading arsenal.

EURUSD with its 200-period Simple moving average. (Image by Author)

As the name suggests, this is your plain simple mean that is used everywhere in statistics and basically any other part in our lives. It is simply the total values of the observations divided by the number of observations. Mathematically speaking, it can be written down as:

We can see that the moving average is providing decent dynamic support and resistance levels from where we can place our orders in case the market goes down there.

def ma(Data, lookback, what, where):

for i in range(len(Data)):
try:
Data[i, where] = (Data[i - lookback + 1:i…

--

--

Sofien Kaabar, CFA
The Startup

Top writer in Finance, Investing, Business | Trader & Author | Bookstore: https://sofienkaabar.myshopify.com/