Silly Math

I’ve been trying to build an EA based on a variant of the martingale. The basic idea is that I don’t want to analyse what is happening in the market and make a technical or fundamental trade decision, but rather switch on a stats based EA that builds my trading account like a high interest bearing bank account.

So the principle martingale I use has the following setup:

[ul]
[li] Trade Buy or Sell is generated by the EA at complete random
[/li][li] The stop loss is 6 pips + % of 15 minute ATR
[/li][li] Take profit is 2.5 times the stop loss
[/li][li] The martingale (Risk) grows at 1.4 times the previous risk, with a view to recoup all losses and take the originally intended profit.
[/li][li] 20 * Daily Target Return = Explosion Loss (when lost full number of steps in my martingale)
[/li][/ul]

So the research stage is based on a Random Variable moving between the various states in a Markov chain in a stochastic process. If I setup and Markov chain with 31 states where state -2 and state -5 are equal to 2 and 5 consecutive losses respectively and state 1 equals a win. I am trying to find the transition probabilities between each state i.e prob lose 5 times given lost 4 time etc… and the mean recurrence time i.e. if I have lost 5 times how long will it take on average before I lose 5 times again. So that I can find the optimal number of steps to have in the martingale.

So I have so far done a crude test with 10 currency pairs for a sixth month period at the tick level, and using a 13 step martingale as a starting point have found that the chances of losing 13 times in a row in any given day ranges from 3.5% (GBPUSD) to 0.8% (USDCHF). Brexit goes some way to explain the anomalous results for Cable but the average across all 10 pairs was 1.4%.

On the face of it that looks interesting because for example if I traded 100 days making £1000 on a winning day and lost £20,000 on a losing day, then with a 2% prob loss I would have lost £40,000 but made £98,000.

But still you never know when the losing day will arise, and given my luck; and assuming all the calculations were right, I would still probably end up losing on my first day. Losing in one pair over the course of time is inevitable, but what if I selected which pair out of 10 to trade the system completely at random too. So far I have not seen any correlation between losing on one (exceed 13 steps) and losing on another, in fact I can run the system multiple times on the same day on one pair and get completely different results due to the random nature of the trade selection.

So in my data there is no cross-over/overlap, no “explosion” on one pair and an explosion on another occurring at the same time. (I would have to run the test 500+ times to double check that).

So I could possibly reduce the “explosion” risk further by selecting one pair in 10 at random each day and running the system on that one. In theory if the average daily lose rate is 1.4 say 2% (1:50) then i could reduce the odds further to Prob(Choose Pair) * Prob(Pair Loses Today) = 0.1 * 0.02 = 0.002 (1:500).

I have run a crude test on the tester and it has worked for a 6 month period so far. I would however to to redo the same run a couple of hundred times to try and get real sense the likely odds.

Still a better way might be to look at the mean recurrence time. If Cable has a mean recurrence time for state 13 at 23 days. Then I could potential improve my odds beyond (1:500) by choosing to trade soon after the last time Cable lost 13 times in a row and also apply the same principle to all 10 pairs; the closer it is to the last explosion given the mean recurrence time would be calculable odds of losing on that particular date which i could compare with other pairs and select the least likely option.

anyway I have not done all the tests and double checked the math and that might take some time, also speaking with an academic to make sure i’m not getting this thing wrong would be a good idea. But I thought I would share it with you.

Your opinions would be most welcome.

I’m afraid not: this is just a variation of the “gambler’s fallacy”.

Your logic here is the same as that of someone backing red at roulette, and imagining that he has a greater winning chance if he waits until black has come up for many consecutive spins before betting. It simply isn’t so.

Hi, mate! I’ll advise against using any martingale-based system. It is a fast route to much sorrow in this business. Trade safe.

Wouldn’t it be better not making the trade completely random but in the direction of the trend? In my tests with martingale the EA could lost 2 years of profit in the last trade It was profitable with 4 levels and making good profit on my first test period But if the period started with a loss it was game over!

Thanks for the post. I’ve had a few bad experiences with exploding martingales but I thought I’d take another look at it.

I used to manually trade a martingale with 6 steps 1:1 R:R so doubling my stake each time and experienced the same kind of things, the problem with coupling a martingale with a particular strategy is the dependence, which makes sense.

