how to give two condition to enter a trade

#1
first, i would like to tell that I m not a programmer , so plz explain to me why my code is not working . i want to give two condition to enter a trade like when macd cross signal then only look only for MA cross over and enter trade

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

ma1= MA(Close,20);
ma2=MA(Close,40);




condi2= Cross(MACD(), Signal());
condi1=Cross(ma1,ma2);
sell1= Cross(ma2,ma1);



atr1= ATR(14);

Buy= Sell = Null;
bflag= sflag=0;

for( i = 1; i < BarCount; i++ )
{
if ( condi2[ i ] AND condi1 AND bflag == 0)
{
Buy = 1;
bflag = 1;
BuyPrice[ i ] =condi1[ i ];


}


if( sell1 AND bflag == 1)
{
Sell = 1;
if(sell1) SellPrice= sell1;
bflag = 0;
sflag=1;
}




//if(Buy)PlotText("buy @" +BuyPrice, i, L-atr1,colorGreen,colorBlack,-55);
//if(Sell)PlotText("sell @" +SellPrice, i, H+atr1, colorRed, colorBlack,40);
}


Plot(ma1, "ma1", colorGreen, styleThick);
Plot(ma2, "ma2", colorRed, styleLine);


PlotShapes(IIf(Buy, shapeUpArrow, shapeNone), colorGreen, 0, L, -35);
PlotShapes(IIf(Sell, shapeCircle, shapeNone), colorBlue, 0, H, 15);
 
#2
Pl chk the corrected afl of yours

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

ma1= MA(Close,20);
ma2=MA(Close,40);




condi2= Cross(MACD(), Signal());
condi1=Cross(ma1,ma2);
sell1= Cross(ma2,ma1);



atr1= ATR(14);

Buy= Sell = Null;
bflag= sflag=0;

for( i = 1; i < BarCount; i++ )
{
if ( condi2[ i ] AND condi1 AND bflag == 0)
{
Buy = 1;
bflag = 1;
BuyPrice[ i ] =condi1[ i ];


}


if( sell1 AND bflag == 1)
{
Sell = 1;
if(sell1 )
SellPrice= sell1;
bflag = 0;
sflag=1;
}




//if(Buy)PlotText("buy @" +BuyPrice, i, L-atr1,colorGreen,colorBlack,-55);
//if(Sell)PlotText("sell @" +SellPrice, i, H+atr1, colorRed, colorBlack,40);
}

Plot(ma1, "ma1", colorGreen, styleThick);
Plot(ma2, "ma2", colorRed, styleLine);

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone), colorGreen, 0, L, -35);
PlotShapes(IIf(Sell, shapeCircle, shapeNone), colorBlue, 0, H, 15);
 
#3
corrected one

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

ma1= MA(Close,20);
ma2=MA(Close,40);




condi2= Cross(MACD(), Signal());
condi1=Cross(ma1,ma2);
sell1= Cross(ma2,ma1);



atr1= ATR(14);

Buy= Sell = Null;
bflag= sflag=0;

for( i = 1; i < BarCount; i++ )
{
if ( condi2[ i ] AND condi1 AND bflag == 0)
{
Buy = 1;
bflag = 1;
BuyPrice[ i ] =condi1[ i ];


}


if( sell1 AND bflag == 1)
{
Sell = 1;
if(sell1 )
SellPrice= sell1;
bflag = 0;
sflag=1;
}




//if(Buy)PlotText("buy @" +BuyPrice, i, L-atr1,colorGreen,colorBlack,-55);
//if(Sell)PlotText("sell @" +SellPrice, i, H+atr1, colorRed, colorBlack,40);
}

Plot(ma1, "ma1", colorGreen, styleThick);
Plot(ma2, "ma2", colorRed, styleLine);

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone), colorGreen, 0, L, -35);
PlotShapes(IIf(Sell, shapeCircle, shapeNone), colorBlue, 0, H, 15);
 
#4
corrected one

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

ma1= MA(Close,20);
ma2=MA(Close,40);




condi2= Cross(MACD(), Signal());
condi1=Cross(ma1,ma2);
sell1= Cross(ma2,ma1);



