The easiest way to program a multi step criteria entry/exit signal is to use a Finite State Machine (FSM). This is much easier than setting flags and then having to turn them on and off. Here is a diagram of a FSM: A Simple FSM Diagram
Backtesting with [Trade Station,Python,AmiBroker, Excel]. Intended for informational and educational purposes only!