I used to log my trades with VBA in excel to figure out the transition probabilities and track my performance relative to the past to identify bad (High Risk - Stop trading) phases. and what was clear from the evidence was that the higher up on the levels (states) that I went the more likely I was going to lose again.

When you are losing in a particular market it is because your system or approach is not suitable for it at that time, if you are assuming just a 50:50 chance of losing it is actually much higher in those periods for that reason and in that case doubling your trade sizes is just double down on a losing strategy.

I think that might be why you start of and continue on to “explode” very quickly, I don’t think a martingale adds value in those situations. I could only ever go for a max 2 weeks before running out of levels.

With a random trade generator some of the dependence is removed, but I notice there is still a narrow set of market type for which the odds of reaching max level is higher but I think that is good thing, because you bow only have to classify the market type and find a way to identify it prior to using your EA in that period.

I think you might be right about that, but I will have to look at it further. For now I will approach it experimentally to see how it might work in practice then dust off some old stats books and look at the theory.

Can I post excel here?

My own perspective on “Martingales” and related position-sizing (and I hope it isn’t unwelcome :8: ) …

Either a method has a genuine edge (net positive expectation) or it doesn’t.

If it does, then it doesn’t need any kind of Martingale position-sizing: it will grow its account most safely (with least risk-exposure) by gradually increasing the stakes in accordance with the account-size.

If it doesn’t, then it isn’t possible to give it an edge by varying the position-size according to previous results, and what’s needed is a new method, not new staking.

Each trade one enters should have a position-size in accordance with its proven edge, your account capital, your degree of risk aversion, and all the normal position-sizing factors.

There’s no logic at all in deciding how much to risk in accordance with what the results of its immediately preceeding trade(s) happened to be: that’s just the “gambler’s fallacy” again, in a different guise.

Systems that don’t have a genuine edge shouldn’t be traded at all. They won’t acquire one by [U]increasing[/U] the risk when [U]losing[/U]. One thing is certain: escalating the stakes during a losing run is eventually going to be a sure-fire way to the poor-house.

I understand your point. But I would say it comes from a very definite philosophy or your approach to trading. There are a number of Funds that apply statistical methods (not necessarily martingale) to exploit market opportunities that would not conform to your approach but non the less work. Finding the net positive expectation in this case is where i’m trying to go with the research, the problem is there are too many moving parts involved to start with the statistical theory and move on to implementation.

I would have to narrow the field by finding something that seems to work then try to understand fundamentally in first principles stats theory why is should work or what the pitfalls might be or how I could tweak it.

Gamblers fallacy is most sure relevant here, but not strictly because that assumes an non absorbing markov chain with infinite states. If i place an absorbing barrier on end by taking profit after a distinct number of wins, or limiting my trades from say 12,000 continuous trades in 6 months then the maths starts to look different. It’s quite complex and I think my time would be more efficiently used finding the result by experiment then trying to understand it.

Fair enough - I’ll certainly plead guilty to having a mathematical/statistical approach and acknowledge that not everyone does (although I believe, myself, that almost everyone [I]profitable in the long term[/I] does - whether they actually call it that or not).

I’d say they all do. All the serious ones, anyway? As far as I know?

We might disagree there: I don’t believe there are [B][U]any[/U][/B] long-term profitable ones that [U]increase[/U] the position-sizes when [U]losing[/U]!

If you can show me one, then I’ll happily and openly admit to being mistaken … but really, that would make [I]no[/I] sense, at all, so please excuse my mentioning that I’m not exactly holding my breath. :wink:

With apologies, you lost me, there. Either the system/method has an overall edge at level stakes or it doesn’t. If it doesn’t, you can’t import one into it by increasing the position-size during a losing run. This is simply factual. It’s objective and mathematically provable. However complicated the method is, one has to test it and know confidently that it has an edge - nobody should be trading with real money (non-demo) a system that doesn’t have a proven edge? But if it does, then its appropriate position-sizing can be worked out fairly easily?

The “gambler’s fallacy” has absolutely nothing to do with Markov chains at all.

An understanding of Markov chains is [I][U]not[/U][/I] needed to work out whether a system has an edge or to derive its appropriate position-sizing according to one’s own risk comfort-level/aversion-level.

I wish you well with it.

