Macd, closing price and ema

hello sir

for buy : up above last 3 days close and macd must above 0 (9,12,26), and ema above 50, up above previous days high

for sell : down below last 3 days close and macd must down 0 (9,12,26), and ema below 50, down below previous days low

time frame intraday day 5 min
please suggest me code for PI

Do this on EOD chart. In pi you can do on 6Hour/ 8 Hour chart.  Please specify which EMA you want so that same can be included-

Buy-
LAST>REF(CLOSE,1) AND REF(CLOSE,1)>REF(CLOSE,2) AND REF(CLOSE,2)>REF(CLOSE,3) AND MACD(12,25,9,SIMPLE)>0 AND LAST>REF(HIGH,1)

Sell-
LAST<REF(CLOSE,1) AND REF(CLOSE,1)<REF(CLOSE,2) AND REF(CLOSE,2)<REF(CLOSE,3) AND MACD(12,25,9,SIMPLE)<0 AND LAST<REF(LOW,1)