Trending Stocks Screener: Amibroker Exploration AFL

The best method for long term success in Stock market is to catch the trend and stay with it. The basic premise behind this assumption is the fact that the ongoing trend continues for a decent time period. It’s difficult to manually scan all the stocks and spot the trending ones. This Amibroker exploration AFL for Trending stocks screener would make this task easier for you. It scans across all the stocks in your database and assigns Trend score to them. A trend score of greater than 5 signals upward trending stocks while trend score of less than 2 signals downward trending stocks. Anything between 2 to 5 is a state of confusion and you should avoid investing on such stocks.

Read our article on AFL tutorial here.

Trending Stocks Screener – AFL Overview

Parameter Value
Preferred Time-frame
Daily
Indicators Used Simple Moving Average, Bollinger Bands, MACD, Aroon Indicator, Stochastic Indicator, RSI, MFI
Bullish Conditions
  • Current Close is less than Bollinger Band Bottom and previous close is greater than Bollinger band bottom.
  • Close is greater than Moving average line (15,45 or 100 period)
  • MACD line crosses signal line
  • Aroon Oscillator is greater than zero.
  • StochasticK line is greater than StochasticD line
  • Current candle RSI is greater than 30 and RSI of previous 2 candles is less than 30.
  • MFI is less than 20
Bearish Conditions
  • Current Close is greater than Bollinger Band Top and previous close is less than Bollinger band bottom.
  • Close is less than Moving average line (15,45 or 100 period)
  • MACD Signal line crosses MACD
  • Aroon Oscillator is less than zero.
  • StochasticD line is greater than StochasticK line
  • Current candle RSI is less than 70 and RSI of previous 2 candles is greater than 70.
  • MFI is greater than 80
Trend Score Calculation
Initial Trend Score is zero. 1 point is added for each Bullish condition met. If no Bullish conditions met then Trend score=0, if all Bullish conditions met then Trend score=7

Trending Stocks Screener – AFL Code

//------------------------------------------------------
//
//  Formula Name:    Trending Stocks Screener
//  Author/Uploader: Trading Tuitions
//  E-mail:          support@tradingtuitions.com
//  Website:         www.tradingtuitions.com
//------------------------------------------------------

_SECTION_BEGIN("Trending Stocks Screener");
i=0;
//52 Week High Low
High52 = HHV(High,250);
Low52 = LLV(Low,250);

//Bollinger Band
BB1=C>BBandTop(C,20,2) AND Ref(C,-1)<Ref(BBandTop(C,20,2),-1);
BB2=C<BBandBot(C,20,2) AND Ref(C,-1)>Ref(BBandBot(C,20,2),-1);
BBStatus=WriteIf(BB1,"Above Top",WriteIf(BB2,"Below Bottom",WriteIf(IsNull(MA(C,20)),"N/A","Neutral")));
BBColor=IIf(BB1,colorRed,IIf(BB2,colorGreen,colorLightGrey));
IIf(BB2,i+1,i);

//Moving Average (Short, Mid & Long Term)
MAShort = C>MA(C,15);
IIf(MAShort,i+1,i);
MAMid = C>MA(C,45);
IIf(MAMid,i+1,i);
MALong = C>MA(C,100);
IIf(MALong,i+1,i);
ShortStatus = WriteIf(MAShort,"Bullish",WriteIf(IsNull(MA(C,15)) ,"N/A","Bearish"));
ShortColor = IIf(MAShort,colorGreen,colorRed);
MidStatus = WriteIf(MAMid,"Bullish",WriteIf(IsNull(MA(C,45))," N/A","Bearish"));
MidColor = IIf(MAMid,colorGreen,colorRed);
LongStatus = WriteIf(MALong,"Bullish",WriteIf(IsNull(MA(C,100)) ,"N/A","Bearish"));
LongColor = IIf(MALong,colorGreen,colorRed);

//MACD
MACDBull=MACD(12,26)>Signal(12,26,9);
IIf(MACDBull,i+1,i);
MACDStatus=WriteIf(MACDBull,"Bullish",WriteIf(IsNull(MACD(12,26)),"N/A","Bearish"));
MACDColor=IIf(MACDBull,colorGreen,colorRed);

//Aroon
Period=14;
LLVBarsSince=LLVBars(L,Period)+1;
HHVBarsSince=HHVBars(H,Period)+1;
AroonDown=100*(Period-LLVBarsSince)/(Period-1);
AroonUp=100*(Period-HHVBarsSince)/(Period-1);
AroonOsc=AroonUp-AroonDown;
Aroon=AroonOsc>0;
IIf(Aroon,i+1,i);
AroonStatus=WriteIf(Aroon,"Bullish",WriteIf(IsNull (RSI(14)),"N/A","Bearish"));
AroonColor=IIf(Aroon,colorGreen,IIf(IsNull(RSI(14) ),colorLightGrey,colorRed));

//Stochastic
StochKBull=StochK(14,3)>StochD(14,3,3);
IIf(StochKBull,i+1,i);
StochKStatus=WriteIf(StochKBull,"Bullish",WriteIf( IsNull(StochK(14,3)),"N/A","Bearish"));
StochKColor=IIf(StochKBull,colorGreen,colorRed);

