How do I block new orders to be sent until the price hits a moving average?


I'm developing a new robot and I'm having trouble to figure this out..
Lets say my robot opened a new order and it hit my SL.
How could I temporarily block new orders to be triggered until the price hits a moving average?

Examples would be great if possible.

First figure out in OnTrade() if a SL happend.

Set a flag to true.

Have a function to check for MA being crossed by price.

Reset the flag.

Check the flag before sending an order.