Can you help me here?

This a simple study that counts how many bars, in this case, MACD, fills above and below zero line.

The problem is that the counter starts always at 1 and never at zero. I can't understand why. I'm starting the count at zero everytime the bars crosses zero line.

Another strange reaction is although I'm requesting to count the up bars, above zero, it actually counts the down bars, below zero.

Code: Select all

`inputs:`

fastLength (14),

slowLength (6);

variables:

counterUpBars (0),

counterDownBars (0),

upCount (false),

downCount (false),

myMACD (0);

myMACD = MACD(close, fastLength, slowLength);

if myMACD > 0 then begin

upCount = true;

counterUpBars = 0;

end

else begin

downCount = true;

counterDownBars = 0;

end;

if upCount then

counterUpBars = counterUpBars + 1;

if downCount then

counterDownBars = counterDownBars + 1;

plot1(counterUpBars);

//plot2(counterDownBars);

As usual, I'm missing something.

Regards,

Fernando