Expectation of HTH (fair coin tosses) There is a sequence of fair coin tosses with Head (H) and Tail (T). I have the stopping time $S=\text{{the first time we get HTH}}$. I want to calculate the $E[S]$, which is $10$. I have to use the optional stopping theorem, but I do not know, how to calculate this. Can somebody help me? I found a solution by combinatoric and by Marcov Chain, but I need one by Optional Stopping..
 A: Imagine a casino with a game where people can bet on the outcome of a coin flip. However, once there are three games in a row with the outcomes $HTH$, the casino must shut down. 
Furthermore, suppose there are infinitely many very predictable gamblers. The $n^{th}$ gambler will sit down at the table for the $n^{th}$ flip. 


*

*Initially, they bet \$$1$ that the result is $H$. If they lose, they leave the table.

*If they won the last bet, then for the next bet, they bet \$$2$ that the result is $T$. If they lose, they leave the table.

*If they won the last bet, then for the next bet, they bet \$$4$ that the result is $H$. If they lose, they leave the table. If they win, the casino shuts down.


Note that if the sequence $HTH$ occurs when a gambler arrives, then they leave the table with \$$7$. Otherwise, they leave the table having lost \$$1$.  
Now, let $X_n$ be the total winnings of all the gamblers after $n$ flips. It is clear that $X_n$ is a martingale since these are all fair bets. Let $\tau$ be the first time that $HTH$ appears. By the optional stopping theorem,
$$
\mathbb E[X_\tau] = \mathbb E[X_0] = 0
$$
On the other hand, we can calculate $X_\tau$ exactly. Given that there were $\tau$ flips, the first $\tau-3$ gamblers which entered the casino will all have lost exactly \$1. The third to last gambler wins \$$7$, the second to last gambler loses \$$1$, and the last gambler wins \$$1$. Therefore,
$$
X_\tau = -(\tau-3) + 7 - 1 + 1 = -\tau +10
$$
Combinting the last two equations, you get
$$
0=E[X_\tau]=E[10-\tau]\implies E[\tau]=10.
$$
