Sunday, September 23, 2012

Meta-Trader - Moving Average Clusters

Welcome back Meta-Traders.

Taking a page from the Oliver Velez material, I recently setup my charts with 3 moving averages, 5, 21 and 50 periods.  I setup the colors with pink for for the 50-period, blue for the 20-period and red for the 5-period.

This is a great combination of indicators since the pink line gives you an excellent idea of the underlying trend, the blue the intermediate trend, and the red line the shortest time frame hugging the price and always leading the other 2 MA's in the direction of the price.   The indicators work well with nearly any time frame for the chart,  but my favorites are M5, M30, H1 and D1.

Next, I noticed that good trading opportunities often occur when all 3 moving averages are bunched up close to each other, along with the price.  Thinking of how to turn this into an indicator, and possibly a trading system, here's what I came up with:

double dMA5 = iMA(NULL, 0, 5, 0, MODE_SMA, PRICE_CLOSE, 1);
double dMA21 = iMA(NULL, 0, 21, 0, MODE_SMA, PRICE_CLOSE, 1);
double dMA50 = iMA(NULL, 0, 50, 0, MODE_SMA, PRICE_CLOSE, 1);
 
/* Lowest of the 3 MA's */
double dLowest = MathMin(MathMin(dMA5, dMA21),dMA50);
 
/* Highest of the 3 MA's */
double dHighest = MathMax(MathMax(dMA5, dMA21),dMA50);

// Grab bar high and low
double dBarHigh = High[1];
double dBarLow = Low[1];

// In Range action
bool InRange = (dBarLow <= dLowest) && (dBarHigh >= dHighest);

In other words, we had to have a single price bar whose low was lower than the lowest of the 3 MA's and whose high was higher that the highest of the 3 MA's.  Put another way we look for a single price bar that straddles all 3 MA's.  The result is an indicator call MA-Clusters with arrows show. above.  The chart above shows a buy signal on Thursday 9/20/2012 with a sell signal a bar or 2 later that led to a nice downward move in EUR/USD.

The signal direction comes in the direction of the price close.  In the example above, we had a lower close, so this would be a sell signal.   Stop loss for the trade would be the opposite end of the signal bar.  In other words, if you took the sell signal above,  the stop loss would be right around where the red arrow is located.  There are several ways to take profit, one is to stick with the trade until you get a close above the 5-bar MA.

The next step was to turn this into an Expert Advisor to see if the system had any merit as an Automated Trading system.  After all, automated trading is what this blog is about, right?  To simplify the system, I used a fixed number of pips for SL and TP.  For the tests below, I used a stop of 55 pips and a Take Profit of 150 pips.

What I found from testing is that the system has some decent recent performance.  On a year-to-date basis, the system is up about 20% with maximum draw down of about 18%. But the system does not appear to be profitable on a stable basis over longer periods of time and therefore seems to have more merit as a tool for manual trading.  Perhaps with more work, it can be turned into a long-term profitable Expert Advisor.

You can find the attached files: ma-cluster.mq4 indicator file, FxMA-Cluster.mq4 expert advisor file and year to date back test files attached to my Yahoo group in case you want to play around with it.

Have a great week.

No comments:

Post a Comment