First prove that the underlying process is a martingale and that the proposed random time is a stopping time for the same filtration. Then identify a sufficient condition for the version of optional stopping you are using. Bounded stopping times are the simplest case. For an unbounded stopping time, stopping first at and justifying a limit by bounded domination or uniform integrability is a common proof.
Stop at a finite time first, then justify the limit
In discrete time, check for every . For the bounded time , write
The indicator is measurable at because its complement is . Each summand has expectation zero by conditioning on . Hence . If almost surely, the left-hand random variable converges almost surely to . To pass the equality to the limit, verify an integrable bound that holds for all , or another applicable condition that ensures convergence in expectation. Almost sure finiteness of alone establishes only the pathwise convergence.
In the sum, the event is already decided at . It says that the process has not stopped by the previous observation. That predictability lets you take it outside the conditional expectation of the next martingale increment. For an unbounded stopping time, the bounded identity holds for every separately. The missing argument is whether expectations converge as tends to . Identify a sufficient condition, such as uniform integrability, or exhibit an integrable bound in the particular problem before taking that limit.
Why the two-barrier walk works and a single barrier can fail
A symmetric random walk starts at and moves up or down by one with equal probability. What is the probability of reaching 5 before 0? Set . The walk is a martingale in its natural filtration and the first hit is a stopping time. Any block of five successive upward steps forces an exit if the walk is still inside the interval. Independent blocks each have probability of being all upward, so the walk exits almost surely. Also, for every . Dominated convergence now gives . Since equals either 0 or 5,
Contrast this with the same walk started at zero and stopped only on its first hit of . In a symmetric walk, that hit occurs almost surely. For example, the probability of hitting before is , which approaches one. The stopped payoff at the first hit of is always one, while the initial value is zero. The bounded domination used for the two-sided walk no longer applies.
For the two-barrier case, always lies between zero and five. You can use the constant five as an integrable bound. The walk exits almost surely because from any interior state there is a uniformly positive chance of reaching a boundary within the next five steps, and repeated blocks make the chance of never exiting vanish. Now the bounded-time expectations pass to the limit. With only an upper barrier the stopped walk can make arbitrarily large negative excursions before hitting. The same bound is no longer available, even though the one-step martingale equation still holds.