Hmm, I admit that even I am lost about the purpose and working of that code. I can only say that it looks very dangerous.
The normal way to reverse a short position with 2 orders:
exitShort();
enterLong();
The unconventional way with 1 order, open position is ThisTrade:
enterLong(Lots+TradeLots);
cancelTrade(ThisTrade);