We introduce a continuous time model for stock prices in a general factor representation with the noise driven by a geometric Brownian motion process. We derive the theoretical hitting probability distribution for the long-until-barrier strategies and the conditions for statistical arbitrage. We optimize our statistical arbitrage strategies with respect to the expected discounted returns and the Sharpe ratio. Bootstrapping results show that the theoretical hitting probability distribution is a realistic representation of the empirical hitting probabilities. We test the empirical performance of the long-until-barrier strategies using US equities and demonstrate that our trading rules can generate statistical arbitrage profits.