I think the answer is technically yes, the loss can be used to offset other gains no matter how soon you buy back in, as that's a completely new and unrelated trade.
However, I was warned when considering other similar arrangements that if it was done often enough, with the obvious goal of reducing tax, then Part IVa (the anti-avoidance provisions) may be able to be used. It might be deemed that there's no commercial reason for it, the only benefit being tax avoidance, and so you could potentially have problems.
You should check with your accountant how much of a risk that might really be for you, which may depend on how often you do it.
Cheers,
GP