Need Code for 20 TMA

i need code for this simple strategy:-

Buy:-Only when a candle open above 20 TMA
Sell:-Only when a candle open below 20 TMA

Buy exit:- When the prices goes below the low of previous candle or price open below the 20 TMA
Sell Exit:-When the prices goes above the High of previous candle or price open above the 20 TMA

It should only take one position at a time.

For the above given condition

Buy Script:

OPEN > TMA(CLOSE, 20)

Sell Script:

OPEN < TMA(CLOSE, 20)

buy and sell exit also you have mentioned same condition. so you can use the same