We are offering Free code for the Empirical Mode Decomposition Indicator (EMD) free TradeStation code helps identify whether a market is in a cycle or trend mode. This indicator is discussed in the article titled “Empirical Mode Decomposition” in the March 2010 Issue of Stocks and Commodities magazine, by John F. Ehlers and Ric Way. For reference, here is a link to the original article. It is a strongly recommended read for anyone interested in TradeStation indicators.
According to the article, when the Trend Component rises above the Average Peaks, the market is in an uptrend. When it is below the Average Valleys, the market is in a downtrend. Finally, when it’s between the two, the market is in cycle mode.
The EMD indicator has 4 optional components: the Bandpass Filter (or cycle component), the Trend Component, the Average Peaks, and the Average Valleys. The inputs include price, period, delta, and fraction. The price defaults to (High + Low) / 2. The period should reflect the cycle period (or frequency) of the market being studied and defaults to 20 bars. The delta should be set to half the bandwidth with common values of 0.1 to 0.5. The fraction is the fraction of the average peaks and valleys used to display the upper and lower limits for the trend component. This value is subjective and can be adjusted to fit your trading style. For swing trades that prefer to trade in cycle mode, a larger fraction might be used such as 0.25.
It’s worth noting that the code contained within the original article will not compile as-is due to the fact that the names of the variables and inputs are now keywords within TradeStation.
We have created a strategy using this indicator. The rules are listed below:
- Go long when the Mean of the Empirical indicator crosses over the upper band (AvgPeak)
- Exit long when the Mean crosses down under the upper band
- Go short when the Mean crosses under the lower band (AvgValley)
- Exit short when the Mean crosses over the lower band
When testing this strategy it seems that for many markets it works better from 2009 forward.
Let’s now look at this system on a very good trending market: crude oil. We will use 12 years of daily data using TradeStation’s continuous contract from July 14, 2003 to July 10, 2015. We will use 25.00 slippage and commission. The strategy (system) is JEhlers_Empirical. Shown below are the parameters we are using for crude oil continuous default contract daily data for 12 years in TradeStation.
Let’s now look at the results:
The results look good but the drawdown is too big. There is something here though in terms of picking up trend mode and direction. Taking a look at the equity curve, we can see that it does much better after 2008. This is not only true of this system for crude but also other markets like the E-Mini Futures. One question that must be investigated now is why?
This system at times has big equity curve givebacks. For example, note the long trade in the center of the chart. It becomes a losing trade but had 10,000 in open equity before it gave it back. We also see that on the short trade we gave back 15,000 off the bottom.
If we look at this system results recently, it has been almost perfect. We gave a few dollars back on the last long trade but it was still profitable and we did get out near the bottom on the recent bear market move.
HYPOTHETICAL PERFORMANCE RESULTS HAVE MANY INHERENT LIMITATIONS, SOME OF WHICH ARE DESCRIBED BELOW. NO REPRESENTATION IS BEING MADE THAT ANY ACCOUNT WILL OR IS LIKELY TO ACHIEVE PROFITS OR LOSSES SIMILAR TO THOSE SHOWN. IN FACT, THERE ARE FREQUENTLY SHARP DIFFERENCES BETWEEN HYPOTHETICAL PERFORMANCE RESULTS AND THE ACTUAL RESULTS SUBSEQUENTLY ACHIEVED BY ANY PARTICULAR TRADING PROGRAM.
ONE OF THE LIMITATIONS OF HYPOTHETICAL PERFORMANCE RESULTS IS THAT THEY ARE GENERALLY PREPARED WITH THE BENEFIT OF HINDSIGHT. IN ADDITION, HYPOTHETICAL TRADING DOES NOT INVOLVE FINANCIAL RISK, AND NO HYPOTHETICAL TRADING RECORD CAN COMPLETELY ACCOUNT FOR THE IMPACT OF FINANCIAL RISK IN ACTUAL TRADING. FOR EXAMPLE, THE ABILITY TO WITHSTAND LOSSES OR TO ADHERE TO A PARTICULAR TRADING PROGRAM IN SPITE OF TRADING LOSSES ARE MATERIAL POINTS WHICH CAN ALSO ADVERSELY AFFECT ACTUAL TRADING RESULTS. THERE ARE NUMEROUS OTHER FACTORS RELATED TO THE MARKETS IN GENERAL OR TO THE IMPLEMENTATION OF ANY SPECIFIC TRADING PROGRAM WHICH CANNOT BE FULLY ACCOUNTED FOR IN THE PREPARATION OF HYPOTHETICAL PERFORMANCE RESULTS AND ALL OF WHICH CAN ADVERSELY AFFECT ACTUAL TRADING RESULTS.