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);
_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);