Hello, fellow quants!

How would one go about reversing a trade when liquidating it. Let's use RSI as an example because it's easy to visualize. 

When RSI is over-sold, one would typically go long, and then sell that position when the RSI is over-bought. How would I go about structuring my code if I want to use the same indicator to also go short at the same price as I sell my long position (effectively making my exposure 100%).