Thank you for your reply. And I don’t mean to be rude but doing basic math to determine net expectation on a trading system is not what i would consider having a “mathematical/statistical approach” that is just common sense computing that forms a basic part of building any trading approach.

And no not trading philosophy either unfortunately. There are hundreds and thousands of funds and investors with different approaches “Philosophies” to trading e.g. George Soros only takes short positions and has built his career around that unique approach, for whatever reason he decided upon it in the first place; in which case you could go to him with the most brilliant long trading idea and he would decline because it was not in line with the philosophy of his fund.

You seem to come with the impression that there is one way to trade, your way and that everybody else is stupid.

Position sizing losing trades if you read my earlier comment is not a good idea, because you’re doubling down on a strategy not appropriate for the market conditions; wrong headed, that is the whole point of randomizing the process and even that doesn’t give you complete independence as I have noticed a cluster of fails around particular periods - so what is the level of independence and how can you build that into your calculations and the model: complexity.

Apples and oranges. You simply can’t see beyond your own style of trading. And gamblers fallacy can absolutely fit within the framework of a markov chain stochastic process (and I was trying to be kind to your other reply also in giving that any weight). Thank you for lecturing the Actuarial Science major on basic stochastic processes.

Thanks for the wishes of luck in investigating a new trading technique. We’ll see how it goes.

I could really use your help. Based on the information I have provided so far, would you be able to tell me what the basic net expectations are as a starting point, for clarity:

65 trading days
10 ~ 13 currency pairs (say 13 )
2 % average blowout rate if selecting a day and pair at random
1:20 reward risk

if you need any more data i’ll provide it

Not easy to forsee that someone asking about a Martingale-based system is going to be an Actuarial Science major, but we live and learn. For the record, I apologise for not knowing and/or misreading your mathematical awareness level. I have Asperger’s syndrome and am probably [I]particularly[/I] poor at estimating things like that (and other stuff, too) about people, from what they post; sorry.

I struggled to offer it (and stay tactful) here, here, here, here, and here, and in several other threads, too … but you dismissed some of it with observations like “That’s silly”.

I won’t dignify that one with a reply.

Sorry - evidently we don’t really speak the same language, and I think you’ll get more useful help from someone who does. You’re obviously way out of my league. :8:

I wrote a Martingale simulator. The odds are the odds. Using incremental increases on the next position will tune you more quickly to the odds. Not using incremental increases causes a distortion in the gain of the account. You can see the difference in the two pics…


The first pic uses a 10 level 125% increase… for 5000 rounds

The second turns off the increases so your next bet is 1.00 and you can see the wave in the gain of the account, but the odds are still the odds.


Anyone who wants to play with the simulator email me I can send it to you.

I didn’t mean to lash out at you, thank you for the opinion, it is what i asked for, it is just a raw idea and may prove not to have any legs.

My system survived long periods in testing up to 2 years making good profit But I couldnt find a way to get out of the last trade with a profit.

I found this article about the subject:

Statistical Verification of the Labouchere Money Management System - MQL4 Articles

I didn’t have time to read it but maybe you find some answers

Thanks for the feedback, I read through the article and the research was very informative and provides a good format for doing my own more thoroughly. The results he mentioned are largely what I have noticed on my strategy tests, although the Expected Value varies quite substantially depending on currency pair and the number of levels you choose.

USDCHF is the best so far. It has the lowest blowout prob, highest and consistently positive EV with multiple 10k test simulations in excel.

  • 65 day test run
  • 1% profit target per day = 1 successful trade
  • 30% Average strike rate = Ave. 4 trades per day

I can blow out zero, once, twice or three times and still remain profitable at the end of the 65 day period with 65%, 44%, 23% and 2% return respectively (where a blowout = 20% loss). The probability of that happening from the Excel simulation is roughly 95% so far. assuming no computing errors.

Anyway I’m inpatient so started testing it real time in the demo and the results so far is 8% return in 6 active trading days.

The only problem is the inevitable blowout, and managing the risk around that event.

  • How can I identify when it is coming and get out at lower losses
  • What market types are most suitable for the program to run smoothly etc…

I like the idea of using the system because 98% of the time i can comfortably trade each day hassle free and be sure to achieve circa 1% return (the blowout rate is a 20% loss). I would like to see how I could hybridize this to play a more active role in managing the risk when the 2% events occur.

