Snoopy,
that I think that your code should get these conditions added to it, in order to enter a trade only if the previous pub CROSSED the BB mainline. I am not a coder, but I think you can see...