Variance of the time of gambler's ruin The problem is as follows:

Let $\xi_1,\xi_2,\ldots$ be independent with $P(\xi_i = 1) = p$ and $P(\xi_i = −1) = q = 1−p$ where $p < \frac{1}{2}$. Let $S_n = S_0 +\xi_1 +\ldots+\xi_n$.  Let $V_0 = \min\left({n \le 0 : S_n = 0 }\right)$

(a) Show that $(S_n−(p−q)n)^2−n(1−(p−q)^2)$ is a martingale. 
(b) Use this to conclude that when $S_0 = x$ the variance of $V_0$ is
$x\cdot\frac{(1−(p−q)^2)}{(p−q)^3}$
I managed to show the expression in part a is a martingale. However, I'm not quite sure how to make the jump to finding the variance of the stopping time.
 A: To simplify notation, let $r \equiv p- q$. First let us compute $\mathbb{E}[V]$. You might have already proved that $S'=S_n - nr$ is also a martingale.  Note that so is $S''$ which is $S'$ stopped at the barrier 0.  So, $$\mathbb{E}[S'']=x=\mathbb{E}[0-Vr]$$ from which we get $\mathbb{E}[V]=x/r$. 
Now consider the martingale M that you showed in part a. Let M' be M stopped at the same time V. Since M' is also a martingale, we get $$\mathbb{E}[M']=0$$ or
$$\mathbb{E}[(0-r V)^2]=\mathbb{E}[V] (1-r^2)$$ which gives 
$$\mathbb{E}[V^2]=\mathbb{E}[V]\frac{1-r^2}{r^2}=x \frac{1-r^2}{r^3}$$ which is the expression you have. 
However, I'm puzzled with your expression because variance is actually $$\mathbb{E}[V^2]-\mathbb{E}[V]^2$$ which is $$x \frac{1-r^2}{r^3} - \frac{x^2}{r^2}$$
A: Here's how I managed to prove it:
We can being by showing that the equation in part (a) is a martingale just by writing the definition of a martingale and doing the algebraic expansion. The calculations are a bit tedious, but lead us to the result without any issues. 
Then, we can apply the optional stopping theorem to the martingale is part (a) (As suggested by angryavian) and we get the following result:
$E[(S_{V_0}−((p−q)V_0)^2]−E[V_0](1−(p−q)^2)= x^2 $
$(p−q)^2E[V^2_0]−E[V_0](1−(p−q)^2) = x^2$
From here, we can isolate $E[V_0^2]$ in terms of $E[V_0], (p-q) \space and \space x^2$
Now, to get the $E[V_0]$, we can use wald's equation given by $E[ S_n - S_0] = \mu E[V_0]. \space $ Let $S_0 = x$, then $E[V_0] = \frac x{q-p}$
Using this, we can find $E[V_0^2]$ and then use that to find $Var[V_0] = \frac {x⋅(1−(p−q)^2)}{(p−q)^3} $ by using $Var[V_0] = E[V_0^2] - E[V_0]^2$. 
