# Creating a Technical Indicator From Scratch in Python

## Thinking About & Creating a Technical Indicator

--

Anybody can create a calculation that aids in detecting market reactions. The question is, how good will it be? It is always complicated to find a good indicator because of the ever-changing market regime which alternates between trending, ranging, and random. In this article, we will think about a simple indicator and create it ourselves in Python from scratch.

I have released a new book after the success of my previous one “*Trend Following Strategies in Python*”. It features advanced contrarian indicators and strategies with a **GitHub **page dedicated to the continuously updated code. If you feel that this interests you, feel free to visit the below Amazon link (which contains a sample), or if you prefer to buy the PDF version, you could check the link at the end of the article.

# The Momentum Indicator

Momentum is an interesting concept in financial time series. Most strategies are either trend-following or mean-reverting. Momentum is the strength of the acceleration to the upside or to the downside, and if we can measure precisely when momentum has gone too far, we can anticipate reactions and profit from these short-term reversal points. One way to measure momentum is by the **momentum indicator**.

The Momentum Indicator’s formula is extremely simple and can be summed up in the below mathematical representation:

What the above says is that we can divide the latest (or current) closing price by the closing price of a previous selected period, then we multiply by 100. Hence, if we say we are going to use Momentum(14), then, we will subtract the current values from the values 14 periods ago and then divide by 100.

The Momentum Indicator is not bounded as can be seen from the formula, which is why we need to form a strategy that can give us signals from its movements.