How to Exit sequentially?

I have 2 sets
Set1: option buying at 09:16 (both CE & PE far OTM)
Set2: option selling at 09:17 (both CE & PE OTM)
Set 2 Exit at 03:10

Due to margin requirements, I have designed as above and designed exits as below.

Universal Exit at 03:11 which actually squares off set 1. Set 2 exit is mentioned in set itself.

Above are working well.

However, when I try to implement PNL at strategy level, it causes problem in exiting due to margin requirement.

I have to exit sequentially. i.e.

  1. exit set2 first i.e. buy sold CE & PE
  2. exit set1 next i.e. sell bought CE & PE

If above both happens simultaneously, strategy may enter “Error” state (due to margin requirements).

Is there any way to achieve above PNL based exit in sequential order?

Thanks in advance.