Buy is not happening as per program

My intention was to use scale in when 3 different MAs cross over each other like MA1 cross MA2, MA1 cross MA3 & Ma2 cross MA3 and in each cross i want to buy with scalein. below AFL is running with wrong buy signals even when there is no cross at all. Can any body help me out to find the mistake I am doing. Scale In I am doing with Van Tharpe position sizing and eventually with Position score. But several buy signals are coming where there is no cross over and seems arbitrarily giving signal-

SetTradeDelays( 1,1,1, 1 );
SetOption( "InitialEquity", 1000000);
SetOption("FuturesMode" ,True);
SetOption( "AllowPositionShrinking", True );
SetOption("MaxOpenPositions", 5);

MA1 = MA(C,5);
MA2= MA(C,20);
MA3 = MA (C,34);
buysig1 = Cross(MA1, MA2);
buysig2 = Cross(MA1, MA3);
buysig3 = Cross(MA2,MA3);
sellsig1 = Cross(MA2,MA1);

Entrysignal1 = ValueWhen(Cross(MA1, MA2), C, 1);
Entrysignal2 = ValueWhen(Cross(MA1, MA3),C,1);
Entrysignal3 = ValueWhen(Cross(MA2,MA3), C, 1);
Exitsignal = H-2*ATR(20);

Entry=IIf((buysig1 OR buysig2 OR buysig3), 1,0);
X= SumSince(sellsig1, Entry>0);

firsttrade = X ==1;
secondtrade = X ==2;
Thirdtarde = X ==3;


Stopsize1 = Entrysignal1 - Exitsignal;
Stopsize2 = Entrysignal2 - Exitsignal;
Stopsize3 = Entrysignal3 - Exitsignal;

pos1 = 100*RiskPct/Stopsize1;
pos2 = 50*RiskPct/Stopsize2;
pos3 = 20*RiskPct/Stopsize3; 

SetPositionSize(IIf(firsttrade,pos1,IIf(secondtrade,pos2,pos3)),spsPercentOfEquity);// invest 20% of portfolio equity in single trade
RoundLotSize = 1;
//PositionScore = ADX(14); 

Buy = IIf(Entry == 1, sigScaleIn,0);
Sell = Exit;

Plot( Close, "Price",colorWhite, styleCandle );

Plot(ema( C, 5),"5EMA",colorWhite);
Plot(ema( C, 20),"20EMA",colorYellow);
Plot (ema( C, 34),"34EMA", colorRed);

@samik, Sorry I don't have time to look seriously into your code, but might I suggest you learn how to use the EXPLORATION. It allows you to track whatever signals and values you have on a bar by bar basis.

That will undoubtedly help you find where you are not getting the signals you want when you want them.

Sorry. pls ignore this afl and don't waste time to check it. This is a wrong AFL one and I shall make it from scratch again. I tried to delete my post but couldn't do it