Rapid Price Pattern Testing

Have you ever wondered what the market does after three down closes in a row? How about what happens after a pivot low is formed and the RSI is below 30? What happens after two inside bars and a breakout to the downside? Searching these types of patterns is one way to locate edges in the market. In this article, I'm going to demonstrate an inexpensive but very interesting tool that can help you locate patterns just like these quickly.

Let's start with a simple pattern such as a 4-bar pattern. With four bars we could look at four consecutive down days or we could look at four consecutive up days. This is rather easy to code and would look like this:

If ( close < close[1] and close[1] < close[2] and close[2] < close[3] and close[3] < close[4] )
then buy next bar at market;


OR

If ( close > close[1] and close[1] > close[2] and close[2] > close[3] and close[3] > close[4] )
then buy next bar at market;


We could then add some code to exit our trade 1, 2, or 3 days after we open a trade. This would be a good way to test the short-term behavior of the market we're testing. But what if we want to also test 3-bar patterns or 5-bar patterns? Well, we would have to introduce a loop in our code. It would look like this:

Setup = true;
For Index = 0 to ConsecutiveLookback-1
Begin
  Setup = Setup and ( Close[Index] > Close[Index+1] );
End;


So far so good. We can easily write some EasyLanguage to do what we want. This loop code would replace our orginal code and give us some flexability. Now let's complicate things a bit.

Consecutive up and consecutive down days are great patterns but there are other patterns we're not even looking for. For example with a 4-bar pattern, we could also look for two bars down, followed by two bars up. What does the market do in that situation? We can't easily handle that with our loop code as that only works for consecutive up or down days. Instead we would need new code.  The code would look like this:

If ( close > close[1] and close[1] > close[2] and close[2] < close[3] and close[4] < close[5] )
then buy next bar at market;


Now what happens if we have two bars up followed by two bars down. Well, we have to write more code.

If ( close < close[1] and close[1] < close[2] and close[2] > close[3] and close[4] > close[5] )
then buy next bar at market;


Next, what would happen if we have a 4-bar pattern that is two bars down, followed by a bar up and then a bar down? Well, we would need to write code for that. You can quickly see that with a four 4-bar price pattern you have a lot of different possibilities. In fact, you have 16 unique combinations you would have to code. If you wanted to explore all possible combinations of a 5-bar pattern you would need to test for 32. With an 8-bar pattern, you would need to test 256 patterns. This is a lot of coding!

Rapid Price Pattern Testing

Can we quickly test for all of these patterns? Yes, with a new TradeStation tool called, Forbidden Pattern Toolbox.

The Forbidden Pattern tool consists of several EasyLanguage strategies that allow us to quickly test different patterns. We're going to look at the ForPatt_NBar_Match strategy to help us explore all patterns in just a few seconds! This strategy has several intersting inputs.

  1. Length
  2. Pattern#Match
  3. LSB
  4. ExitBars

Length allows us to define the number of bars in our pattern search. Entering a 2 means a 2-bar search. Entering a 4 means a 4-bar search. The highest Length we can enter is an 8.

Pattern#Match allows us to define what type of pattern we're going to search for. This will be explained in more detail below. 

LSB determines if we want to look for longs only, shorts only or look for both.

ExitBars allows us to test different hold periods for our trade. That is, we can hold a trade for 1 day, 2 days or 3 days.

Naturally we can make use of the TradeStation optimizer to test a range of values for any of these inputs. For now, lets test a 4-bar pattern. We'll start simple with a four consecutive days down. We set our inputs as follows:

  • Length: 4
  • Pattern#Match: 0
  • LSB: 1
  • ExitBars: 3

That's it! We enter those values and the strategy code will now look for four consecutive down days, buy and then sell three bars later. No coding required! All we had to do was enter in those values in the inputs. Here is the result of our run on the @ES market.

Searching All 4-Bar Patterns Quickly

The real power is to utilize TradeStation optimization feature to analyze all 4-bar patterns. Using out new tool we can analize not only all possible bar combinations but, we can also optimize the holding period for each pattern by optimizing over 1-5 days.

To run this 4-bar optimization we would enter the following inputs:

  • Length: 4
  • Pattern#Match: Optimize 0-15
  • LSB: 1
  • ExitBars: Optimize 1-5

So, we're looking for 4-bar patterns, longs only, and testing holding days 1-5. Below are the optimization results for the top 10 optimizations.

Here we can see the top pattern is a 5 (first column) with a hold day of 5 (second column). But what exactly does a 5 mean for a pattern? Good question!

Binary Patterns

This tool uses a series of zeros and ones to represent patterns. For example, recall our four down day patter. That could be represneted as this:

0 0 0 0

A zero represnts a down day. Four zeros in a row represents four consecutive down days.  What would our pattern look like if we wanted an up-day followed by three consecutive down days?

1 0 0 0

The 1 represnets the up day four days ago followed by three down days.  Lets do one more. Say we want yesterday to be an up day and the previous three days to be down days. What would that pattern look like?

0 0 0 1

The 1 represents the up-day (yesterday) and the previoius three days are down days.  

Once we understand this we then can represent each pattern as an integer. How? Well, if you have a pattern of ones and zeros thats a binary code. If you worked with computers you will know that integers can be represented as a binary pattern.

I'm not going to go into binary patterns or how you convert binary code into integers. Just know that we'll have to take our pattern number, 5, and convert it to a binary number. Once we have that we'll know what our patter is. Here is a converter that will take our 5 and convert it to a binary number.

Turns out a five in binary look like:  0101

Reading from right to left we have yesterday was an up-day, the day before was down, the day before was up and four days ago was down. Written in EasyLanguage it would look like this:

Setup = close > close[1] and close[1] < close[2] and close[2] > close[3] and close[3] < close[4];

It only took us a few minute to discover this pattern! Now lets look at the results. 

This is a fantastic starting point for a possible trading system. This pattern was discovered without writing a single line of code and exploring all possible price bar combinations. Very coool!

Euro Futures Daily Chart

Next I loaded @EC (Euro Futures) and tested all combinations of 5-bar patterns (shorting only). Within a few seconds I discovered this pattern...11011. 

Crude Oil on 60-Minute Chart

Finally I loaded @CL (Crude Futures) on a 60-minute chart and tested all combinations of 6-bar patterns (long only). Within a few seconds there was this pattern...010001.

Very interestding! Will these all turn out to be great trading systems? Probably not but, they are all fantastic looking starting points. 

Conclusion

We just started to scratch the surface on what this tool can do. This tool can explore even more complicated patterns suchas what happens after a pivot low is formed and the RSI is below 30?  This tool will allow you to analyze all Length bar patterns at once and output advanced statistical information on each pattern. And it can do much more! If you're at all interested in locating patterns like these and more, check out Forbidden Pattern Toolbox.

Forbidden Pattern Toolbox

Get Your Copy Today

Take your research to a whole new level with this fully disclosed powerful tool. This tool allows you to define a pattern and then analyze all its possible permutations.This package includes several trading systems. Plus you get fully disclosed code for this very clever EasyLanguage addon.

About the Author Jeff Swanson

Jeff is the founder of EasyLanguage Mastery - a website and mission to empowering the EasyLanguage trader with the proper knowledge and tools to become a profitable trader. Join our EasyLanguage FaceBook group to interact with other EasyLanguage traders! Click the FaceBook icon to join.

follow me on:
>