The Cross Indicator. Quick Glance at Golden & Death Crosses in Trading.
Creating a Cross Indicator to Help Detecting Multiple Moving Average Crosses.
Moving average crossovers provide signals that suggest a change in the trend. This is a very valuable information and can pave the way for strong trend-following strategies. In this article, we will introduce a simple calculation to facilitate the detection of crossovers and we will try out a controversial idea revolving moving averages and how to use their lag to our advantage.
I have just published a new book after the success of my previous one “New Technical Indicators in Python”. It features a more complete description and addition of structured trading strategies with a GitHub page dedicated to the continuously updated code. If you feel that this interests you, feel free to visit the below link, or if you prefer to buy the PDF version, you could contact me on LinkedIn.
The Concept of Moving Average
Moving averages help us confirm and ride the trend. They are the most known technical indicator and this is because of their simplicity and their proven track record of adding value to the analyses. We can use them to find support and resistance levels, stops and targets, and to understand the underlying trend. This versatility makes them an indispensable tool in our trading arsenal.
As the name suggests, this is your plain simple mean that is used everywhere in statistics and basically any other part in our lives. It is simply the total values of the observations divided by the number of observations. Mathematically speaking, it can be written down as:
# 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
The below states that the moving average function will be called on the array named my_data for a lookback period of 200, on the column indexed at 3 (closing prices in an OHLC array). The moving average values will then be put in the column indexed at 4 which is the one we have added using the adder function.
my_data = ma(my_data, 200, 3, 4)
The Golden Cross
A Golden Cross occurs when the short-term moving average crosses the long-term moving average from the below to the above signaling a confirmation of the bullish trend and an acceleration to the upside.
If you are also interested by more technical indicators and using Python to create strategies, then my best-selling book on Technical Indicators may interest you:
The Death Cross
A Death Cross occurs when the short-term moving average crosses the long-term moving average from the above to the below signaling a confirmation of the bearish trend and an acceleration to the downside.
The Cross Indicator
The Cross Indicator is a type of signal of when the two moving averages cross. It is composed of the difference between the short-term moving average and the long-term moving average.
Whenever the Cross Indicator switches form negative values to positive values, a golden cross has occurred, and market is turning bullish. Or has already turned bullish as moving averages are lagging.
Whenever the Cross Indicator switches form positive values to negative values, a death cross has occurred, and market is turning bearish. Or has already turned bearish as moving averages are lagging.
We can easily code the function in Python that first measures the two moving averages of two selected variables representing the different lookback of the moving averages then takes the difference between the two.
def cross_indicator(Data, short_lookback, long_lookback, what, where):
Data = ma(Data, short_lookback, what, where)
Data = ma(Data, long_lookback, what, where + 1)
Data[:, where + 2] = Data[:, where] - Data[:, where + 1]
Data = deleter(Data, where, 2)
return Data
The trader can select whichever lookback period he or she follows. Generally, people talk about crosses between 60/200 and 20/60 but in my back-testing personal opinion, nothing works consistently. Which is why, this article will not have a back-test. I only use moving averages in discretionary trading (i.e. to find support and resistance levels for optimal entry points). However, one point has always intrigued me with these fascinating indicators, it is their weakness. Can we transform this weakness into a strength?
The weakness I am talking about here is the Lag.
Exploiting the Lag in Moving Averages
Notice how in the below plots, whenever the golden cross happens, it is usually around the top and whenever the death cross happens, it is around the bottom. This is not to say that the cross strategy is bad, but it is just a problem of lag and timing. Two ways can be used to remedy this:
Awaiting the pull-back to a subjective support/resistance level before riding the newly established trend.
Playing the reaction after the cross and targeting the area where the two moving averages are situated.
Let us discuss both techniques in more detail. The first one states that we can simply wait before we initiate a trade.
Whenever the Golden Cross happens (i.e. the Cross Indicator turns positive), we have to wait for the market price to drop to the area where the moving average are before initiating a long (Buy) order.
Whenever the Death Cross happens (i.e. the Cross Indicator turns negative), we have to wait for the market price to rise to the area where the moving average are before initiating a short (Sell) order.
The second strategy is to actually play the reverse move of the cross strategy. It can be very interesting to know more about the results of such a strategy. Below are the conditions:
Whenever the Cross Indicator switches form negative values to positive values, a golden cross has occurred, and market is turning bullish. Or has already turned bullish as moving averages are lagging. This is where we initiate a short (Sell) order
Whenever the Cross Indicator switches form positive values to negative values, a death cross has occurred, and market is turning bearish. Or has already turned bearish as moving averages are lagging. This is where we initiate a long (Buy) order
# Reverse Crossover Strategy
def reverse_crossover_signal(Data, what, buy, sell):
for i in range(len(Data)):
if Data[i, what] > 0 and Data[i - 1, what] < 0 and Data[i - 2, what] < 0:
Data[i, sell] = -1
if Data[i, what] < 0 and Data[i - 1, what] > 0 and Data[i - 2, what] > 0:
Data[i, buy] = 1
# Standard Crossover Strategy
def crossover_signal(Data, what, buy, sell):
for i in range(len(Data)):
if Data[i, what] > 0 and Data[i - 1, what] < 0 and Data[i - 2, what] < 0:
Data[i, buy] = 1
if Data[i, what] < 0 and Data[i - 1, what] > 0 and Data[i - 2, what] > 0:
Data[i, sell] = -1
As a refresher, the standard crossover strategy is where we buy the Golden Cross and sell the Death Cross while the reverse crossover strategy is where we sell the Golden Cross and buy the Death Cross.
The above two equity plots show two crossover strategies, the standard one with the already known conditions and the reverse one which seeks to exploit the lag. There was no risk management used and the trades are closed upon the next signal. Visibly, on this pair, the timing factor has its weight and a pure crossover standard trend-following strategies does not work using the current conditions.
Conclusion
Why was this article written? It is certainly not a spoon-feeding method or the way to a profitable strategy. If you follow my articles, you will notice that I place more emphasize on how to do it instead of here it is and that I also provide functions not full replicable code. In the financial industry, you should combine the pieces yourself from other exogenous information and data, only then, will you master the art of research and trading. I always advise you to do the proper back-tests and understand any risks relating to trading.