# The Pure Price Slope. Creating Technical Indicators

### Creating a Price Slope Indicator to Trade the Markets in Python

In a previous article, we have seen how apply the slope calculation onto moving average in order to derive signals. In this article, we will apply a pure approach where we simply calculate the price slope. This should give us an uncorrelated technical indicator that can help us diversify our framework. This slope indicator is a good addition to a systematic trading framework.

I have just released a new book after the success of my previous one “*The Book of Trading Strategies*”. 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**.

### The Concept of the Slope

The steepness of two or more points is measured by the slope. A greater slope means a steeper line while a lower slope means a flatter line. We can measure the slope in geometry by using a simple formula. Basically, the slope can be found by measuring the *ratio of the vertical change to the horizontal change.*

In time series, when we are dealing with the slope of two successive points in time, the slope function shortens to just subtracting the last value by the one preceding it. In case we want the slope of a wider interval, say 5 points in time, we have to use the below formula:

For example, consider the following information on the EURUSD:

**Current closing price = 1.2300****Closing price 5 periods ago = 1.2200****Time interval selected = 5 periods**

We can find that the slope for this period is therefore the change in the closing prices which is 0.0100 divided by 5, giving us a slope of **0.002.**

The graph above shows the slope represented by the moving line. Notice how it changes with directional movements on the blue line. Now, we can proceed to applying this concept on a rolling basis.

### Using Price Slope as a Signal Generator

When we apply the slope function to the market price on a rolling basis, we can see a mean-reversion structure emerging as seen in the below plot of the EURUSD with a rolling slope of 3 periods.

```
def slope_indicator(Data, lookback, what, where):
Data = adder(Data, 1)
for i in range(len(Data)):
Data[i, where] = (Data[i, what] - Data[i - lookback, what]) / lookback
Data = jump(Data, lookback)
return Data
```

What the above function does is simply calculate the slope of a given variable called **what **which in our case would be the moving average, then loops around the totality of the data array and subtracts the current moving average by the one preceding it by a variable amount of time that we wish to specify using the **lookback **input, and finally dividing by the time interval which is the same as the lookback period. The **where **variable is where you want to output the indicator.

Using the slope indicator is tricky because we need to understand how to exploit it. Surpassing the zero line can give a bullish signal while breaking it can give our a bearish signal. Similarly, we can form subjective barriers just as we do on the RSI and trade reversals. One last strategy we can use is to create a moving average on the slope and trade the cross between it and the slope indicator.

If you are also interested by more technical indicators and strategies, then my book might interest you:

### Conclusion

Remember to always do your back-tests. You should always believe that other people are **wrong**. My indicators and style of trading may work for me but maybe not for you.

I am a firm believer of not spoon-feeding. I have learnt by doing and not by copying. You should get the idea, the function, the intuition, the conditions of the strategy, and then elaborate (an even better) one yourself so that you back-test and improve it before deciding to take it live or to eliminate it. My choice of not providing specific Back-testing results should lead the reader to explore more herself the strategy and work on it more.

To sum up, are the strategies I provide realistic? *Yes*, but only by optimizing the environment (robust algorithm, low costs, honest broker, proper risk management, and order management). Are the strategies provided only for the sole use of trading? **No**, it is to stimulate brainstorming and getting more trading ideas as we are **all sick of hearing about an oversold RSI as a reason to go short or a resistance being surpassed as a reason to go long. I am trying to introduce a new field called Objective Technical Analysis where we use hard data to judge our techniques rather than rely on outdated classical methods.**

### One Last Word

I have recently started an NFT collection that aims to support different humanitarian and medical causes. **The Society of Light** is a set of limited collectibles which will help make the world slightly better as each sale will see a percentage of it sent directly to the charity attributed to the avatar. As I always say, nothing better than a bullet list to outline the benefits of buying these NFT’s:

**High-potential gain**: By concentrating the remaining sales proceedings on marketing and promoting**The Society of Light**, I am aiming to maximize their value as much as possible in the secondary market. Remember that trading in the secondary market also means that a portion of royalties will be donated to the same charity.**Art collection and portfolio diversification**: Having a collection of avatars that symbolize good deeds is truly satisfying. Investing does not need to only have selfish needs even though there is nothing wrong with investing to make money. But what about investing to*make money, help others, and collect art?***Donating to your preferred cause(s):**This is a flexible way of allocating different funds to your charities.**A free copy of my book in PDF**: Any buyer of any NFT will receive a free copy of my latest book shown in the link of the article.