//RSI
R1=RSI(14)>30 AND Ref(RSI(14),-1)<30 AND Ref(RSI(14),-2)<30;
R2=RSI(14)<70 AND Ref(RSI(14),-1)>70 AND Ref(RSI(14),-2)>70;
IIf(R1,i+1,i);
RSIStatus=WriteIf(R1,"Improving",WriteIf(R2,"Decli ning",WriteIf(IsNull(RSI(14)),"N/A","Neutral")));
RSIColor=IIf(R1,colorGreen,IIf(R2,colorRed,colorLightGrey));

//MFI
M1=MFI(14)>80;
M2=MFI(14)<20;
IIf(M2,i+1,i);
MFIStatus=WriteIf(M1,"Overbought",WriteIf(M2,"Over sold",WriteIf(IsNull(MFI(14)),"N/A","Neutral")));
MFIColor=IIf(M1,colorRed,IIf(M2,colorGreen,colorLightGrey));


 TrendScore =

 IIf(BB2,1,0)+
 IIf(MAShort,1,0)+
 IIf(MAMid,1,0) +
 IIf(MAMid,1,0) +
 IIf(MALong,1,0)+
 IIf(MACDBull,1,0) +
 IIf(Aroon,1,0) +
 IIf(StochKBull,1,0)+
 IIf(R1,1,0) +
 IIf(M2,1,0) ;


Filter = 1;

//AddColumn(High52,"52 Week High");
//AddColumn(Low52,"52 Week Low");
AddColumn(C,"Close",1,IIf(C>Ref(C,-1),colorGreen,colorRed));
AddColumn(V,"Volume",1,IIf(V>Ref(V,-1),colorGreen,colorRed));
AddTextColumn(BBStatus,"BBand",1,colorWhite,BBColor);
AddTextColumn(ShortStatus,"Short MA(15)",1,colorWhite,ShortColor);
AddTextColumn(MidStatus,"Mid MA(45)",1,colorWhite,MidColor);
AddTextColumn(LongStatus,"Long MA(100)",1,colorWhite,LongColor);
AddTextColumn(MACDStatus,"MACD",1,colorWhite,MACDColor);
AddTextColumn(AroonStatus,"Aroon",1,colorWhite,AroonColor);
AddTextColumn(StochKStatus,"Stochastic",1,colorWhite,StochKColor);
AddTextColumn(RSIStatus,"RSI(14)",1,colorWhite,RSIColor);
AddTextColumn(MFIStatus,"MFI(14)",1,colorWhite,MFIColor);
AddColumn(TrendScore,"Score");
_SECTION_END();

Exploration Screenshot

Trending Stocks Screener

How to use Trending Stocks Screener ?

Step 1: Copy the AFL code from above and set it up in your local Amibroker.

Step 2: Download and setup EOD data for your preferred exchange.

Step 3: Goto Analysis–>Explore. In the range drop-down select ‘1 recent bar’.

Step 4: In the results, you would be able to see the Trend score for each scrip. A trend score of greater than 5 signals bullish stocks while trend score of less than 2 signals bearish stocks

Disclaimer:

All the AFL’s posted in this section are for learning purpose. Trading Tuitions does not necessarily own these AFL’s and we don’t have any intellectual property rights on them. We might copy useful AFL’s from public forums and post it in this section in a presentable format. The intent is not to copy anybody’s work but to share knowledge. If you find any misleading or non-reproducible content then please inform us at support@tradingtuitions.com

10 Comments

  1. Sir If this TRENDING STOCK SCREENER excel sheet is put up in your website on EOD basis , it will be of great help. Thank u.

  2. Trending Stocks Screener AFL working nice , but not showing any Trend score to any stock can u plz help me

  3. Great codes bro… and thanks a mil for sharing as I was so so desparately looking for a good scanning AFL and yours fits the bill perfectly.
    Have a quick few queries :
    (1) Does it support shorter time frame scans during the day as the market progresses from 9:15 AM (like 5-15 min which can be set in the settings under analysis)
    (2) If I want to do a EOD analysis for shortlisting stocks for tomorrow… let us say for e.g. 17th May (today being 16th May) what are the steps. I am assuming I have to choose from 16.5.2017 to 17.5.17 and choose ‘Daily’under Settings. Is this correct ? All I am looking for to find out stocks that are bearish or bullish for tomorrow
    (3) Strangely the following columns are 90% Neutral despite stocks that have moved very nicely either down or up viz. BBand, RSI(14) and MFI(14).
    I know that is a lot of questions, but cant help it as your AFL is too good. Would greatly appreciate your kind response.

    Namaste
    GK

    • 1) Does it support shorter time frame scans during the day as the market progresses from 9:15 AM (like 5-15 min which can be set in the settings under analysis?

      Yes you can change timeframe from settings

      2) If I want to do a EOD analysis for shortlisting stocks for tomorrow… let us say for e.g. 17th May (today being 16th May) what are the steps. I am assuming I have to choose from 16.5.2017 to 17.5.17 and choose ‘Daily’under Settings. Is this correct ? All I am looking for to find out stocks that are bearish or bullish for tomorrow.

      Yes, you are correct

      (3) Strangely the following columns are 90% Neutral despite stocks that have moved very nicely either down or up viz. BBand, RSI(14) and MFI(14).

      It totally depends on the values of those indicators and ongoing trend. Let us know if you see any discrepancies in their values

  4. Also want to add there are many places where it says “Bearish” but appears in “Green”color and vice versa.

    • Hi Hari,

      In order to study MCX commodities, you would need to import MCX data into Amibroker. I am not sure about any free data sources, but there are plenty of paid options available out there.

Leave a Reply

Your email address will not be published. Required fields are marked *