Breakout Script for Backtest

How do I write a Tradescript for Backtest for Buy order:

Close > Resistance (that is, the maximum of x candles before, if the current price is within 5 average candle lengths from resistance)

As per the above query the resistance can not be coded with tradescript, provide the condition based on Open high low close