Indicator : crossing (bar & previous bar) (URGENT)

 

Hi there,

Need help with a simple crossing code in an indicator : 

 if ((close[bar - 1] < Pivot[0]) && (close[bar] > Pivot[0])) { BuyBuffer[bar]=low[bar]-Range*SignalShift; }
 if ((close[bar - 1] > Pivot[0]) && (close[bar] < Pivot[0])) { SellBuffer[bar]=high[bar]+Range*SignalShift; }

Error (not during compilation, but when attached to chart) :

array out of range in (363,12)
 

Array out of range points to column 12 so I guess content of bar = 0 and bar - 1 = -1 but -1 is not a valid index. 

 
Maybe the formula should be "close[bar+1]" depending on the rest of your program logic?
 
MrGrey:
Maybe the formula should be "close[bar+1]" depending on the rest of your program logic?
Here it is :p