Hi,
why did not use NumOpenLong/Short and simplify the code?
I do not like that loop and I think you forgot to init the total to 0.
Why did you use a var counter and not a int one?

my 2 cents