Switch-case statement issue...
Because your indicator is build in the wrong direction (from present to past) :
for(i=0; i<limit; i++)
...directly from -1 to -4, or 1 to 4, without first going to -3 or 3 as would be expected from the state machine. It also goes from 0 to -3 or 0 to 3, without first going to -4 or 4 as would be expected from the state machine.
It doesn't go from -1 to -4 ... but from -4 to -1, from 4 to 1, from -3 to 0 and from 3 to 0. Which is what you coded.
I'm writing an indicator with a switch-case statement and it's behaving in a way that I can't understand. I'm wondering if someone might have some insight? This switch-case runs a state machine. Once in the upwardTrend or downwardTrend state, it should only be able to go back to the noTrend state if the dirMult variable is a certain value (3 or -3). However, if you look at the indicator window below, you can see that the value of dirMult (the red histogram) skips directly from -1 to -4, or 1 to 4, without first going to -3 or 3 as would be expected from the state machine. It also goes from 0 to -3 or 0 to 3, without first going to -4 or 4 as would be expected from the state machine. I am completely stumped as to how this is happening.