atr1= ATR(14);

Buy= Sell = Null;
bflag= sflag=0;

for( i = 1; i < BarCount; i++ )
{
if ( condi2[ i ] AND condi1 AND bflag == 0)
{
Buy = 1;
bflag = 1;
BuyPrice[ i ] =condi1[ i ];



}


if( sell1 AND bflag == 1)
{
Sell = 1;
if(sell1 )
SellPrice= sell1;
bflag = 0;
sflag=1;
}





//if(Buy)PlotText("buy @" +BuyPrice, i, L-atr1,colorGreen,colorBlack,-55);
//if(Sell)PlotText("sell @" +SellPrice, i, H+atr1, colorRed, colorBlack,40);
}


Plot(ma1, "ma1", colorGreen, styleThick);
Plot(ma2, "ma2", colorRed, styleLine);


PlotShapes(IIf(Buy, shapeUpArrow, shapeNone), colorGreen, 0, L, -35);
PlotShapes(IIf(Sell, shapeCircle, shapeNone), colorBlue, 0, H, 15);
hi, thank you for your reply
an error is comming "Error 6. Condition in IF, WHILE, FOR statements has to be Numeric or Boolean type. You can not use array here, please use [] (array subscript operator) to access array elements"
 
#5
pl chk the following code

_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

ma1= MA(Close,20);
ma2=MA(Close,40);




condi2= Cross(MACD(), Signal());
condi1=Cross(ma1,ma2);
sell1= Cross(ma2,ma1);



atr1= ATR(14);

Buy= Sell = Null;
bflag= sflag=0;

for( i = 1; i < BarCount; i++ )
{
if ( condi2[ i ] AND condi1 AND bflag == 0)
{
Buy = 1;
bflag = 1;
BuyPrice[ i ] =condi1[ i ];


}


if( sell1 AND bflag == 1)
{
Sell = 1;
if(sell1 )
SellPrice= sell1;
bflag = 0;
sflag=1;
}




//if(Buy)PlotText("buy @" +BuyPrice, i, L-atr1,colorGreen,colorBlack,-55);
//if(Sell)PlotText("sell @" +SellPrice, i, H+atr1, colorRed, colorBlack,40);
}

Plot(ma1, "ma1", colorGreen, styleThick);
Plot(ma2, "ma2", colorRed, styleLine);

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone), colorGreen, 0, L, -35);
PlotShapes(IIf(Sell, shapeCircle, shapeNone), colorBlue, 0, H, 15);
 
#6
replace the following lines
1) if ( condi2[ i ] AND condi1 AND bflag == 0) to if ( condi2[ i ] AND condi1 AND bflag == 0)


2)if(sell1 ) to if(sell1)
 
#8
_SECTION_BEGIN("Price");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) Vol " +WriteVal( V, 1.0 ) +" {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 )) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
_SECTION_END();

ma1= MA(Close,20);
ma2=MA(Close,40);




condi2= Cross(MACD(), Signal());
condi1=Cross(ma1,ma2);
sell1= Cross(ma2,ma1);



atr1= ATR(14);

Buy= Sell = Null;
bflag= sflag=0;

for( i = 1; i < BarCount; i++ )
{
if ( condi2[ i ] AND condi1 AND bflag == 0)
{
Buy = 1;
bflag = 1;
BuyPrice[ i ] =condi1[ i ];


}


if( sell1 AND bflag == 1)
{
Sell = 1;
if(sell1 )
SellPrice= sell1;
bflag = 0;
sflag=1;
}




//if(Buy)PlotText("buy @" +BuyPrice, i, L-atr1,colorGreen,colorBlack,-55);
//if(Sell)PlotText("sell @" +SellPrice, i, H+atr1, colorRed, colorBlack,40);
}

Plot(ma1, "ma1", colorGreen, styleThick);
Plot(ma2, "ma2", colorRed, styleLine);

PlotShapes(IIf(Buy, shapeUpArrow, shapeNone), colorGreen, 0, L, -35);
PlotShapes(IIf(Sell, shapeCircle, shapeNone), colorBlue, 0, H, 15);