Va quasi come hai fatto, però devi anche prevedere che operi quando vale ZERO, cioè vai LONG se è 0 oppure 1, vai SHORT se è 0 oppure 2. Perché quando è ZERO devi potere operare regolarmente, quindi la riga 58 dovrà essere:
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok