Help Requested Please -Multiple EMA & MA Crossover on multiple timeframes

#1
Hello Experts
Request help for AFL for displaying stocks who's CLOSE is above multiple EMA's and MA's on daily, weekly and monthly timeframe. Below is an AFL (which i started coding on Dly timeframe - being a novice) which should give SripName in the EXPLORE for all stocks close > EMA 5,10,20,50 & MA100,200. Strangely, it is not being shown. Also another problem is that it is showing output of stocks who Closing price is < 1 Rupee ...

Say for example, as of now - 28Jul2017 closing, HDFC close is above EMA 5,10,20,50 and MA 100,200 on all timeframes (Dly & Wkly & Mnthly). But the same is not coming in the Explore output.
Attaching all screenshots for reference.
Can someone please help to code the requirement please ?
Requesting a code which will display all stocks to be shown who's CLOSE is above EMA 5,10,20,50 and MA100,200 on all timeframes - Daily, Weekly & Monthly
(Have attached the files of Explore output and HDFC Chart on multiple timeframes)

Below is the code which I had written - as a starting point. Please help by modifying the same

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

_SECTION_BEGIN("EMA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("EMA2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("EMA3");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("EMA4");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();


_SECTION_BEGIN("MA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("MA2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();


//_SECTION_BEGIN("MA_Buy-Sell");
//M100=MA(C,100);
//M200=MA(C,200);

COND1 = EMA(C,5) AND EMA(C,10) AND EMA(C,20) AND EMA(C,50) AND MA(C,100) AND MA(C,200);
BuyCond= EMA(C,5) > EMA(C,10)> EMA(C,20) > EMA(C,50) > MA(C,100) > MA(C,200);
SellCond= EMA(C,5) < EMA(C,10) < EMA(C,20) < EMA(C,50) < MA(C,100) < MA(C,200);

MA_BUY=IIf((C > COND1) AND (BuyCond==True),1,0);
MA_SELL=IIf((C < COND1) AND (SellCond==True),1,0);

Filter = MA_Buy OR MA_Sell;


AddColumn(Close,"Close");


BuySig = IIf((MA_buy) == True, 1, 0) ;
SellSig = IIf((MA_sell) == True, 1, 0);


AddColumn(BuySig,"Buy", format = 1.2, IIf(BuySig, Textcolor = colorGreen, textcolor = colorWhite));
AddColumn(SellSig,"Sell", format = 1.2, IIf(SellSig, Textcolor = colorRed, textcolor = colorWhite));
AddColumn(EMA(C,5),"EMA5");
AddColumn(EMA(C,10),"EMA10");
AddColumn(EMA(C,20),"MA100");
AddColumn(EMA(C,50),"MA100");
AddColumn(MA(C,100),"MA100");
AddColumn(MA(C,200),"MA200");
 

Attachments

Romeo1998

Well-Known Member
#2
Hello Experts
Request help for AFL for displaying stocks who's CLOSE is above multiple EMA's and MA's on daily, weekly and monthly timeframe. Below is an AFL (which i started coding on Dly timeframe - being a novice) which should give SripName in the EXPLORE for all stocks close > EMA 5,10,20,50 & MA100,200. Strangely, it is not being shown. Also another problem is that it is showing output of stocks who Closing price is < 1 Rupee ...

Say for example, as of now - 28Jul2017 closing, HDFC close is above EMA 5,10,20,50 and MA 100,200 on all timeframes (Dly & Wkly & Mnthly). But the same is not coming in the Explore output.
Attaching all screenshots for reference.
Can someone please help to code the requirement please ?
Requesting a code which will display all stocks to be shown who's CLOSE is above EMA 5,10,20,50 and MA100,200 on all timeframes - Daily, Weekly & Monthly
(Have attached the files of Explore output and HDFC Chart on multiple timeframes)

Below is the code which I had written - as a starting point. Please help by modifying the same

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

_SECTION_BEGIN("EMA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("EMA2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("EMA3");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("EMA4");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( EMA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();


_SECTION_BEGIN("MA1");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();

_SECTION_BEGIN("MA2");
P = ParamField("Price field",-1);
Periods = Param("Periods", 15, 2, 300, 1, 10 );
Plot( MA( P, Periods ), _DEFAULT_NAME(), ParamColor( "Color", colorCycle ), ParamStyle("Style") );
_SECTION_END();


//_SECTION_BEGIN("MA_Buy-Sell");
//M100=MA(C,100);
//M200=MA(C,200);

COND1 = EMA(C,5) AND EMA(C,10) AND EMA(C,20) AND EMA(C,50) AND MA(C,100) AND MA(C,200);
BuyCond= EMA(C,5) > EMA(C,10)> EMA(C,20) > EMA(C,50) > MA(C,100) > MA(C,200);
SellCond= EMA(C,5) < EMA(C,10) < EMA(C,20) < EMA(C,50) < MA(C,100) < MA(C,200);

MA_BUY=IIf((C > COND1) AND (BuyCond==True),1,0);
MA_SELL=IIf((C < COND1) AND (SellCond==True),1,0);

Filter = MA_Buy OR MA_Sell;


AddColumn(Close,"Close");


BuySig = IIf((MA_buy) == True, 1, 0) ;
SellSig = IIf((MA_sell) == True, 1, 0);


AddColumn(BuySig,"Buy", format = 1.2, IIf(BuySig, Textcolor = colorGreen, textcolor = colorWhite));
AddColumn(SellSig,"Sell", format = 1.2, IIf(SellSig, Textcolor = colorRed, textcolor = colorWhite));
AddColumn(EMA(C,5),"EMA5");
AddColumn(EMA(C,10),"EMA10");
AddColumn(EMA(C,20),"MA100");
AddColumn(EMA(C,50),"MA100");
AddColumn(MA(C,100),"MA100");
AddColumn(MA(C,200),"MA200");
Dear friend,
use this code :)
It will show the required results in exploration and arrows on chart :)
Code:
_SECTION_BEGIN( "Price" );
SetChartOptions( 0, chartWrapTitle | chartShowArrows | chartShowDates, 0 );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
Plot( C, "Close", ParamColor( "Color", colorDefault ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );

Plot( EMA( C, 5 ), "Ema 5", coloryellow , Styleline ) ;
Plot( EMA( C, 10 ), "Ema 10", colorred , Styleline ) ;
Plot( EMA( C, 20 ), "Ema 20", colorgreen , Styleline ) ;
Plot( EMA( C, 50 ), "Ema 50", colorblue , Styleline ) ;
Plot( MA( C, 100 ), "Ma 100", colororange , Styleline ) ;
Plot( MA( C, 200 ), "Ma 200", colorviolet , Styleline ) ;

DC = TimeFrameGetPrice( "C", inDaily, 0, expandLast );
WC = TimeFrameGetPrice( "C", inWeekly, 0, expandLast );
MC = TimeFrameGetPrice( "C", inMonthly, 0, expandLast );

BuyCond = EMA( DC, 5 ) > EMA( DC, 10 ) AND EMA( DC, 10 ) > EMA( DC, 20 ) AND EMA( DC, 20 ) > EMA( DC, 50 ) AND EMA( DC, 50 ) > MA( DC, 100 ) AND MA( DC, 100 ) > MA( DC, 200 )
          AND EMA( WC, 5 ) > EMA( WC, 10 ) AND EMA( WC, 10 ) > EMA( WC, 20 ) AND EMA( WC, 20 ) > EMA( WC, 50 ) AND EMA( WC, 50 ) > MA( WC, 100 ) AND MA( WC, 100 ) > MA( WC, 200 )
          AND EMA( MC, 5 ) > EMA( MC, 10 ) AND EMA( MC, 10 ) > EMA( MC, 20 ) AND EMA( MC, 20 ) > EMA( MC, 50 ) AND EMA( MC, 50 ) > MA( MC, 100 ) AND MA( MC, 100 ) > MA( MC, 200 );

SellCond = EMA( DC, 5 ) < EMA( DC, 10 ) AND EMA( DC, 10 ) < EMA( DC, 20 ) AND EMA( DC, 20 ) < EMA( DC, 50 ) AND EMA( DC, 50 ) < MA( DC, 100 ) AND MA( DC, 100 ) < MA( DC, 200 )
           AND EMA( WC, 5 ) < EMA( WC, 10 ) AND EMA( WC, 10 ) < EMA( WC, 20 ) AND EMA( WC, 20 ) < EMA( WC, 50 ) AND EMA( WC, 50 ) < MA( WC, 100 ) AND MA( WC, 100 ) < MA( WC, 200 )
           AND EMA( MC, 5 ) < EMA( MC, 10 ) AND EMA( MC, 10 ) < EMA( MC, 20 ) AND EMA( MC, 20 ) < EMA( MC, 50 ) AND EMA( MC, 50 ) < MA( MC, 100 ) AND MA( MC, 100 ) < MA( MC, 200 );

MA_BUY = IIf( Cross( C , EMA( DC, 5 ) ) AND buycond == True , c, 0 );
MA_SELL = IIf( Cross( EMA( DC, 5 ), C ) AND sellcond == True , c, 0 );

Filter = MA_Buy OR MA_Sell;
AddColumn( MA_BUY, "Buy", format = 1.2, IIf( MA_BUY, colorGreen, colorWhite ), colorDefault, 70 );
AddColumn( MA_SELL, "Sell", format = 1.2, IIf( MA_SELL, colorRed, colorWhite ), colorDefault, 70 );
AddColumn( Close, "Close" );
AddColumn( EMA( DC, 5 ), "D EMA5" );
AddColumn( EMA( DC, 10 ), "D EMA10" );
AddColumn( EMA( DC, 20 ), "D EMA20" );
AddColumn( EMA( DC, 50 ), "D EMA50" );
AddColumn( MA( DC, 100 ), "D MA100" );
AddColumn( MA( DC, 200 ), "D MA200" );
AddColumn( EMA( WC, 5 ), "W EMA5" );
AddColumn( EMA( WC, 10 ), "W EMA10" );
AddColumn( EMA( WC, 20 ), "W EMA20" );
AddColumn( EMA( WC, 50 ), "W EMA50" );
AddColumn( MA( WC, 100 ), "W MA100" );
AddColumn( MA( WC, 200 ), "W MA200" );
AddColumn( EMA( MC, 5 ), "M EMA5" );
AddColumn( EMA( MC, 10 ), "M EMA10" );
AddColumn( EMA( MC, 20 ), "M EMA20" );
AddColumn( EMA( MC, 50 ), "M EMA50" );
AddColumn( MA( MC, 100 ), "M MA100" );
AddColumn( MA( MC, 200 ), "M MA200" );

PlotShapes( IIf( MA_BUY, shapeUpArrow, shapeNone ), colorBrightGreen, 0, L, -20, 0 );
PlotShapes( IIf( MA_SELL, shapedownArrow, shapeNone ), colorRed, 0, H, -20, 0 );
_SECTION_END();
 
Last edited:
#3
Romeo Sir

Thanks for the code and apologies for late reply.
One more request, am getting error in the below lines. Request your help to clear the error please

PlotShapes( IIf( MA_BUY, shapeUpArrow, shapeNone ), colorBrightGreen, 0, L, -20, 0 );
PlotShapes( IIf( MA_SELL, shapedownArrow, shapeNone ), colorRed, 0, H, -20, 0 );

Thanks in advance.
A Bhapkar

Dear friend,
use this code :)
It will show the required results in exploration and arrows on chart :)
Code:
_SECTION_BEGIN( "Price" );
SetChartOptions( 0, chartWrapTitle | chartShowArrows | chartShowDates, 0 );
_N( Title = StrFormat( "{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ) );
Plot( C, "Close", ParamColor( "Color", colorDefault ), styleNoTitle | ParamStyle( "Style" ) | GetPriceStyle() );

Plot( EMA( C, 5 ), "Ema 5", coloryellow , Styleline ) ;
Plot( EMA( C, 10 ), "Ema 10", colorred , Styleline ) ;
Plot( EMA( C, 20 ), "Ema 20", colorgreen , Styleline ) ;
Plot( EMA( C, 50 ), "Ema 50", colorblue , Styleline ) ;
Plot( MA( C, 100 ), "Ma 100", colororange , Styleline ) ;
Plot( MA( C, 200 ), "Ma 200", colorviolet , Styleline ) ;

DC = TimeFrameGetPrice( "C", inDaily, 0, expandLast );
WC = TimeFrameGetPrice( "C", inWeekly, 0, expandLast );
MC = TimeFrameGetPrice( "C", inMonthly, 0, expandLast );

BuyCond = EMA( DC, 5 ) > EMA( DC, 10 ) AND EMA( DC, 10 ) > EMA( DC, 20 ) AND EMA( DC, 20 ) > EMA( DC, 50 ) AND EMA( DC, 50 ) > MA( DC, 100 ) AND MA( DC, 100 ) > MA( DC, 200 )
          AND EMA( WC, 5 ) > EMA( WC, 10 ) AND EMA( WC, 10 ) > EMA( WC, 20 ) AND EMA( WC, 20 ) > EMA( WC, 50 ) AND EMA( WC, 50 ) > MA( WC, 100 ) AND MA( WC, 100 ) > MA( WC, 200 )
          AND EMA( MC, 5 ) > EMA( MC, 10 ) AND EMA( MC, 10 ) > EMA( MC, 20 ) AND EMA( MC, 20 ) > EMA( MC, 50 ) AND EMA( MC, 50 ) > MA( MC, 100 ) AND MA( MC, 100 ) > MA( MC, 200 );

SellCond = EMA( DC, 5 ) < EMA( DC, 10 ) AND EMA( DC, 10 ) < EMA( DC, 20 ) AND EMA( DC, 20 ) < EMA( DC, 50 ) AND EMA( DC, 50 ) < MA( DC, 100 ) AND MA( DC, 100 ) < MA( DC, 200 )
           AND EMA( WC, 5 ) < EMA( WC, 10 ) AND EMA( WC, 10 ) < EMA( WC, 20 ) AND EMA( WC, 20 ) < EMA( WC, 50 ) AND EMA( WC, 50 ) < MA( WC, 100 ) AND MA( WC, 100 ) < MA( WC, 200 )
           AND EMA( MC, 5 ) < EMA( MC, 10 ) AND EMA( MC, 10 ) < EMA( MC, 20 ) AND EMA( MC, 20 ) < EMA( MC, 50 ) AND EMA( MC, 50 ) < MA( MC, 100 ) AND MA( MC, 100 ) < MA( MC, 200 );

MA_BUY = IIf( Cross( C , EMA( DC, 5 ) ) AND buycond == True , c, 0 );
MA_SELL = IIf( Cross( EMA( DC, 5 ), C ) AND sellcond == True , c, 0 );

Filter = MA_Buy OR MA_Sell;
AddColumn( MA_BUY, "Buy", format = 1.2, IIf( MA_BUY, colorGreen, colorWhite ), colorDefault, 70 );
AddColumn( MA_SELL, "Sell", format = 1.2, IIf( MA_SELL, colorRed, colorWhite ), colorDefault, 70 );
AddColumn( Close, "Close" );
AddColumn( EMA( DC, 5 ), "D EMA5" );
AddColumn( EMA( DC, 10 ), "D EMA10" );
AddColumn( EMA( DC, 20 ), "D EMA20" );
AddColumn( EMA( DC, 50 ), "D EMA50" );
AddColumn( MA( DC, 100 ), "D MA100" );
AddColumn( MA( DC, 200 ), "D MA200" );
AddColumn( EMA( WC, 5 ), "W EMA5" );
AddColumn( EMA( WC, 10 ), "W EMA10" );
AddColumn( EMA( WC, 20 ), "W EMA20" );
AddColumn( EMA( WC, 50 ), "W EMA50" );
AddColumn( MA( WC, 100 ), "W MA100" );
AddColumn( MA( WC, 200 ), "W MA200" );
AddColumn( EMA( MC, 5 ), "M EMA5" );
AddColumn( EMA( MC, 10 ), "M EMA10" );
AddColumn( EMA( MC, 20 ), "M EMA20" );
AddColumn( EMA( MC, 50 ), "M EMA50" );
AddColumn( MA( MC, 100 ), "M MA100" );
AddColumn( MA( MC, 200 ), "M MA200" );

PlotShapes( IIf( MA_BUY, shapeUpArrow, shapeNone ), colorBrightGreen, 0, L, -20, 0 );
PlotShapes( IIf( MA_SELL, shapedownArrow, shapeNone ), colorRed, 0, H, -20, 0 );
_SECTION_END();
 

Romeo1998

Well-Known Member
#4
Romeo Sir

Thanks for the code and apologies for late reply.
One more request, am getting error in the below lines. Request your help to clear the error please

PlotShapes( IIf( MA_BUY, shapeUpArrow, shapeNone ), colorBrightGreen, 0, L, -20, 0 );
PlotShapes( IIf( MA_SELL, shapedownArrow, shapeNone ), colorRed, 0, H, -20, 0 );

Thanks in advance.
A Bhapkar
Dear friend A Bhapkar,
Please dont call me Sir :happy: What error r u getting ? :happy:
 

Similar threads