PIVOT crossing alert and expert advisor code

Hi everyone, Happy independence day.

I am working on one script which will generate below alerts.

BUY - When candle’s open is below black pivot line and when same candle’s LTP goes above the same black pivot line.

The code which I am trying is as below.

SET PVT = (( REF(HIGH,1) + REF(LOW,1) +REF(CLOSE,1) ) / 3.0)
LAST > PVT AND OPEN < PVT

Question - When I backtest this code also shows some wrong entries. I am not able to find out what is wrong. is the formula for pivot is wrong? It’s showing alerts which are far below the black pivot point as well.