#### Discover more from All About Trading!

# The Cross Indicator. Quick Glance at Golden & Death Crosses in Trading.

### Creating a Cross Indicator to Help Detecting Multiple Moving Average Crosses.

Moving average crosses provide signals that suggest a change in the trend. This is a 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 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**.

### Moving Averages

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:

We can see that the moving average is providing decent dynamic support and resistance levels from where we can place our orders in case the market goes down there. The code for the moving average can be written down as the following:

```
# 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
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.

### 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.

If you are also interested by more technical indicators and strategies, then my book might interest you:

### 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 the 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 the market is turning bearish or has already turned bearish as moving averages are lagging.**

We can easily code the statement 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.

```
my_data = ma(my_data, 50, 3, 4)
my_data = ma(my_data, 100, 3, 5)
```

`my_data = adder(my_data, 1)`

`my_data[:, 6] = my_data[:, 4] - my_data[:, 5]`

```
def signal(data, cross_indicator_column, buy, sell):
data = adder(data, 10)
for i in range(len(data)):
if data[i, cross_indicator_column] > 0 and data[i - 1, cross_indicator_column] < 0:
data[i, buy] = 1
elif data[i, cross_indicator_column] < 0 and data[i - 1, cross_indicator_column] > 0:
data[i, sell] = -1
return data
```

The trader can select whichever lookback period he or she follows. Generally, people talk about crosses between 50/100 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 theLag.

### Exploiting the Lag in Moving Averages

Notice how sometimes, 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 averages are before initiating a 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 averages 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 the 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 the market is turning bearish or has already turned bearish as moving averages are lagging.****This is where we initiate a buy order**

### 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.**