Systematic Trading research and development, with a flavour of Trend Following
Au.Tra.Sy blog – Automated trading System header image 2

MMDI Portfolio Filter in Trading Blox

February 2nd, 2010 · 4 Comments · Backtest, Futures, Software, Strategies

David Varadi, from the very good CSS Analytics blog, pointed me to his interesting findings on a Mean Median Divergence Indicator (MMDI) he devised as a replacement to the standard MACD.

I wanted to test the MMDI as a follow-up to Moving Median: a better indicator than Moving Average?. This also provided a good opportunity to test Trading Blox (which I am thinking of buying).

MMDI: What is it?

In short, this is an indicator very similar to the MACD, except that the short moving average of the MACD is replaced by a moving median.

Portfolio Filter: Trade with the trend

One concept often used to improve the edge of a trading system is to look at 2 or more timeframes. The main timeframe (shorter one) is used for triggering trading signals (eg Donchian Channel breakouts), and the longer timeframe is used to determine the direction of the main trend. The filter rules prevent any trade signal to be taken if it goes against the main trend.

Trading Blox: a componentized testing framework

A great feature of Trading Blox is that it provides you with a skeleton workflow that forms the framework for the backtesting process. What this means is that Trading Blox implements and runs its logical workflow in the simulation loop (ie read data, update indicators, check entry signals, check exit signals, post-simulation scripts, etc.) but provides you with hooks at every step (about 35 hooks per simulation loop) where you can write your own code for customisation (with access to Trading Blox internal objects).

Next is the concept of blocks, which represent the different components of a trading systems (Entry signals, Money Management, Risk Management, Portfolio Filter, etc.). These blocks are easily reusable in any system and implement the functionality required via the code contained in their scripts.

One such block we are interested in for today is the MACD Portfolio Filter:

MACD Portfolio Filter Blox

MACD Portfolio Filter Blox

This block stops the system from opening new trades in the opposite direction to the trend (the direction of the trend is derived from the MACD value).

MMDI Portfolio Filter

It was easy to use the standard Donchian channel system that ships with Trading Blox and replace its MACD Portfolio filter block by an implementation of the MMDI Portfolio filter. All it took was a copy of that block and an update of some of the scripts to implement the MMDI indicator and the filtering based on its value.

Indicator calculation:

mmdiIndicator=Median(ohlcDiv4,mmdiShort)-emaIndicator

Filtering code (long side):

[...]
' If positive, then allow long trades
IF ( mmdiIndicator > 0 ) THEN
	instrument.AllowLongTrades
ENDIF
[...]

And applying the new block (MMDI Portfolio Filter) to the system in the system editor screen:

SystemEditorMMDI

System Editor


 
 

Test Scenario

The test is a comparison of the standard Donchian Channel breakout Tend Following system with MACD Portfolio Filter against its variation using the MMDI Portfolio Filter.

In order to get more data points (and to test Trading Blox parameter stepping), the comparison was run over a combination of system parameters:
- Long MMDI Moving Average: 200, 250 and 300
- Short MMDI Moving Median: 50, 62 and 74
- Donchian Channel Length (Entry): 20, 30 and 40
- Donchian Channel Length (Exit): 15
- Stop level: 2 x ATR(40)
- Slippage: 15% of ATR (+3% at rollover)
- Commissions: $12.50 per contract
- Dates: 01/01/2001 to 09/30/2010
- Instruments: 28 liquid futures (currencies, commodities, financials)

Test Results

Here are the two results tables produced by Trading Blox, showing a few stats for each system tested:

MACD Portfolio Filter Results

MACD Portfolio Filter Results - click to expand

MMDI Portfolio Filter results

MMDI Portfolio Filter results - click to expand

Looking at the CAGR and Sharpe ratio on aggregate, here is the how the systems compare:

Stats MACD Sys. MMDI Sys.
Median CAGR
13.94%
15.58%
CAGR Median Absolute Deviation
1.68%
1.83%
CAGR Coefficient of Variation 0.1205 0.1175
Median Sharpe ratio
0.42
0.45
Sharpe ratio Median Absolute Deviation
0.06
0.07
Sharpe ratio Coefficient of Variation 0.1429 0.1556

Conclusions

First on Trading Blox: it was fairly straight-forward to code up this new indicator and system. The stepped parameter tests were also really quick to run (<1 min). Still pretty pleased and feeling at ease with it.

The test results show a small improvement in the MMDI favour. A possible explanation might be that the more volatile nature of the moving median (as illustrated in the moving median indicator post) allows it to pick up changes in trend faster (and get in them at an earlier, better price).

The whipsawing produced in the Moving Median crossover run would normally take place during range-bound markets, where few Donchain breakouts would happen, therefore cancelling the extra noise and losses associated with them.

Might be worth investigating further…
 
 
PS: David’s code for MMDI on TradeStation is available for free on his dvindicators.com website

PS2: As a comparison, and to illustrate the impact of a portfolio filter, here are the results for the same system without any Portfolio Filter:

Only 3 sets of results as the MACD/MMDI stepped parameters have been removed

Only 3 sets of results as the MACD/MMDI stepped parameters have been removed - click to expand

Without the trend filter applied to the portfolio, the Donchian channel breakout system now exhibits a negative performance (-2.68% on average across the 3 backtests). The trend is definitely your friend!

Related Posts with Thumbnails

Tags: ···

4 Comments so far ↓

  • bb

    Sorry for the simpleton question, but what does ” filter rules” mean in this context? Tried searching your blog and previous entries linked on this entry and couldn’t find the answer.

    Do you mean that you’re looking for a cross of the Short MMDI over the Long MMDI to initiate a trade?

  • Jez

    No worries for the question bb. The filter rule is simply that: trades on the shorter timeframe are only taken in the direction of the trend on the longer timeframe.

    In practice: only take the “long/buy” channel breakout signals when the MMDI is positive and only take the “short/sell” channel breakout signals when the MMDI is negative.

    Note that the MMDI is the difference between the short moving median and a long moving average – so it will only be positive when the short median has crossed the long average.

  • bb

    Thanks Jez, I appreciate it.

  • david varadi

    hi jez, cool app thanks, and the blox software looks pretty good too.

    cheers
    dv

Leave a Comment