You're right in avoiding simutaneous long and short positions of the same asset. But you need no special code for that, simply set Hedge = 5.