Trend-following also deserves to be studied thoroughly as many known indicators do a pretty well job in tracking trends. It is known that trend-following strategies has some structural lags in them due to the confirmation of the new trend. They are more about time in the market than timing the market. In this article, a very known indicator is presented and coded, the Aroon oscillator.
I have just released a new book after the success of the previous book. 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.
Trend Following Strategies in Python: How to Use Indicators to Follow the Trend.
Amazon.com: Trend Following Strategies in Python: How to Use Indicators to Follow the Trend.: 9798756939620: Kaabar…www.amazon.com
Creating the Aroon Oscillator
The Aroon Oscillator is created from two sub-indicators called Aroon Up and Aroon Down. They measure the trend’s strength using the highs and lows in a way that is unique and unlike other regular indicators.
The first step is to calculate the Aroon Up and Down using the following formula:
Let us look at an example on what is meant by Aroon Up and Aroon Down. Consider an asset where it has reached a new low last time period. For a 25-period Aroon Down, the value will be 96 because we will be subtracting 1 from 25, dividing it by 25 and multiplying by 100. Similarly, for a 13-period Aroon Up, where an asset has reached a new high one period ago, the Aroon Up will show a reading of 92.30.
It is understood that the higher the value of the Aroon, the stronger the trend. Now, let us code the Aroon in Python before moving on to the Aroon Oscillator.
def aroon(Data, period, close, where):
# Adding Columns
Data = adder(Data, 10)
# Max Highs
for i in range(len(Data)):
try:
Data[i, where] = max(Data[i - period + 1:i + 1, 1])
except ValueError:
pass
# Max Lows
for i in range(len(Data)):
try:
Data[i, where + 1] = min(Data[i - period + 1:i + 1, 2])
except ValueError:
pass
# Where the High Equals the Highest High in the period
for i in range(len(Data)):
if Data[i, 1] == Data[i, where]:
Data[i, where + 2] = 1
# Where the Low Equals the Lowest Low in the period
for i in range(len(Data)):
if Data[i, 2] == Data[i, where + 1]:
Data[i, where + 3] = 1
# Jumping Rows
Data = jump(Data, period)
# Calculating Aroon Up
for i in range(len(Data)):
try:
try:
x = max(Data[i - period:i, 1])
y = np.where(Data[i - period:i, 1] == x)
y = np.array(y)
distance = period - y
Data[i - 1, where + 4] = 100 *((period - distance) / period)
except ValueError:
pass
except IndexError:
pass
# Calculating Aroon Down
for i in range(len(Data)):
try:
try:
x = min(Data[i - period:i, 2])
y = np.where(Data[i - period:i, 2] == x)
y = np.array(y)
distance = period - y
Data[i - 1, where + 5] = 100 *((period - distance) / period)
except ValueError:
pass
except IndexError:
pass
# Cleaning
Data = deleter(Data, 5, 4)
return Data
The above chart shows the EURUSD hourly values with the Aroon Up in blue and Aroon Down in orange. The last step is to calculate the Aroon Oscillator which is the difference between Aroon Up and Aroon Down:
my_data[:, where_aroon_osc] = my_data[:, where_aroon_up] -
my_data[:, where_aroon_down]
Created by Tushar Chande, the Aroon Oscillator is a popular trend-following indicator which is calculated as seen in the above code snippet. It is worth knowing that the word Aroon most likely means dawn’s early light in Sanskrit.
Trading the Aroon Oscillator
The way to trade the Aroon Oscillator is to use the flip technique where the value flips from positive to negative or from negative to positive. In our case, the below will be the trading conditions:
Buy (Long position) whenever the Aroon Oscillator turns positive by surpassing the zero line.
Sell (Short position) whenever the Aroon Oscillator turns negative by breaking the zero line.
def signal(Data, aroon_osc_col, buy, sell):
Data = adder(Data, 10)
for i in range(len(Data)):
if Data[i, aroon_osc_col] > 0 and Data[i - 1, aroon_osc_col] < 0:
Data[i, buy] = 1
elif Data[i, aroon_osc_col] < 0 and Data[i - 1, aroon_osc_col] > 0:
Data[i, sell] = -1
return Data
As can be seen from the signal chart, sometimes, lag is the biggest enemy of trend-following strategies. What is the solution to this? We can try to tweak the lookback period, the conditions, add filters, and even change the strategy itself.
The V strategy is a unique contrarian confirmation technique with a configuration that resembles the letter V. Basically, to have a V signal, we need the following conditions:
For a bullish (Buy) signal, the Aroon Oscillator must shape a V formation, meaning the current reading is above -75, the previous reading is less than -75, and the one prior to it greater than -75.
For a bullish (Sell) signal, the Aroon Oscillator must shape an inverted V formation, meaning the current reading is less than 75, the previous reading is above 75, and the one prior to it less than 75.
def signal(Data, aroon_osc_colr, buy, sell):
Data = adder(Data, 10)
for i in range(len(Data)):
if Data[i, aroon_osc_colr] > -75 and Data[i - 1, aroon_osc_colr] < -75 and Data[i - 2, aroon_osc_colr] > -75 :
Data[i, buy] = 1
elif Data[i, aroon_osc_colr] < 75 and Data[i - 1, aroon_osc_colr] > 75 and Data[i - 2, aroon_osc_colr] < 75:
Data[i, sell] = -1
return Data
If you are also interested by more technical indicators and strategies, then my book might interest you:
The Book of Trading Strategies
Amazon.com: The Book of Trading Strategies: 9798532885707: Kaabar, Sofien: Bookswww.amazon.com
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.
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.