Choose Next expiry based on condition

I would like to use Next weekly expiry on Wednesday and Thursdays. How to use this.

Condition 1: For Wednesday & Thursday for a future signal choose Next week Expiry ATM

Condition 2: Already position created on current expiry and on Wednesday after 2:00PM switch position to next week expiry.