When writing a trading system, one of the problems I encounter is determining what kind of market we are in, and what kind of market the software will do well in. Some trading systems do well in smooth trending markets, but do poorly in volatile markets, and other systems need the volatility to do their work.Author Van Tharp divides market types into several different categories of bear, bull or neutral, and then a volatility qualifier for each one. He uses a 100-day period of the S&P 500 to determine the market type. Tharp explains his system and the reasons behind it in several of his books.
An article from the March 2013 issue of Futures magazine gives a different approach. The author, Billy Williams, explains how to use a 20-period moving average and a 40-period moving average in his article “What’s your market type?” In his method, he uses the weekly charts of the financial instrument he is trading to determine its market type, with these rules:
- When the 20-period moving average is above the 40, the market is bullish.
- When the 40-period moving average is about the 20, the market is bearish.
- When there’s no clear winner, the market is going sideways.
Other authors I have read use different tools such as pivot points and average true range to determine the general market type, before making trading decisions. The point is that determining the market type is critical information. You need to know what kind of market you are in before you do anything else.
Once you determine the general market type you are in, you can make better decisions in your code; if your trading system works really well in trending markets, then you can decide to sit out a volatile period, or perhaps switch strategies until the market returns to a trending state.
Take a look at Van Tharp’s market classification system and Billy Williams’ market type rules, and use these in your code. Both Tharp’s and Williams’ systems are easily coded, using simple math to make their classifications.