Premium Market Analysis, Trader Education, Software, and Trading Strategies. Thirty Years Of Skin In The Game

Price Action Strategies, Trading Strategies

Machine Generated DIA Patterns and Trading Systems

The steps are presented here for discovering price patterns in DIA (SPDR Dow Jones Industrial Average) historical daily data using the Price Action Lab search function, testing the results in an out-of-sample and then creating a trading system. It is shown that Price Action Lab can identify price patterns in a completely deterministic (reproducible) way that result in a statistically significant and profitable system in a sufficiently long out-of-sample period with high win rate, Sharpe ratio and profit factor.

This is the fifth in a series of posts with the aim of demonstrating the process of machine generation of trading systems based on price patterns. The first post was about SPY patterns, the second was about QQQ patterns, the third was about EC futures and the fourth post was about YM futures. Anyone interested in purchasing the code for these systems please follow this URL for the proper email address to use. Full system code is available for Tradestation and Amibroker (Charts created with AmiBroker – advanced charting and technical analysis software.”).

This post was motivated by an email sent by a demo user of the program asking whether Price Action Lab patterns can work not only in forward out-of-sample periods but also in backward out-of-sample periods. In addition the email sender asked to use in an example of this sort a liquid enough security with a chart exhibiting several major up and down swings and to use a small enough target and a stop in the search so that the average trade duration is relatively small. In addition, the results should include a good mix of long and short patterns. These are very reasonable requirements that are supposed to minimize the chance of curve-fitting the results to the price series and also maximize the chance of getting a robust system. DIA was selected because in its price history since its inception it exhibits major up and down swings and long periods of sideways movement, as it may be seen from the daily chart below:


The results presented here, except the pattern code, can be confirmed by anyone with a demo version of Price Action Lab. Actually, the demo version was used to generate the results of this study.

Step 1: Create a target and stop file

In this example I will use 2% for the profit-target and for the stop-loss for an expected average win to average loss ratio close to 1. A T/S file is created with the values as shown below and then saved as 2.trs:


Step 2: Create a search workspace


 The workspace is created by selecting the following: 

a) The T/S file we created by the name 2.trs
b) The in-sample data file DIA.txt. Range: 01/02/2001 – 04/05/2012.
c) The trade parameters: “%” is is marked to indicate that the values in the selected T/S file stand for percentages of the entry price, which is selected as the open of the next bar under Inputs. The Delay input is kept marked off. (Using delay inputs will be the subject of another post).
d) Under search parameters we input 68 for the percent minimum win rate for long patterns and 66 for short patterns. We also input 29 for the minimum number of trades and 10 for the maximum number of consecutive losers. The profit factor is set at the default value (1.50).
e) The date range in the data file is shown under File Date Range. In this case it corresponds to the in-sample range. The Search Range is left to 500. This means that Price Action Lab will demand that all patterns that are found to satisfy the performance criteria set in (a) – (d) must have at least one historical trade in the most recent 500 bars. Finally, the Extended search option is checked and we run the workspace.

 Step 3: In-sample results

Price Action Lab will run for an interval of time depending on computer CPU speed but in this particular case it will complete the search after about 30 minutes on the average.  The output should look like the one below: 


Each line in the above results corresponds to a price pattern that satisfies the performance parameters specified by the user.  Index and Index Date are used internally to classify patterns. Trade on is the entry point, in this case the Open of next bar. P is the success rate of the pattern, PF is the profit factor, Trades is the number of historical trades, CL is the maximum number of consecutive losers, Type is LONG for long patterns and SHORT for short patterns , Target is the profit target,  Stop is the stop-loss and C indicates whether % or points for the exits, in this case it is %. Last Date and First Date are the last and first date in the historical data file.

It may be seen from the results that Price Action Lab found 21 patterns, 12 long and 9 short, which satisfied the performance criteria specified on the workspace for the in-sample. (Please keep in mind that this is an example for specific risk/reward criteria and performance parameters). One could argue that these patterns are random and a result of survivorship bias, i.e. they survived by chance alone and they have no predictive power. This is the reason we used an in-sample to search for the patterns. We will now use the out-of-sample to see how these patterns performed in a regular backtest. Please note that:

