Your updated code has still a bug: It exits only when the signals match, but it enters trades on every bar with these lines:

if(!NumOpenLong) enterLong();
...
if(!NumOpenShort) enterShort();

I believe you've forgotten the { } brackets.