Calculating the probability to win with martingale in roulette

I've made a python program that uses martingale betting method to see what the probability is to double your starting pot and then stop at European roulette (no double 00). The program works like this, You got $100$ dollars in the beginning and the starting bet is $1$ dollar. The program always bet on red and if it wins it will bet $1$ dollar again. If it loses it will double the initial bet. $1,2,4,8$ etc until it either goes bankrupt or wins. I've made the program do this a million times and then divide the times it doubled it's money by a million and i got $0.304063$.

My question is how would I calculate this value without having to use the program?

The probability of getting red is $\frac{18}{37}$. You play until you have either won $100$ dollars or lost everything.

• So you stop playing at the first time you win? What exactly do you want to calculate? Have you checked the St Petersburg paradox? – user190080 Aug 24 '15 at 11:11
• @user190080 No it stops playing when it has doubled it's starting money, I want to calculate what the probability that the player will double it's money is. Which according to the program is 30,4%. Thank you I will check it out. – Thobias Ivarsson Aug 24 '15 at 11:20
• ah okay...so you play as long as you either gained 100 (in sum 200) or you lost your initial capital, maybe you should add this to your question. Also the probabilities of winning a round, I guess $\mathbf{P}$(red) $=$ $\mathbf{P}$(black)$=$ $\frac 1 2$? – user190080 Aug 24 '15 at 11:28
• @user190080 I've updated the question, and the probability of getting red is (18/37). So how would I get the same percentage by calculating it with math? – Thobias Ivarsson Aug 24 '15 at 11:38
• another thing: what happens if you can't double anymore, e.g. you lose in a row and therefore bet $1,2,4,\dots,128$ but the next doubling doesn't work... – user190080 Aug 24 '15 at 11:57

If you have from $100$ to $126$ dollars you can bet up to $6$ times in your martingale system, while if you have from $127$ to $199$ dollars you can bet up to $7$ times, since $1+2+2^2+\cdots+2^6=2^7-1=127$.
The probability of not losing $n$ times in a row is $1-\left(1-\dfrac{18}{37}\right)^n$. So the probability of progressing from $100$ dollars to $200$ dollars is $$\left(1-\left(1-\dfrac{18}{37}\right)^6\right)^{27} \left(1-\left(1-\dfrac{18}{37}\right)^7\right)^{73} \approx 0.3041318$$ which is what your Python program predicted.
Note that if your system fails, you will usually still end up with a positive amount (unless you lose seven times in a row starting with $127$ dollars): for example if you start at $100$ dollars and immediately lose six times you will end up with $37$ dollars when your system requires you to bet $64$ so you have to give up. If your system fails then your expected final amount is about $41.468$ dollars. So, after taking account of the possibility of reaching $200$ dollars, your expected overall finishing amount is about $89.683$ dollars.