The problem you stated is an example of a random walk with one barrier problem. You can find a discussion in any standard probability text. For example Feller (Vol I) is a very good, although old test.
I'm sorry but I don't see the solution, It would be easy if I have to stimate the probability after n flip but I have to calculate it dinamically trough the n flips.
I thougt to make tehe product from 40 to n-40 of (1-Bin(0.5)) but i don't know if is right.
With 1000 flip --> p=1-0.126 to see a difference of 40 during the test