Coding for EMA at crossovers with IF condition

Pls code for below strategy:

BUY:   at  Crossover 13/50 ema OR Crossover 13/34 only IF 13 & 34 emas are above 50 ema.

SELL:  at Crossover 50/13 ema OR  Crossover 34/13 only IF 13 & 34 emas are below 50 ema.

If you are looking for a AFL below is the code

_SECTION_BEGIN("EMA CrossOver with IF");

Title = "{{NAME}} {{DATE}} {{INTERVAL}} " + _DEFAULT_NAME() + " Chart values : {{VALUES}}";


//EMA of 13-period
ema13 = EMA(Close,13);

//EMA of 34-period
ema34 = EMA(Close,34);

//EMA of 50-period
ema50 = EMA(Close,50);


//Get previous closed values to avoid false Buy/Sell triggers
x = Ref(ema13,-1);
y = Ref(ema34, -1);
z = Ref(ema50, -1);

Plot(ema13,"",colorBrightGreen, styleLine, styleThick);
Plot(ema34,"",colorBlue, styleLine, styleThick,0, 0);
Plot(ema50,"",colorRed, styleLine, styleThick,0, 0);

//BUY:   at  Crossover 13/50 ema OR Crossover 13/34 only IF 13 & 34 emas are above 50 ema.
a = (x > z) AND ( y > z);
for( i = 0; i < BarCount; i++ )
{
if( a[i] == 1){
Buy = Cross(x,z) OR Cross(x,y);
PlotShapes(shapeUpArrow*Buy,colorGreen, 0, L, Offset=-45);
}
}

//SELL:  at Crossover 50/13 ema OR  Crossover 34/13 only IF 13 & 34 emas are below 50 ema.
b = (x < z ) AND (y < z);
for( i = 0; i < BarCount; i++ )
{
if( b[i] == 1){
Sell = Cross(z,x) OR Cross(y,x);
PlotShapes(shapeSmallDownTriangle*Sell,colorred, 0, H, Offset=-45);
}
}

_SECTION_END();

you can also visit http://algobase.neotradeanalytics.com/   for basic AFL's

Regards,

Sharath