Entering a BTO while still in a STO trade on the same contract

My system sells trades after a 30 minute hold. During that time it is possible for the system to generate an exact opposite trade. For example…

9:30 am STO - 1 contract of /ES (with parked order to BTC in 30 minutes)


9:50 am BTO - 1 contract of /ES

A similar situation just occurred and the result was being totally closed out of /ES. No huge deal. I understand how that causes overlap and it’s cleanest to just have them cancel each other out. However, if there’s a solution, that’s cool too.

I asked the same question and Mr. Klein said two things: 1) mathematically canceling each other out has the exact same effect in terms of profit/losses, apparently it is called offsetting. 2) more importantly I don’t think exchanges permit a holding of both short and long of the same contract.