I think your problem is your actually checking 2 bars back, use priceOpen(0), priceClose(0) etc etc....to check the last candle.