Can you make money on coin tosses when the odds are against you? The strategy
Given an initial investment $n$ dollars and a "bet buffer" $b$.


*

*Calculate the bet size $x=\left\lfloor\frac{n}{2^b-1}\right\rfloor$ dollars.

*Wager $x$ dollars on random variable $C$ that $C=1$ with $P\left\{C=0\right\}=p>.5$ and $P\left\{C=1\right\}=1-p<.5$ and payout x$2$.

*If the bet is won, update $n:=n+x$ and go to step 1.

*If the bet is lost, update $n:=n-x$, $x:=2x$, and go to step 2 (martingale).


An example
I start with an initial investment of $n=2044$ and bet buffer of $b=10$. I calculate my bet size to be $x=1$.  I win.  Now $n=2045$ and $x=1$.  I lose.  Now $n=2044$ and $x=2$.  I lose.  Now $n=2042$ and $x=4$.  I win.  Now $n=2046$ and the "base" bet size has increased to $x=2$.  Assume I reach $n=3069$, this allows my base bet size to increase to $x=3$.
My questions
Let $B$ be the number of bets needed to double an initial investment $n$ given $b$ and $p$.  What is $E\left[B\right]$?
Let $X_i$ be the net-gain or loss after the $i$th bet.  What is $E\left[X_i\right]$?  As $i\rightarrow\infty$?
How do things change if the bet size can be continuous?
What other interesting metrics can be computed from this information?  Interesting conclusions drawn?
Meta-question
How does one go about "encoding" the variability of the bet size?  The way that it's updated after each bet, depending on the previous bet?
Thanks.
 A: Let us formulate your problem mathematically. Let $X_n$ be the outcome of each coin toss. 
$P(X_n = 1) = 1- p$ and $P(X_n = -1) = p$ 
Let $H_{n}$ be your bet size on $n$-th toss and this depends on outcomes of previous coin tosses $X_1,... X_n$. Let $S_n = \sum_{i=1}^n X_n$
Then your final wealth is $W_n = W_0+\sum_{i=1}^n H_n X_n = W_0 + \sum_{i=1}^n H_n (S_n-S_{n-1})$
Here $W_0$ is your initial wealth. $H_n$ is each one of your bet. $S_n-S_{n-1}=X_n$, so when this is 1, you win $H_n$ and when this is -1, you lose $H_n$.
I now state this 
Fact one : $S_n$ is a supermartingale. The mean of this is decreasing. 
Fact two : $W_n$ is a supermartingale for ANY choice of $H_n\geq 0$ if $H_n$ depends on $S_0,...S_{n-1}, X_1,... X_{n-1}, W_0,...W_{n-1}$ - your strategy satisfies this. Basically you have to bet before you see the result of the toss
you restricted your strategy such that $W_n$ can only stay positive.
Fact three: A positive supermartingale ALWAYS converges. (i.e. $P(W_n\text{converges})=1$)
In this case, there is no escape, it cannot converge anything rather than 0. Now you might say: fine, I allow $W_n$ to be negative - I can borrow money to fuel my gambling debt.
What if I stop when once I double my wealth?
FACT: if the odds is against you, the best bet is to put all your money on the first throw. This is because when it is against you, you 'lose expectation' for every bet you make, the more often you do this, the more your expectation diminishes. It might be the case you NEVER double your wealth. If the coin toss is fair, the chance you will double your wealth before you go bust is exactly $1/2$ (unsurprisingly)
YOU ARE NEVER GUARANTEED TO MAKE MONEY USING ANY STRATEGY WHEN ODDS IS AGAINST YOU.
I am sure you know this strategy:
bet on head, if you win stop, if you lose double your bet. For this strategy, eventually, you will win, so what is the catch?
The answer is that you might be down by an arbitrarily large amount before you make your 1 dollar. You may be down 1023 bucks if it went tails 9 times consecutively or maybe $2^{100}-1$ if it went tails first 99 times consecutively.
MORAL: YOU CAN GUARANTEE TO MAKE MONEY ONLY WHEN YOUR POCKET IS INFINITELY DEEP
In fact, this is very closely related to fundamental theorem of asset pricing in continuous time, which says
THERE IS NO FREE LUNCH WITH VANISHING RISK
note also that this remains true when $p=1/2$. In this case you get a martingale, but a martingale is a supermartingale, so all the results here hold.
to answer your specific questions:
$E[B]=\infty$ because there is a chance you will never double your initial investment
The net loss converges to negative of your starting value.
Making it continuous does nothing. Note for my set up, I allowed a much bigger set of allowed betting strategies than the one you used. They will always result in a loss unless you have an infinitely deep pocket.
to answer your meta-question:
discrete time martingale theory is how you encode variability of the bet size. Note $H_n$ can depend on all information up to time $n-1$. In probability theory language, $H_n$ is predictable/previsible.
