I read this article today:
https://www.mql5.com/en/articles/5008
and as it is raining here in Greece I thought it would be an interesting way to pass the time trying to code something around the idea.
Basically in the article it analyses strategies based on reversing your trading direction after every losing trade and doubling your stake after every losing trade. If your trade wins then stake size returns to minimum.
Note: Doubling your stake after a losing trade is the classic and very dangerous martingale system – I do not advocate trading this way unless you have a very,very,very big starting capital and are keen to lose it!
This is the code I came up with:
once positionsize = 1
martingale = 2
if longonmarket then
sell at market
if close > positionprice then
positionsize = 1
endif
if close < positionprice then
positionsize = positionsize * martingale
longshort = 0
endif
endif
if shortonmarket then
exitshort at market
if close < positionprice then
positionsize = 1
endif
if close > positionprice then
positionsize = positionsize * martingale
longshort = 1
endif
endif
if (not onmarket and longshort = 1 and (long entry conditions)) or (not onmarket and positionsize = 1 and (long entry conditions)) then
buy positionsize shares at market
endif
if (not onmarket and longshort = 0 and (short entry conditions)) or (not onmarket and positionsize = 1 (short entry conditions)) then
sellshort positionsize shares at market
endif
My version was intended for the daily chart. If either long or short entry conditions are met then a trade is opened at minimum size in that direction. The position is held for one bar and closed. If it is a loser then the the next trade can only be opened in the opposite direction and stake size is doubled. If it is a winner then trades can be opened in either direction and stake size is returned to minimum stake size.
You will note that I have not included my entry conditions just in case anyone was tempted to run it live!
I tested it with very basic entry conditions based on a single very popular indicator. I decided to test it on forex as it is in my mind a casino style strategy which suits the casino that is the forex markets. I was surprised by the results.
Here is the results for the strategy on EURUSD daily with the martingale position sizing turned off so level stakes. Spread = 2
[attachment file=85849]
…and this is with the martingale doubling the position size after losing trades:
[attachment file=85850]
Most people would have a heart attack placing a £256 bet after a run of 8 losers so I decided to see what happened if you didn’t double up but multiplied by a lesser number. Here are the results:
[attachment file=85851]
….and the results for a multiple of 1.5:
[attachment file=85852]
The biggest all time stake size with a 1.5 multiple is now just £25.62 and that is with a starting stake of 1.0. At the minimum stake size for EURUSD of 0.5 this would be even less at just £12.81.
So it seems that some form of martingale can be used with smaller starting capital but I could not get similar results on other forex pairs so I may have just hit on something that works on EURUSD. Perhaps I just got lucky with my simple entry conditions and the trade direction reversing. Maybe if this rain continues I will investigate further.
Remember this was just for fun and not a strategy idea that I’d recommend putting anywhere near a live account!