Price Action Lab does not look at the out-of-sample when searching the in-sample. This is very important because if a program looks at the out-of-sample and then selects patterns from the in-sample that also worked well in the out-of-sample this is an extremely bad (and even deceiving) practice that is known as data-snooping.

– Price Action Lab does not find systems that later allow varying their parameters for fitting their performance in the out-of-sample. All patterns found are parameter-free, eliminating an important but serious concern dealing with curve-fitting.

Price Action Lab does not use genetic programming, neural networks, permutations or any other methods employed by some other programs that produce random and curve-fitted systems. Price Action Lab is based on a proprietary deterministic algorithm that produces the same output each time it encounters the same conditions and that is in compliance with the standards of scientific testing and analysis.

 Step 4: Out-of-sample testing

Price Action Lab makes it very easy to test in the out-of-sample all patterns found in the in-sample results. Just click on Test Patterns and then select the location of the out-of-sample data file, as shown below:


It may be seen that the out-of-sample period is from 01/28/1998 to 12/29/2000. Thus, this is a backward out-of-sample test, instead of the usual forward test.

The results are obtained shortly after making the selection and confirming it: 


It may be seen that the pattern performance parameters changed due to the out-of-sample backtest. As a result,  8 patterns have profit factor less than 1, meaning that they are losers in the out-of-sample. 

The profit factor of this group of 21 price patterns can be calculated using the backtesting function of Price Action Lab applied to each pattern, adding gains and losses separately and then calculating the ratio. In this case, Amibroker (Charts created with AmiBroker – advanced charting and technical analysis software.”) code was generated and a simple system was built that uses the OR condition to combine long patterns and short patterns separately. Below is a table with key performance statistics for the in-sample and out-of sample:

  W LT ST PF R Sharpe E
In-sample 66.04% 371 321 2.15 1.11 2.68 61.45
Out-of-sample 56.74 73 105 1.39 1.06 1.29 29.78

Legend – W: win rate, LT, ST: number of long and short trades, PF: profit factor, R: avg. win to avg. loss ratio, E: expectancy (average trade).

It may be seen from the above table that the system maintained a high win rate, a high profit factor and Sharpe ratio in the out-of-sample test. The average bars in trades parameter was equal to 4.22 for the combined samples.

Below is the equity curve for the system for both the in-sample and out-of-sample periods:


The above equity curve was based on $10,000 of initial capital. The position size was constant and equal to 100 shares. No pyramiding and no compounding was used. No dividends were included in the performance results. It may be seen than in the out-of-sample the system experiences a small drawdown in the order of 9%. Notice however how brutal was the out-of-sample period from mid 1999 to the end of 2000, with the market moving sideways with high volatility. Thus, this was a very challenging out-of-sample for the system and the resulting performance can be deemed very satisfactory. 

Step 5:  Add the systems to system tracking or generate code

The patterns Price Action Lab discovered can be added to the system tracking module of the program for receiving notifications when a signal is generated or, if the user wishes, code can be generated for implementing a system in some other popular platform.

Comments and FAQ

How long will these patterns remain profitable? This is unknown. However, the real value of Price Action Lab is that the search can be repeated again after one year, for example, and the systems can be upgraded. This is not like buying a black-box and have to live with it.

Do I really need the out-of-sample test since it reduces available data for the in-sample? Actually, some people believe that out-of-sample testing is not needed after it is used to confirm that a certain process of finding trading systems leads to significant results. Thus, if it is shown than Price Action Lab can get significant patterns in an out-of-sample as long as the one in this post, then the process can be eliminated all together and the available data can be used as an in-sample to increase search flexibility. Instead of doing out-of-sample tests, the search is rerun every six months and the system is rebalanced.

Disclosure: no relevant position at the time of this post.

Charting program: Amibroker (Charts created with AmiBroker – advanced charting and technical analysis software.”)