Discover more from All About Trading!
Trading the Outstretched Indicator in Python — Profiting From Momentum.
Creating and Coding the Outstretched Indicator in Python.
Momentum can be faded in many ways when we have enough elements to suggest that exhaustion may happen. This can be done through divergence analysis, oversold/overbought levels, and timing indicators such as the TD differentials pattern. In this article, we will create an indicator that can be used both for discretionary and systematic trading.
Creating the Outstretched Indicator Step-By-Step
The idea is to mark rising and falling momentum and then calculate an exponential moving average based on the sum of the different momentum moves. The steps can be summed up as follows:
Select a momentum lookback and a moving average lookback. By default we can use 3.
Create two columns called the positive stretch and the negative stretch, where the first one has 1’s if the current closing price is greater than the closing price 3 periods ago and the other one has 1’s if the current closing price is lower than the closing price 3 periods ago.
Sum the latest three positive and negative stretches and subtract the results from each other. This is called the raw outstretch.
Finally, to get the outstretched indicator, we take the 5-period exponential moving average of the raw outstretch.
def outstretched_indicator(Data, lookback, lookback_ma, close, where): # Adding a few columns Data = adder(Data, 6) # Calculating the Stretch for i in range(len(Data)): # Positive Stretch if Data[i, close] > Data[i - lookback, close]: Data[i, where] = 1 # Negative Stretch else: Data[i, where + 1] = 1
# Positive Stretch Summation for i in range(len(Data)): Data[i, where + 2] = Data[i - lookback + 1:i + 1, where].sum()
# Negative Stretch Summation for i in range(len(Data)): Data[i, where + 3] = Data[i - lookback + 1:i + 1, where + 1].sum() # Calculating the Raw Outstretch Data[:, where + 4] = Data[:, where + 2] - Data[:, where + 3] # Calculating the Outstretched Indicator Data = ema(Data, 2, lookback_ma, where + 4, where + 5) # Deleting columns Data = deleter(Data, where, 5) return Data
Note that for the above function to work, you do not need to add columns before as it is already embedded in the function.
Using the Outstretched Indicator in Discretionary Trading
Discretionary is manual low-frequency trading. It is what we do when we take the time to look at the market and consult our research for the best opportunities. Discretionary trading is superior to systematic trading when it comes to subjective interpretation and the hunch or what is referred to as the trader’s guts.
The above chart shows the signals generated when the barriers on the indicator are set close to the absolute extreme (which is 3) at 2.5. This means that whenever the indicator reaches 2.5 or -2.5, we can have a contrarian bias.
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.