I'm studying the pricing of a Double-Barrier binary option on the price of $S$. By this I mean an option that pays $X$ at maturity $T$ if the lower ($H1$) or upper barriers ($H2$) are not hit during the lifetime of the option.
I was told that the valuation could be done by subtracting an up-and-in-cash(at expiry)-or-nothing struck at $H2$ from a down-and-out cash or nothing struck at $H1$. That is:
\begin{align*} KO_{H1}- KI_{H2} = &\ (X\ \ \text{if}\ \ \forall\ \ t \le T: S_{t}>H1) - (X\ \ \text{if}\ \ \exists\ \ t \le T: S_{t}>H2) \end{align*}
This valuation kind of makes sense to me because we are considering all the paths that are above $H1$ and subtracting the paths that got above $H2$ which would only leave us the paths between the lower and upper barrier.
However I am doubtful about it since I can't find this way of doing it in any place. Is there a mistake in it?
I've seen a formula for this which involves some infinite series and $sin(x)$ functions, but it seems way too different to my approach.
Much help appreciated