Help me with tradescript

I have a strategy in nifty.
I will use 30 min chart. I will use 3 Rd candle as reference.
After 3 Rd candle is complete. I will take high and low of 3rd candle as reference. If nifty moves above that high I will go long. If it breaches the low, I will go short. Can I backtest the strategy in PI. If so, what would be the coding ?

Newbie here, but this might help.

  • BUY

    TREND(CLOSE, 3) = DOWN AND CLOSE > REF(HIGH, 1)

  • SELL

    TREND(CLOSE, 3) = DOWN AND CLOSE < REF(LOW, 1)