Code for setting 3EMA indicators

hi,
I want to backtest 3EMA(3,15 & 51) indicators to generate buy or sell signals.The strategy should be this:
1.For buying – 3EMA crosses 15 & 51
2.For selling – 3EMA crosses 15 & 51 on downside.

Please help me with the code of this strategy so that I can backtest it.
Thanks