Building A Better Trend Filter - EasyLanguage Programming | futures io social day trading
futures io futures trading


Building A Better Trend Filter
Updated: Views / Replies:7,149 / 21
Created: by Jeff65 Attachments:2

Welcome to futures io.

(If you already have an account, login at the top of the page)

futures io is the largest futures trading community on the planet, with over 90,000 members. At futures io, our goal has always been and always will be to create a friendly, positive, forward-thinking community where members can openly share and discuss everything the world of trading has to offer. The community is one of the friendliest you will find on any subject, with members going out of their way to help others. Some of the primary differences between futures io and other trading sites revolve around the standards of our community. Those standards include a code of conduct for our members, as well as extremely high standards that govern which partners we do business with, and which products or services we recommend to our members.

At futures io, our focus is on quality education. No hype, gimmicks, or secret sauce. The truth is: trading is hard. To succeed, you need to surround yourself with the right support system, educational content, and trading mentors – all of which you can find on futures io, utilizing our social trading environment.

With futures io, you can find honest trading reviews on brokers, trading rooms, indicator packages, trading strategies, and much more. Our trading review process is highly moderated to ensure that only genuine users are allowed, so you don’t need to worry about fake reviews.

We are fundamentally different than most other trading sites:
  • We are here to help. Just let us know what you need.
  • We work extremely hard to keep things positive in our community.
  • We do not tolerate rude behavior, trolling, or vendors advertising in posts.
  • We firmly believe in and encourage sharing. The holy grail is within you, we can help you find it.
  • We expect our members to participate and become a part of the community. Help yourself by helping others.

You'll need to register in order to view the content of the threads and start contributing to our community.  It's free and simple.

-- Big Mike, Site Administrator

Reply
 2  
 
Thread Tools Search this Thread
 

Building A Better Trend Filter

  #1 (permalink)
 Vendor: www.systemtradersuccess.com 
Gurnee, IL
 
Futures Experience: Advanced
Platform: TradeStation
Broker/Data: TradeStation
Favorite Futures: Futures
 
Posts: 46 since Apr 2010
Thanks: 17 given, 92 received

Building A Better Trend Filter

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;
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).


Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

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.
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).



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.

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).
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;
Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

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.

Please register on futures.io to view futures trading content such as post attachment(s), image(s), and screenshot(s).

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:
BullMarket = PriceProxy > UpperBand;
BearMarket = PriceProxy <= LowerBand;
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.

Reply With Quote
The following 8 users say Thank You to Jeff65 for this post:
 
  #2 (permalink)
Quick Summary
Quick Summary Post

Quick Summary is created and edited by users like you... Add FAQ's, Links and other Relevant Information by clicking the edit button in the lower right hand corner of this message.

 
  #3 (permalink)
Elite Member
Newcastle, Australia
 
Futures Experience: Intermediate
Platform: Multicharts 8 - Full Version
Broker/Data: IB
Favorite Futures: SPI,FTSE100, 6E, 6A
 
Posts: 285 since Oct 2010
Thanks: 108 given, 177 received


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.

Neil.

Sent from my GT-I9100T using Tapatalk 2

Reply With Quote
The following 5 users say Thank You to NW27 for this post:
 
  #4 (permalink)
Elite Member
Netherlands
 
Futures Experience: Advanced
Platform: Ensign, Multicharts
Favorite Futures: SP500
 
Posts: 95 since Nov 2009
Thanks: 66 given, 56 received

yes, i'm interested in your trend filter

Reply With Quote
 
  #5 (permalink)
Elite Member
Newcastle, Australia
 
Futures Experience: Intermediate
Platform: Multicharts 8 - Full Version
Broker/Data: IB
Favorite Futures: SPI,FTSE100, 6E, 6A
 
Posts: 285 since Oct 2010
Thanks: 108 given, 177 received

Hi Jeff,

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.

Neil.
DownLoad NWT Trend Ribbon

Attached Thumbnails
Building A Better Trend Filter-nwt-trend-ribbon-ver1.png  
Reply With Quote
The following 3 users say Thank You to NW27 for this post:
 
  #6 (permalink)
 Vendor: www.systemtradersuccess.com 
