The parabolic SAR is a unique and versatile trading tool that can be used either for directional guidance or for risk management. It is uncommon to find such a polyvalent indicator.
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 Parabolic Stop-And-Reverse
The parabolic stop-and-reverse is an interesting indicator created by Welles Wilder Jr. who is also the creator of the famous RSI. This indicator is mostly used as a trailing stop that tracks the trend as it develops but there is no harm in using it as a signal generator. It is worth noting that it performs relatively well in steady trends but just as any other indicator, it has its weakness, in this case, ranging markets. The below chart shows an example of the EURUSD with the standard parabolic SAR. We will see below how to code it.
I will refer to a python library called talib from where the user could import the sar function that uses a data frame and calculates the values. Having modified that function, you can refer to the one below (I do not take credit for it as I just changed some lines as opposed to the other functions which have been coded by me):
def sar(s, af = 0.02, amax = 0.2):
s = pd.DataFrame(s)
s.columns = ['open','high','low','close']
high, low = s.high, s.low
# Starting values
sig0, xpt0, af0 = True, high[0], af
sar = [low[0] - (high - low).std()]
for i in range(1, len(s)):
sig1, xpt1, af1 = sig0, xpt0, af0
lmin = min(low[i - 1], low[i])
lmax = max(high[i - 1], high[i])
if sig1:
sig0 = low[i] > sar[-1]
xpt0 = max(lmax, xpt1)
else:
sig0 = high[i] >= sar[-1]
xpt0 = min(lmin, xpt1)
if sig0 == sig1:
sari = sar[-1] + (xpt1 - sar[-1])*af1
af0 = min(amax, af1 + af)
if sig0:
af0 = af0 if xpt0 > xpt1 else af1
sari = min(sari, lmin)
else:
af0 = af0 if xpt0 < xpt1 else af1
sari = max(sari, lmax)
else:
af0 = af
sari = xpt0
sar.append(sari)
s = np.array(s)
s = np.reshape(s, (-1, 1))
return sar
The basic understanding is that when the parabolic SAR (the dots around the market price) is under the current price, then the outlook is bullish and when it is above the current price, then the outlook is bearish.
To add the parabolic SAR to your OHLC array, use the following steps:
importing pandas as pd
par = sar(my_data, af = 0.02, amax = 0.2)
par = np.array(par)
par = np.reshape(par, (-1, 1))
my_data = np.concatenate((my_data, par), axis = 1)
Now, we will discuss 4 different strategies that can be formed around this indicator. Our aim is to explore the horizons around it.
The Parabolic Flip Strategy
The first and most common strategy relies on the position of the current market price relative to the parabolic SAR. Essentially, we can use the following conditions as trading triggers:
Long (Buy) whenever the market price becomes above the parabolic SAR while the previous price is below it. Hold this position until the market price dives below the parabolic SAR.
Short (Sell) whenever the market price becomes below the parabolic SAR while the previous price is above it. Hold this position until the market price surpasses the parabolic SAR.
def signal(data, close, psar, buy, sell):
data = adder(data, 2)
for i in range(len(data)):
if data[i, close] > data[i, psar] and data[i - 1, close] < data[i - 1, psar]:
data[i, buy] = 1
if data[i, close] < data[i, psar] and data[i - 1, close] > data[i - 1, psar]:
data[i, sell] = -1
return data
The above function is the signal of the conditions mentioned. Let us see an example on the EURUSD buy and sell signals generated from the flip strategy.
A strategy that relies purely on these conditions is unlikely to succeed in such a complex market.
If you are also interested by more technical indicators and strategies, then my book might interest you:
The Parabolic Three Dots Strategy
The second strategy relies on more confirmation than the first one. We remain within the same optic of the flip but we will wait for three periods (dots) to confirm that it is a true flip before we initiate the position. Therefore, the conditions in detail are:
Long (Buy) whenever we have three consecutive dots below the market after the bullish flip occurs. Hold this position until the market price dives below the parabolic SAR.
Short (Sell) whenever we have three consecutive dots above the market after the bearish flip occurs. Hold this position until the market price surpasses the parabolic SAR.
def signal(data, close, psar, buy, sell):
data = adder(data, 3)
for i in range(len(data)):
if data[i, close] > data[i, psar] and data[i - 1, close] < data[i - 1, psar]:
data[i, buy] = 1
if data[i, close] < data[i, psar] and data[i - 1, close] > data[i - 1, psar]:
data[i, sell] = -1
return data
The above function is the signal of the conditions mentioned. Let us see an example on the EURUSD buy and sell signals generated from the three dots strategy.
The Parabolic Index Strategy
To understand this strategy, we need to first understand what normalization is. This great technique allows us to trap the values between 0 and 1 (or 0 and 100 if we wish to multiply by 100). The concept revolves around subtracting the minimum value in a certain lookback period from the current value and dividing by the maximum value in the same lookback period minus the minimum value (the same in the nominator).
We can try to code this formula in python. The below function normalizes a given time series of the OHLC type:
def normalizer(Data, lookback, what, where):
for i in range(len(Data)):
try:
Data[i, where] = (Data[i, what] - min(Data[i - lookback + 1:i + 1, what])) / (max(Data[i - lookback + 1:i + 1, what]) - min(Data[i - lookback + 1:i + 1, what]))
except ValueError:
pass
Data[:, where] = Data[:, where] * 100
return Data
We can use the same signal function as above to find the below signals on the EURUSD.
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.