Coding for below stratagy

Kindly provide the code for the below strategy in 1 minute chart.

If the price crosses  and close above from below of  5 SMA,  and buy after  high of  3rd highest candle after crossing 5 sma

If the price crosses and  close below from above  of 5 SMA,   and sell after  low of  3rd Lowest candle  after crossing 5 sma.

Thanks.

As per the above condition

Buy Script:

CROSSOVER(CLOSE,SMA(CLOSE,5)) AND HIGH > REF(HIGH,1) > REF(HIGH,2)

Sell Script:

CROSSOVER(SMA(CLOSE,5),CLOSE) AND LOW < REF(LOW,1) < REF(LOW,2)

The Code provided by AlgoGeek has error.

Please try below given codes

Buy :

CROSSOVER(CLOSE,SMA(CLOSE,5)) AND HIGH > REF(HIGH,1) AND HIGH> REF(HIGH,2)

Sell :

CROSSOVER(SMA(CLOSE,5),CLOSE) AND LOW < REF(LOW,1) AND LOW< REF(LOW,2)

Thanks

Hi AlgoGeek,
This script is showing an error while back testing; and not generating any buy or sell signals.
some thing is missing?
Thanks

please try to backtest with more historical data., alerts come only if pattern matchs… above is as per your condition

It works. No errors.