From the anecdotal evidence avoiding high volatility periods including the news release on USD & CHF and ranging markets with a low ATR seem to improve the odds further (higher EV) but I haven’t researched it extensively enough to formalize a trading plan around that.

Why do you test in excel and not on MT4? You can also live trade on a demo.

How is your system performing without the martingale? Does it have an edge? Did you consider to scale in on a winning position like reverse martingale?

Thanks for the post. It has positive EV for USDCHF without a martingale, but mostly negative with other pairs. I used excel to replicate the conditions when I was trying to work out/improve the probabilities.

I haven’t tried a reverse martingale yet no, but I have introduce a trailing stop which disproportionately cut out down my losing positions and increased my overall strike rate to circa 45% (from 30%) the net effect of this on MT4 strategy test was to increase the time to blowout to roughly 2000 trades (13 steps) across all currency pairs.

Brief update.

Three options to improve the EA to achieve +ve on all pairs.

1 - Improve the strike rate to be consistently above the equilibrium value of 28.57%

2 - Improve the probability of wining after having lost in some way

3 - Make the transitions through the levels up and down so I increase and decrease the risk according to the performance of each trade e.g. go from level 5 back down to level 3 before continuing.

Possible Solutions:

1 - (Indicators): Indicators are generally useless when trying to identify entry and exit points on the price action because they simply confirm or re-organise and represent what is happening in the price action.

However, they can add some value in the EA for telling me what is happening in the performance of the EA, information That I would otherwise not have access to. Example, if I place multiple sequential random trades and take the average strike rate in the last 20 trades as equivalent to the current currency price; I would be able to monitor the relative strike rate performance.

With a binary set of -1 (lose) and +1 (wins) trading data from randomly generated trades I can use that information to work out the strike rate over the last 20 trades and feed that information into the formula for a Stochastic Oscillator to give me the equivalent of buy signal (Price Action to Performance) get in/Switch On or sell signal (Price Action to Performance) go short/Switch Off.

Preliminary tests have benn feedback: recording 4000 random trade outcomes on USDCHF as (-1,1), using this approach I have been able to consistently select buy/good periods (average 50% strike rate) and sell/bad periods (average 10% strike rate).

Still more work to be done but i’m sure this will work. I would subsequently be able to run the EA on multiple pairs simultaneously (trade 0.01 lot size and record/no martingale) and cream off the good periods on each to switch on the EA at the normal lotsize and with a martingale.

2 - Reduce TP distance: the martingale currently tries to recover all losses on the previous trades whilst making the equivalent profit of one successful trade at level one. The reason for the circa 28% strike rate is because the RR is configured at 1:2.5, if my RR was 1:1 my strike rate would be roughly 50% and so if I reduce the TP:SL ratio moving up the levels the probability of wining on each level increases marginally. I would have to find a way to gradually reduce the TP effectively which might even mean ultimately losing something at the final level i.e. a 10 level martingale where winning at the last level doesn’t quite recover all my previous losses.

I’m not so sure about this one, but will look at it further.

3 - Taking advantage of marginal victories (Trailing stop): the first version of the EA provided a binary win lose outcome. Among the losing trades however there were many occasions when the trade went substantially into profit before reversing to close me out at a loss.

I repeated the trades above but also decided to record the highest +ve PnL on each one to see if a trailing stop would give me any advantages. The results were quite favorable and I noticed that i introducing a trailing stop would disproportionately reduce my losing trades more than my winning ones.

I tried a simple event @ when PnL = Risk i.e RR 1:1 bring the stop loss to breakeven and this improved the EA massively. The strike rate Increased to 48% on each run in the strategy tester (which makes sense since small profits around breakeven count as wins) and increased the time to blowout massively, making GBPUSD & USDJPY & AUDUSD now more consistently profitable over the 6 month period.

What I would like to do is take it further and start trailing from breakeven as a trade moves further into profit. Locking in more profit in this way will have the effect of reducing the accumulated loss at that level (step) so that I can reduce the risk on the next trade to recover the marginally reduced accumulated loss at that level. This has worked anecdotally on the live demo test and I have seen the martingale jump down from level 7 to level 5 due to the marginal profits made on a previous trade.

So believe taking advantage of the marginal favorable moves could help deescalate my risk on the martingale and the prob of hitting the maximum level.