Welcome to NexusFi: the best trading community on the planet, with over 150,000 members Sign Up Now for Free
Genuine reviews from real traders, not fake reviews from stealth vendors
Quality education from leading professional traders
We are a friendly, helpful, and positive community
We do not tolerate rude behavior, trolling, or vendors advertising in posts
We are here to help, just let us know what you need
You'll need to register in order to view the content of the threads and start contributing to our community. It's free for basic access, or support us by becoming an Elite Member -- see if you qualify for a discount below.
-- Big Mike, Site Administrator
(If you already have an account, login at the top of the page)
In this article I will create a trend filter (also known as market mode filter or regime filter) that is adaptable to volatility and utilizes some of the basic principles of hysteresis to reduce false signals (whipsaws). As you may know I often will use the 200-period simple moving average (200-SMA) to determine when a market is within a bull or bear mode on a daily chart. When price closes above our 200-SMA we are in a bull market. Likewise, when price is below our 200-SMA we are in a bear market. Naturally, such rules will create some false signals. By the end of this article you will have a market mode filter that can be used in your system development that produces better results than a standard 200-SMA filter. To build our better market trend filter we will use the following concepts:
Hysteresis
Price proxy
HYSTERESIS BASICS
When building trading systems many of the decisions have a binary outcome. For example, the market is bearish or bullish. You take the trade or you don’t. Introducing a “gray area” is not always considered. In this article I’m going to introduce a concept called Hysteresis and how it can be applied to our trading.
The common analogy to help understand the concept of Hysteresis is to imagine how a thermostat works. Let’s say we are living in a cool weather climate and we are using a thermostat to keep the temperature of a room at 70 degrees F (critical threshold). When the temperature falls below our critical threshold the heaters turn on and begin blowing warm air into the room. Taking this literally as soon as the temperature moves to 69.9 our heater kicks on and begins blowing warm air into the room driving the temperature up. Once the temperature reaches 70.0 our heaters turn off. In a short time the room begins to cool and our heaters must turn on again. What we have is a system that is constantly turning off and on to keep the temperature at 70 degrees. This is inefficient as it produces a lot of wear on the mechanical components and wastes fuel. As you might have guessed, hysteresis is a way to correct this issue. More in just a moment.
The purpose of this article is to improve our market mode filter. Below is the result of buying the S&P cash index when price closes above the 200-SMA and selling when price closes below the 200-SMA. This is similar to our thermostat example. Instead of turning on the furnace to heat a room we are going to open a new position when a critical threshold (200-SMA) is crossed. In order to keep things simple, there is no shorting. For all the examples in this article, $50 is deducted from each trade to account for both slippage and commissions.
SMA_Line = Average( Close, 200 );
If ( Close > SMA_Line ) then Buy next bar at market;
If ( Close < SMA_Line ) then Sell next bar at market;
Going back to our thermostat example, how do we fix the problem of the furnace turning on and tuning off so many times? How do we reduce the number of signals? Let’s create a zone around our ideal temperature of 70 degrees. This zone will turn on the heaters when the temperature reaches 69 degrees and turn off when the temperature reaches 71 degrees. Our ideal temperature is in the middle of a band with the upper band at 71 and the lower band at 69. The lower band is when we turn on the furnace and the upper band is when we turn off the furnace. The zone in the middle is our hysteresis.
In our thermostat example we are reducing “whipsaws” or false signals, by providing hysteresis around our ideal temperature of 70 degrees. Let’s use the concept of hysteresis to attempt to remove some of these false signals. But like our ideal temperature we want an upper band and a lower band to designate our “lines in the sand” where we take action. There are many ways to create these bands. For simplicity let’s create the bands from the price extremes for each bar. That is, for our upper band we will use the 200-SMA of the daily highs and for the lower band we will use the 200-SMA of the daily lows. This band floats around our ideal point which is the 200-SMA. Both the upper and lower bands vary based upon the recent past. In short, our system has memory and adjusts to expanding or contracting volatility. The EasyLanguage code for our new system look something like this:
SMA_Line = Average( Close, 200 );
UpperBand = Average( High, 200 );
LowerBand = Average( Low, 200 );
If ( Close crosses over UpperBand ) then Buy next bar at market;
If ( Close crosses under LowerBand ) then Sell next bar at market;
Here are the results with using our new bands as trigger points.
Looking at the chart above we can see an improvement in all important aspects of the system’s key performance. Most notably, the Band Cross column shows a reduced number of trades and increased the accuracy of the system. This suggests we eliminated unprofitable trades. Just what we want to see. Below is an example of a trade entry example. Notice the trade is opened when our daily bar closes above the upper band. The thick blue line is our 200-SMA.
PRICE PROXY
A price proxy is nothing more than using the result of a price-based indicator instead of price directly. This is often done to smooth price. There are many ways to smooth price. I won’t get into them here. Such a topic is great for another article. For now, we can smooth our daily price by using fast period exponential moving average (EMA). Let’s pick a 5-day EMA (5-EMA). Each day we compute the 5-EMA and it’s this value that must be above or below our trigger thresholds. By using the EMA as a proxy for our price we are attempting to remove some of the noise in our system. Let’s see how this effects our performance.
SMA_Line = Average( Close, 200 );
UpperBand = Average( High, 200 );
LowerBand = Average( Low, 200 );
PriceProxy = XAverage( Close, 5 );
If ( PriceProxy crosses over UpperBand ) then Buy next bar at market;
If ( PriceProxy crosses under LowerBand ) then Sell next bar at market;
Looking at the graph above we once again see a solid improvement in our system’s performance. We continue to reduce the number of losing trades. Our profit per trade has jumped from $7.15 to $23.17. That’s over a 300% increase. Below is an example of a trade entry example. Notice the trade is opened when our price proxy (yellow line) crosses over the upper band.
The above code is a simple trading system designed to show you the benefit of our “better” trend filter. If we want to use this in a trading system it would be ideal to create a function from this code that would pass back if we are in a bear or bull trend. However, the programming aspect of such a task is really beyond the scope of this article. However, below is a quick example of setting two boolean variables (in EasyLanguage) that could be used as trend flags:
In this article we have created a dynamic trend filter that smooths price by using a simple EMA as price proxy, it adapts to market volatility and utilizes hysteresis principles. With just a few lines of code we dramatically reduced the number of false signals thus, increasing the profitability of the trading system. This type of filter can be effective in building the trading system for ETFs, futures and forex on daily bars.
I thought I would throw in my two cents worth but in short fashion given im typing on a phone.
I agree with what you have done and have used this for many years.
However, to coin another traders term, it still doesn't keep you out of barbwire ie sideways action where you can get whipsawed.
A new trend filter i have come up with, is using two moving averages, say a 20ema and a 40ema.
Ie fast>slow for an up trend. Just like this you still get whip sawed, however if you also said (using forex as an example) that the two ma's had to be seperated by 0.0003, you now have a good trend filter that also keeps you out of the barbwire.
In multicharts i have created this is a study and it displays a horizontal line on the bottom of the chart. The line changes color, where green is a up trend, red is down trend and blue is barbwire (sideways).
If people are interested, i will up load it.
I enjoy your articles keep up the great work. I like your analytical mind and general approach.
I'm looking forward to the rest of this thread.
For those that are interested, here is a screen shot of the Trend ribbon. It is on the chart four times, each using the same MA periods but different MA's ie EMA, WMA, ZMA & TEMA (just for comparisons sake).
Also for comparison is the standard ADX at the bottom with RED lines at 20,25 & 30.
When you combine the color of the trend ribbon with the same color on the price action MA, you get good signals.
Hi Neil,
I m new to the forum and would be interested in your NWT Trend Ribbon Indi. I intend to translate ist into Equilla, ie Tradesignals language :-).
Could you pls sent me the indicator, since I'm not an Elite Member yet.