Gurnee, IL
 
Futures Experience: Advanced
Platform: TradeStation
Broker/Data: TradeStation
Favorite Futures: Futures
 
Posts: 46 since Apr 2010
Thanks: 17 given, 92 received


NW27 View Post
Hi Jeff,

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.

Neil.
DownLoad NWT Trend Ribbon

Thanks. Glad you like the articles.

Thank you for providing the link to the Trend ribbon. I'll take a look at it.

Reply With Quote
 
  #7 (permalink)
 Vendor: www.systemtradersuccess.com 
Gurnee, IL
 
Futures Experience: Advanced
Platform: TradeStation
Broker/Data: TradeStation
Favorite Futures: Futures
 
Posts: 46 since Apr 2010
Thanks: 17 given, 92 received


Jeff65 View Post
Thanks. Glad you like the articles.

Thank you for providing the link to the Trend ribbon. I'll take a look at it.

Just realized I can't view the code. Must be an elite member. Oh well...

Reply With Quote
 
  #8 (permalink)
Elite Member
Newcastle, Australia
 
Futures Experience: Intermediate
Platform: Multicharts 8 - Full Version
Broker/Data: IB
Favorite Futures: SPI,FTSE100, 6E, 6A
 
Posts: 285 since Oct 2010
Thanks: 108 given, 177 received


Jeff65 View Post
Just realized I can't view the code. Must be an elite member. Oh well...

I guess you will have to join
Tis only a small donation for the privilege of using a great forum.

Or I could send you the code.

Neil.

Reply With Quote
 
  #9 (permalink)
Trading Apprentice
Bremen + Germany
 
Futures Experience: Master
Platform: Tradesignal
Favorite Futures: Stocks
 
Posts: 1 since May 2012
Thanks: 0 given, 0 received

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.

Cheers - Iro

Reply With Quote
 
  #10 (permalink)
 Vendor: www.systemtradersuccess.com 
Gurnee, IL
 
Futures Experience: Advanced
Platform: TradeStation
Broker/Data: TradeStation
Favorite Futures: Futures
 
Posts: 46 since Apr 2010
Thanks: 17 given, 92 received



NW27 View Post
I guess you will have to join
Tis only a small donation for the privilege of using a great forum.

Or I could send you the code.

Neil.

This post almost slipped by me. It would be great if you could send me a copy of the code.

I probably should join. Another thing to look into. Item #2343 on the to-do list.

Thanks.

Reply With Quote

Reply



futures io > > > > > Building A Better Trend Filter

Thread Tools Search this Thread
Search this Thread:

Advanced Search



Upcoming Webinars and Events (4:30PM ET unless noted)

Linda Bradford Raschke: Reading The Tape

Elite only

Adam Grimes: TBA

Elite only

NinjaTrader: TBA

January

Ran Aroussi: TBA

Elite only
     

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help using Awesome Oscillator as a filter protrader007 NinjaTrader Programming 19 August 30th, 2016 05:11 PM
Building Blocks of a Trading System (1) - Trend Filter Fat Tails Elite Automated Trading 31 December 21st, 2015 11:55 AM
SuperTrend EA with Trend Strength Filter trendfly Platforms and Indicators 7 July 2nd, 2012 02:44 PM
Three Way Filter with Boolean Setup zeller4 NinjaTrader Programming 3 July 19th, 2011 09:19 PM
Filter trades by using +DMI, help needed abcplot EasyLanguage Programming 5 May 19th, 2011 04:59 PM


All times are GMT -4. The time now is 01:53 AM.

Copyright © 2017 by futures io, s.a., Av Ricardo J. Alfaro, Century Tower, Panama, +507 833-9432, info@futures.io
All information is for educational use only and is not investment advice.
There is a substantial risk of loss in trading commodity futures, stocks, options and foreign exchange products. Past performance is not indicative of future results.
no new posts
Page generated 2017-12-11 in 0.18 seconds with 20 queries on phoenix via your IP 54.226.34.209