MasterMartingale v1 --- a multi-strategy EA

 

In my study of doubling or 'Martingale' systems, I've identified three major strategies that can be employed:

1. Counter trend. This is the strategy used in Terminator, Predator, DLM, 10Points3 and others, and involves continuing to trade in the losing direction, doubling each time, until the market corrects enough to generate a profit. It makes money when the trend direction is correctly selected, stalls during tight ranging periods and makes large profits when the market trends normally, with normally expected corrections. If the market trends (or runs) in one direction for a large distance without a sufficient correction, it can easily wipe you out..

2. Alternating trades. This is the strategy I'm trying to use with Collector. In this strategy, when the market moves against your current trade, instead of adding another position in the same direction, you add one in the opposite direction. This should have the effect of building up the progression while the market is stuck in a small range, but taking profit as soon as the range is broken - no matter which way the market breaks. If the market is trending in one direction or another, it will continue to take profitable position after profitable position.

3. Indicator driven. This is the most pure Martingale strategy, in that it always trades in the direction of the trend, as shown by some indicator. It's not trying to catch a trend per se (though it does so very well) and it's not trying to scalp a ranging market.. it simply assumes that the indicator will not continue to be wrong more times in a row than the trader's capital can withstand. Ultimately, it depends on using an indicator that is right more often than wrong, and the more so, the better.

Another important aspect of such a strategy is whether a losing trade is closed when the next (doubled) trade is made, or whether all losing trades are held until the largest one wins, at which time all open trades are closed for an overall profit. The original Martingale strategy - as devised for betting - calls for a bet to end in a realized loss before the next (doubled) bet is made. In keeping with that fact, I've put together an EA that allows any of the three strategies listed above to be selected, but the system always closes a losing trade (at the SL point) before opening the next trade in the progression.

There are also many other bells and whistles that could be added, such as trailing stops, account protection plans, profit tracking and scaling, etc., but this EA is designed to be simple, and so these have been left out for now.

The operation is simple... the TradeMode parameter selects the strategy (1 = counter, 2 = alternating, 3 = indicator), Profit is taken at the TP, and a trade is closed for a loss at the SL. Direction selects the trade direction (1 = long, -1 = short) and is active only for TradeMode 1 (all trades are in the selected direction) and TradeMode 2 (the first trade is in the selected direction, all subsequent trades in the progression are made in an alternating order). In TradeMode 3, the Direction parameter is ignored, and all trades are taken based on the indicator used. In this initial version, I've used the i_trend_s indicator (included).

This code has not been thoroughly tested and may contain some bugs. I have not done any backtesting with MT4 as I don't trust it. I plan to run several tests over the next week to see how it performs... I invite all interested parties to help with this testing and to participate in development of this code..

 

ill start testing on it this week.............

 

I ran this EA in mode 2 (alternating trade directions) for about 12 hours and there's definitely something wrong with it... it kept opening trade after trade until there were 8 or more trades open in each pair... bear in mind that this EA is never supposed to have more than one open trade at a time in each pair - it should close the existing trade before it opens the next one... obviously I've screwed something up. I'll try to ferret out the bug(s) and re-post the next version soon...

 

OK, I dug out some problems and now it's behaving nicely in alternating mode. Theoretically it should also work in the other modes, too, but we need some testing to verify that. I'll try the other two modes starting tonight.

 

Backtests went from 10K to 0 in less than a month. What timefame and setings are you using and on what pairs?

 
Ducati:
Backtests went from 10K to 0 in less than a month. What timefame and setings are you using and on what pairs?

I wouldn't waste my time on backtesting when the EA is not fully debugged yet. We need to be sure there are no kinks or errors in the code first. Besides, backtesting with MT4 has been conclusively proven to be riddled with errors and highly unstable.

As for pairs and timeframes, it should theoretically be useful on any pair, though certainly some pairs will be better than others. For modes 1 and 2, the timeframe is irrelevant as it doesn't use any indicators. For mode 3 I'm currently working with H1 and M15, but that's just a starting point, since the code still needs to be fully debugged and verified.

 

Is style number two on this ea the same as what the collector ea is (trying) doing?

 

The code I have been commissioned to work on is a variation of #2. The system trades almost flawlessly in backtest, and with the last chunk of code I'm working on it should be flawless in forward test. The system uses buystops and sellstops for added complexity :/ It has trailing stops that count as losses. Another "strategy variation" is that it changes the total risk each time, instead of always just increasing the lots. There is a simple percentage based spread to determine lot increase or pip increase. This will avoid channels very well, and if the breakout occurs in the opposite direction then the trade is profitable if the pip increase is less than the total breakout - offset. (It might be easier to work it out for yourself than try to understand that poorly written sentence.)

AFter I meet my basic obligations I will look at your code and try to help bughunt. Since MA based signals are essentially random entry, this is probably a good system for testing. A purely random entry may have slightly better results. Profitability with random entry is based on market volatility mapped to your settings.

With a (50+(broker take/avg trade))% indicator, this will likely be profitable. Without one, it will eventually loose money because of broker spread. Increasing the loops to 6 or 10 just delays the inevitable.

 

Possible bug

Hi ZTrader,

Thanks for sharing the first version of your EA. I may have found a bug, or it may be that I simply don't understand it's logic. When using the Alternating setting (#2), it won't take alternate trades. What I mean is that if I set direction at +1 (long), it ONLY buys long, no matter what. Even if you let it run for a few months in backtesting, it will ONLY BUY. From my understanding, if the market goes against the trade, the EA in this mode should then double the position in the opposite direction.

Thanks again.

Doug

 

@daraknor..

Your project sounds very interesting.. I think the concept we're pursuing is very sound if properly implemented - I'm going the very simple route for now, but I'll be interested to see how your enhanced version works out...

@dcraig..

You may be right. I've made some changes and now it seems to trade properly in Mode 2, and I've been running a test in Mode 1 as well to verify its function. I'll check my progress later and also post the latest version.

 

As promised, I've attached the latest version (1.03) which is testing flawlessly in Mode 2 (alternating) and also in Mode 1 (counter-trade). In Mode 2, it's pulled in 109 pips in just under 16 hours on USD/JPY..

Next I'm going to spruce up the graphics a bit, and also start testing in Mode 3 (indicator)...

Reason: