Isn't the Martingale betting system completely rational? https://en.wikipedia.org/wiki/Martingale_(betting_system) I don't think it's based on gambler's fallacy.
Suppose I have $1+2+4+8+.....+2^{9}=1023$ Dollars.
I'm about to bet on heads in the tosses of a fair coin. If the coin lands heads, I receive an amount double my bet (my original bet + profit equal to my original bet) My strategy will be:
1.Bet 1 Dollar on the first toss.
2.Double my bet on each successive toss.
3.Walk away on my first win.
So, all the possible outcomes are:
$$H, TH, TTH, TTTH, TTTTH, TTTTTH, TTTTTTH, TTTTTTTH, TTTTTTTTH, TTTTTTTTTH, TTTTTTTTTT$$
I end up making a 1 dollar profit in the first 10 of these outcomes. Only in the last case I lose 1023 dollars. But it would take a miracle for $TTTTTTTTTT$ to happen with a fair coin. I know that the expected value is negative but the expected value comes into play only when I keep on betting till the end of time. My strategy is to walk away on the first win.
So, before I begin to bet, isn't it reasonable for me to believe that I'll most likely make a profit?
 A: As you say, this strategy does have a high probability of yielding a very small profit. But with small positive probability, you lose everything! That's why in the 'long run,' you can't make money off of this strategy (or any strategy based off betting on a coin flip, as you rightly say). If you have $2^N$ dollars, then you make $1$ dollar if you win within the first $N$ turns, and you lose it all if you don't win by the $N$th try. So your expected return is given by
$-2^{-N} 2^N + \sum_{n=1}^N 2^{-i} = 0.$
Note that your bet has variance
$2^{-N}2^{2N} + \sum_{n=1}^N 2^{-i} \approx 2^N+1$, 
which is very large! This is part of the reason casinos have table limits: it puts a cap on how far someone can take this strategy, i.e. how high the variance of a single bet can be. 
See the St. Petersburg paradox, which has a similar flavor. 
A: Let's just compute the expected value of your supposed betting system:
With probability $\frac{1}{2}$ you will win $1$ Dollar on the first toss, if you lose the first one there is again a $\frac{1}{2}$ chance of you winning $1$ Dollar on the second toss (so overall a $\frac{1}{4}$ chance of you winning a dollar exactly at the second toss). Generally there is a $\frac{1}{2^n}$ chance that you will win $1$ Dollar at the $n$-th toss (up to and including the $10$=th toss) and finally a $\frac{1}{2^{10}}$ chance that you will loose $1023 = 2^{10}-1$ Dollars on the $10$-th toss.
So on average you win or lose nothing. The problem being, the best you will ever do is win a single dollar while in the worst case you lose $1023$ Dollars.
Summing these up your expected value is
$\left(\sum_{i=1}^{10} \frac{1}{2^i} \right) - \frac{1}{2^{10}}(2^{10} -1) = 0$
A: The probability of losing is equivalent to getting $10$ tails in a row, which is $2^{-10}$. Should you lose, you lose all $1023$ dollars. The probability of winning is $1$ minus the probability of losing, i.e. $1-2^{-10}$. But if you win, you only win $1$ dollar. Thus the expectation is a net change of 
$$
(1-2^{-10})-1023\cdot2^{-10}=0
$$ 
so you would expect to gain nothing, and to only lose a lot of time. The idea is that when you win, you only win a very small amount. But when you lose, you lose a huge amount! The two effects cancel out in the end to give a zero expectation.
