Counting directional change macro

Hi all,
I’ve written a macro that segments a movie of a fish larva in a dish and have used MorpholibJ’s Geodesic Diameter to find the coordinates of the upper and lower extremities of the fish.
So far so good but I then try to count how many times the lower extremity changes direction and my macro fails.

This is where I think the problem is but I can’t work out what I’m doing wrong:
I have defined “Difference1X” as the difference in coordinates in X for point1 between timeframes and “OldDifference1X” is the difference in the previous timeframe. If one of the difference is positive and one is negative (indicating a change in direction), I label the change in direction as “Beat1X=1” and add one to the beat counter.

if(Difference1X>0 && OldDifference1X<0){
	Beat1X=1;
	BeatCounter1X=BeatCounter1X+1;
	}
else{
	Beat1X=0;
	}		
if(Difference1X<0 && OldDifference1X>0){
	Beat1X=1;
	BeatCounter1X=BeatCounter1X+1;
	}
else{
	Beat1X=0;
	}

Can you help?

@MatthieuV

Without seeing more of your macro - it’s a bit hard to tell what is going ‘wrong’… if I were you - I’d use print() statements to see if what you are wanting to occur is or not… might reveal where the issue is located.