Hi
The program has bet count variables, matched, ummatched, back, lay etc.
why not use in the betting trigger:
and selections trigger expression allbets_bm_num-allbets_lm_num is equal or less than 5
in answer your original question I thought you wanted no more than 5 bets per market, but I can see from your trigger it is only one back and one lay.
If you still want to use a counter, I think you need to set it to zero one time only and then update it globally, but the above is much more efficient.