The reason your first if statement was ignored was because you had placed a ";" at the end thus disconnecting the logic that you had between the "{ }".
I modified the indicator you provided. When i debug something I like to have things I can see so I enabled the plot output so that i could see on the chart when the values went to +1 or -1 or zero. I put the plot in another panel. I added dots to show on the price panel where the crossovers occurred meeting the conditions I believe you wanted.
I also commented in the indicator to help in understanding.
Hope this helps.
Comment