Help me to write strategy for zerodhaPi candle chart of 15,20, 30, 60 min chart

  1. BUY AT-

WHEN LAST PRICE - X > HIGH PRICE OF EARLIER CANDLE AND WHERE OPEN +Y => CLOSE.

  1. SELL AT-

WHEN LAST PRICE - X < LOW PRICE OF EARLIER CANDLE AND WHERE CLOSE = >OPEN +Y

(X, AND Y ARE CONSTANT FIGURE FOR DIFFERENT CASE OF TIME FRAME AND SCRIPT.)

As per the above condition lets say X=2 and Y=3  as a placeholder for example

Buy Script:

LAST-2 > REF(HIGH,1) AND OPEN+3 >= CLOSE

Sell Script:

LAST-2 < REF(LOW,1) AND OPEN+3 <= CLOSE