Buy & Sell Alert in Pi Terminal

I want to create 1 strategy, can u please help me to create code for that & share in our pi terminal for Backtesting

Buy - When 5EMA Cross 12EMA in upward direction and RSI is above 50
Buy Exit- when 5EMA Cross 12 EMA in downward direction or RSI is below 50

Sell - When 5EMA Cross 12 EMA in downward direction and RSI below 50
Sell Exit - When when 5EMA Cross 12EMA in upward direction or RSI is above 50
 

Could you please help me for the same

Your early response highly appreciated.

As Per your given condition

Buy Script:

CROSSOVER(EMA(CLOSE,5),EMA(CLOSE,12)) AND RSI(CLOSE,14)>50

Buy Exit:

CROSSOVER(EMA(CLOSE,12),EMA(CLOSE,5)) OR RSI(CLOSE,14)<50

Sell Script:

CROSSOVER(EMA(CLOSE,12),EMA(CLOSE,5)) AND RSI(CLOSE,14)<50

Sell Script:

CROSSOVER(EMA(CLOSE,5),EMA(CLOSE,12)) OR RSI(CLOSE,14)>50