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:
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.
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:
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)
Here are the two results tables produced by Trading Blox, showing a few stats for each system tested:
Looking at the CAGR and Sharpe ratio on aggregate, here is the how the systems compare:
|Stats||MACD Sys.||MMDI Sys.|
|CAGR Median Absolute Deviation||
|CAGR Coefficient of Variation||0.1205||0.1175|
|Median Sharpe ratio||
|Sharpe ratio Median Absolute Deviation||
|Sharpe ratio Coefficient of Variation||0.1429||0.1556|
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:
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!