You are making it a bit more difficult than it is I think.
NumOpenTotal is per asset/algo, so you don't need to check what algo is currently in use.

From the manual

Code:
Limit the number of open positions
// max. 3 open long positions per asset/algo
if(my_long_condition == true) {
  exitShort(); // no hedging - close all short positions
  if(NumOpenLong < 3) enterlong();
}



Or just use reverseLong/reverseShort so e.g. instead of enterLong()
use reverseLong(x) where x is the maximum number if open positions allowed.