# Timing the Markets With Patterns and Momentum.

### Using Pattern Recognition & Momentum to Trade the Markets.

Pattern recognition is a big field and while we simply try to find simplistic ones, we can always try to combine them and include them in other strategies. One of these strategies is by using patterns to time when the momentum will shift, meaning that we will apply our pattern recognition system on a technical indicator and then use a technique that allows us to see where we can detect a local top or bottom. This is of course easier said than done.

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 Momentum Indicator

The momentum indicator’s formula is extremely simple and can be summed up in the below mathematical representation:

What the above says is that we can divide the latest (or current) closing price by the closing price of a previous selected period, then we multiply by 100. Hence, if we say we are going to use momentum(13), then, we will subtract the current values from the values 13 periods ago and then divide by 100. The momentum indicator is not bounded as can be seen from the formula, which is why we need to form a strategy that can give us signals from its movements.

The above graph shows the EURUSD values versus the Momentum Indicator of 13 periods. This means we are simply dividing the current closing price by the price 13 periods ago and multiplying by 100. Below is the Python code to create a function that calculates the Momentum Indicator on an OHLC array.

```
def adder(data, times):
for i in range(1, times + 1):
new = np.zeros((len(data), 1), dtype = float)
data = np.append(data, new, axis = 1)
```

` return data`

```
def deleter(data, index, times):
for i in range(1, times + 1):
data = np.delete(data, index, axis = 1)
```

```
return data
def jump(data, jump):
data = data[jump:, ]
return data
```

`def momentum_indicator(data, lookback, close, where):`

` data = adder(data, 1)`

```
for i in range(len(data)):
data[i, where] = data[i, close] / data[i - lookback, close] * 100
```

` return data`

### TD Waldo #8

Tom Demark, the renowned famous technical analyst has created many indicators and patterns. Among his many discoveries, he came up with 7 different price patterns that would dub as “**Waldo patterns**”.

Inspired by the cartoon **Where’s Waldo?** Tom has developed these patterns to find short-term tops and bottoms. Any trader or even a receiver of such information would be excited knowing about this, but with hindsight and confirmation bias, the person seeing this, will test the patterns on the chart and *focus on the ones that work while disregarding the ones that do not*. The only way to remedy this problem is by developing a systematic trading strategy based on these patterns, and that is precisely what we are going to do.

To find a potential short-term bottom and a long opportunity:

**The close of the current bar must be higher than the close of 12 bars earlier.****The close of the current bar must be lower than all 7 prior lows.**

To find a potential short-term top and a short-sell opportunity:

**The close of the current bar must be lower than the close of 12 bars earlier.****The close of the current bar must be higher than all 7 prior highs.**

`def td_waldo_8(data, high, low, close, buy, sell):`

```
# Adding a few columns
data = adder(data, 10)
for i in range(len(data)):
# Short-term Bottom
if data[i, 3] < data[i - 1, 2] and \
data[i, 3] < data[i - 2, 2] and \
data[i, 3] < data[i - 3, 2] and \
data[i, 3] < data[i - 4, 2] and \
data[i, 3] < data[i - 5, 2] and \
data[i, 3] < data[i - 6, 2] and \
data[i, 3] < data[i - 7, 2] and \
data[i, 3] > data[i - 12, 3]:
data[i, buy] = 1
# Short-term Top
if data[i, 3] > data[i - 1, 1] and \
data[i, 3] > data[i - 2, 1] and \
data[i, 3] > data[i - 3, 1] and \
data[i, 3] > data[i - 4, 1] and \
data[i, 3] > data[i - 5, 1] and \
data[i, 3] > data[i - 6, 1] and \
data[i, 3] > data[i - 7, 1] and \
data[i, 3] < data[i - 12, 3]:
data[i, sell] = -1
```

` return data`

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

### Creating the Strategy

We will first see how to generate signals on the momentum indicator. This entails the use of a moving average and a few conditions:

**Whenever the momentum indicator surpasses its moving average while being below 100, a bullish signal is generated.****Whenever the momentum indicator breaks its moving average while being above 100, a bearish signal is generated.**

After these conditions are validated, we will see if we have a pattern in the signal bar or at least in the three previous bars. That way we will not filter too much the signals. Therefore, the updated conditions will be:

**Long (Buy) whenever the momentum indicator surpasses its moving average while being below 100 and a TD Waldo 8 buy pattern has appeared either in this current price bar or at least in one of the previous three.****Short (Sell) whenever the momentum indicator breaks its moving average while being above 100 and a TD Waldo 8 sell pattern has appeared either in this current price bar or at least in one of the previous three.**

```
def signal(data, momentum_column, momentum_average_column, waldo_buy, waldo_sell, buy, sell):
data = adder(data, 2)
for i in range(len(data)):
if data[i, momentum_column] < 100 and data[i, momentum_column] > data[i, momentum_average_column] and \
data[i - 1, momentum_column] < data[i - 1, momentum_average_column] and data[i, waldo_buy] == 1 or \
data[i - 1, waldo_buy] == 1 or data[i - 2, waldo_buy] == 1 or data[i - 3, waldo_buy] == 1 and data[i - 1, buy] == 0:
data[i, buy] = 1
for i in range(len(data)):
if data[i, momentum_column] > 100 and data[i, momentum_column] < data[i, momentum_average_column] and \
data[i - 1, momentum_column] > data[i - 1, momentum_average_column] and data[i, waldo_sell] == -1 or \
data[i - 1, waldo_sell] == -1 or data[i - 2, waldo_sell] == -1 or data[i - 3, waldo_sell] == -1 and data[i - 1, sell] == 0:
data[i, sell] = -1
return data
```

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