Discover more from All About Trading!
The Know Sure Thing Technical Indicator — Coding in Python.
Presenting & Coding the Know Sure Thing Indicator.
This article discusses a structured oscillator called the Know Sure Thing. It is mainly used in reversal trading strategies and to confirm the already established bias. We will also take a look on how to use it after coding it in Python.
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 Rate of Change Indicator
The rate of change of a security can be found by using the below formula:
It describes the evolution of the value over time. If the previous price of a security was $100 and is now $110, then the rate of change will be 10%. This means that the market price increased by 10% since the previous period.
The rate of change Indicator is an oscillator that uses the above formula on a rolling basis and for a specified lookback period. A lookback period of 3 means that we will calculate the rate of change between the current price and the price 3 periods ago. The below plot shows an example of a 10-period lookback.
Let us now see how we can use this simple indicator as a main ingredient in the Know Sure Thing cooking recipe.
The Know Sure Thing Indicator
Developed by Martin Pring, the KST uses smoothed versions of the rate of change to interpret changes in momentum. It is an unbounded oscillator that resembles the MACD and uses four rate of change calculations with different lookback periods as illustrated below:
We then take a 10-period simple moving average on the first three ROC’s and a 15-period simple moving average on the last ROC. Finally, we use the following formula to calculate the Know Sure Thing:
We then calculate a signal line which is simply a 9-period moving average on the KST.
The figure above shows the KST in blue with the signal line in red. Notice how it oscillates over the zero line and crosses its signal line from time to time.
# The function to add a number of columns inside an array def adder(Data, times): for i in range(1, times + 1): new_col = np.zeros((len(Data), 1), dtype = float) Data = np.append(Data, new_col, axis = 1) return Data
# The function to delete a number of columns starting from an index def deleter(Data, index, times): for i in range(1, times + 1): Data = np.delete(Data, index, axis = 1) return Data # The function to delete a number of rows from the beginning def jump(Data, jump): Data = Data[jump:, ] return Data
# Example of adding 3 empty columns to an array my_ohlc_array = adder(my_ohlc_array, 3)
# Example of deleting the 2 columns after the column indexed at 3 my_ohlc_array = deleter(my_ohlc_array, 3, 2)
# Example of deleting the first 20 rows my_ohlc_array = jump(my_ohlc_array, 20)
# Remember, OHLC is an abbreviation of Open, High, Low, and Close and it refers to the standard historical data file
def ma(Data, lookback, close, where): Data = adder(Data, 1) for i in range(len(Data)): try: Data[i, where] = (Data[i - lookback + 1:i + 1, close].mean()) except IndexError: pass # Cleaning Data = jump(Data, lookback) return Data
def know_sure_thing(Data, lookback1, lookback2, lookback3, lookback4, close, where):
Data = adder(Data, 5) # First ROC for i in range(len(Data)): Data[i, where] = ((Data[i, close] - Data[i - lookback1, close]) / Data[i - lookback1, close]) * 100 # Second ROC for i in range(len(Data)): Data[i, where + 1] = ((Data[i, close] - Data[i - lookback2, close]) / Data[i - lookback2, close]) * 100 # Third ROC for i in range(len(Data)): Data[i, where + 2] = ((Data[i, close] - Data[i - lookback3, close]) / Data[i - lookback3, close]) * 100 # Fourth ROC for i in range(len(Data)): Data[i, where + 3] = ((Data[i, close] - Data[i - lookback4, close]) / Data[i - lookback4, close]) * 100
# Smoothing Data = ma(Data, lookback1, where, where + 4) Data = ma(Data, lookback1, where + 1, where + 5) Data = ma(Data, lookback1, where + 2, where + 6) Data = ma(Data, lookback2, where + 3, where + 7)
# KST Data[:, where + 8] = Data[:, where + 4] + \ (Data[:, where + 5] * 2) + \ (Data[:, where + 6] * 3) + \ (Data[:, where + 7] * 4) # Signal line Data = ma(Data, 9, where + 8, where + 9) # Cleaning Data = deleter(Data, where, 8) return Data
Trading this indicator is based on simple crossover rules and are as follows:
A long (Buy) whenever the KST line crosses over the KST signal line.
A short (Sell) whenever the KST line crosses under the KST signal line.
def signal(Data, kst, kst_ma, buy, sell): Data = adder(Data, 2) for i in range(len(Data)): if Data[i, kst] > Data[i, kst_ma] and Data[i - 1, kst] < Data[i - 1, kst_ma]: Data[i, buy] = 1
elif Data[i, kst] < Data[i, kst_ma] and Data[i - 1, kst] > Data[i - 1, kst_ma]: Data[i, sell] = -1 return Data
In general, the signals are a little late to the party and are not of high quality. The hit ratio and profitability metrics of this indicator are not impressive.
If you are also interested by more technical indicators and strategies, then my book might interest you:
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.