Start Scanning Stocks using Amibroker Exploration

Now here is a simple question. You have the NSE EOD database for amibroker.( If not you can download the NSE EOD database – updated upto 28 July 2010) and the stocks in nse is more than 1300 symbols.

Question :
Now all you need to do is you have to find the list of stocks that had recently made 5/20 EMA crossover from the bunch of NSE Stock pack and also you have to scan the stocks with price value greater than Rs50. And also print the values of 5EMA and 20 EMA values for those corresponding stocks.

Answer:
An exploration makes it easy to filter stocks or get data in a specified format. And now inorder to filter the stocks based on 5/20 EMA crossover from database and also to filter the stocks only above Rs 50 use the filter function as shown below

Filter=Cross(EMA(C,5),EMA(C,20)) AND C>50;

cross function is used to identify the crossovers and C in the above notation denotes the Close price.

And inorder to print the values of 5EMA and 20 EMA values for those corresponding stocks use the funtion AddColumn as shown below

AddColumn(EMA(C,5),”EMA-5″,1.2);
AddColumn(EMA(C,20),”EMA-20″,1.2);

Now save the simple 5-20 EMA scanner as a .afl file under the directory c:program filesamibrokerformulascustomSimple 5-20 EMA scanner.afl

Goto->Amibroker->Analysis->Automatic Analysis and select All Symbols and n=1. The value of n is choose as one just to find out the recent 5/20 EMA crossover among the list of nse stocks as shown below .Also select the Simple 5-20 EMA scanner formula afl file from the c:program filesamibrokerformulascustom path

Select Explore button to start filtering the stock database and the results of EMA 5/20 crossover will be published along with the technical data 5EMA and 20 EMA values.

Now the list of Stocks the meets the criteria i.e EMA(5,13) bullish crossover and also the stocks should also be above Rs 50 simply arrives as shown above


And we will work out some of the famous stock scanning methods in upcoming sessions step by step.

Related Readings and Observations

  • NMA Swing Explorer I had added few more codes to the NMA Buy or Sell Signal to make it exploration possible. The purpose of the Exploration is to identify the stop loss of any kind of trade at the given time.
  • N Bar High-Low Dots – Amibroker AFL code Here is a simple strategy that alerts by plotting dots over the candle whenever a new N bar high-low is made. The below chart shows Nifty future EOD charts and the Yellow dots in this […]
  • William VIX FIX Indicator – Amibroker AFL Code We know that VIX most of the time reflects the investor/traders sentiment. When VIX is higher it means lot of fear in the market and lower VIX indicates lack of fear in the market. The […]
  • Amibroker – Button Style Manual Trading Control for NEST/NOW Here is a button style manual control to place One-Click Trading from Amibroker Charts. He had desinged the framework for sending manual click button trading from Amibroker to NEST/NOW […]

Comments

  1. CoolDude says

    In this formula:

    AddColumn(EMA(C,5),”EMA-5″,1.2);
    AddColumn(EMA(C,20),”EMA-20″,1.2);

    What is 1.2 doing? Can you please tell

  2. says

    1.2 is just to output the stock values in 2 decimal digits
    1.5 gives 5 decimal digits, 1.0 gives no decimal digits as output.

    For Example the output of EMA(20) for different format

    1.2 format -> 129.56

    1.5 format -> 129.56780

    1.0 format -> 129

    And the integer part of this number can be used to pad formatted number with spaces here it will be spaced with one character in the above example.

  3. Veer says

    Dear Rajendran,

    Thank you very much. I am interested in MACD above 0 line and bullish cross over.There are some bolgspots which gives MACD Bullish Cross Over. But I need at the same time MACD to be above 0 line. How to do. Please help me.

    Thanks in Advance,

    Regards,

    Veer

  4. says

    @veer
    Here r1,r2 are the moving average
    r3 = Signal Average
    s1 = Signal(Blue line)
    m1 = MACD(Red line)
    m1-s1 = MACD histogram(Black line)

    So use

    Filter = MACD(r1,r2)>0 AND Cross(MACD(r1,r2),Signal(r1,r2,r3));
    AddColumn(MACD(r1,r2),”MACD”,1.2);
    AddColumn(Signal(r1,r2,r3),”Signal”,1.2);

    which will produced MACD above zero line and also the bullish MACD,signal crossover. Check out the afl code as shown below

    _SECTION_BEGIN(“MACD”);
    r1 = Param( “Fast avg”, 12, 2, 200, 1 );
    r2 = Param( “Slow avg”, 26, 2, 200, 1 );
    r3 = Param( “Signal avg”, 9, 2, 200, 1 );

    Plot( ml = MACD(r1, r2), StrFormat(_SECTION_NAME()+”(%g,%g)”, r1, r2), ParamColor(“MACD color”, colorRed ), ParamStyle(“MACD style”) );

    Plot( sl = Signal(r1,r2,r3), “Signal” + _PARAM_VALUES(), ParamColor(“Signal color”, colorBlue ), ParamStyle(“Signal style”) );

    Plot( ml-sl, “MACD Histogram”, ParamColor(“Histogram color”, colorBlack ), styleNoTitle | ParamStyle(“Histogram style”, styleHistogram | styleNoLabel, maskHistogram ) );

    Filter = MACD(r1,r2)>0 AND Cross(MACD(r1,r2),Signal(r1,r2,r3));

    AddColumn(MACD(r1,r2),”MACD”,1.2);
    AddColumn(Signal(r1,r2,r3),”Signal”,1.2);

    _SECTION_END();

  5. bala says

    HI MR.Rajan i would like to learn the use of amibrokersoftware and let me know in detaily if u free enough to share and even i can keep in tuch if u dont mind to leave the mail id thanks

  6. raghuramareddy says

    Dear Rajandran,

    Thanks for the above.Please tell me the afl for 5/20 ema cross over for amibroker.Earlier u had given afl for 30/1070 for intraday.Please do the need ful.

    Raghu

  7. men says

    Hi,
    In the profit table for which the afl is put up could you please explain how the profit for the month is calculated? Could you also please verify the accuracy as I found some major differences with eod data.
    Also is any gann afl for drawing the 45 degree lines available with anyone here.
    Thanks.

  8. kalpen says

    dear rajandran,
    i want to learn coding of AFL for running various scans on amibroker databases. and also coding of various conditions for my trading system,
    can u pls guide me how can i learn so?
    thanx .

    ur blog is very informative and usefull.
    specially information about new data-feed softwares.

    -kp

  9. says

    @Kalpen,
    Iam intrested in sharing more simple strategies with amibroker to understand it in a better way to built complex strategies. will write more about the afl strategies.

  10. Akki says

    Hello Friends & Rajandran Sir

    Would request all to check out this amibroker formula which can give full eod analysis of the eod data in amibroker, would like to help our family :)

    _SECTION_BEGIN(“All in One Explorer -- Manish”);
    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=CRef(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),-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)=Ref(C,-11),1,-1)+
    IIf(C>=Ref(C,-12),1,-1)+
    IIf(C>=Ref(C,-13),1,-1)+
    IIf(C>=Ref(C,-14),1,-1)+
    IIf(C>=Ref(C,-15),1,-1)+
    IIf(C>=Ref(C,-16),1,-1)+
    IIf(C>=Ref(C,-17),1,-1)+
    IIf(C>=Ref(C,-18),1,-1)+
    IIf(C>=Ref(C,-19),1,-1)+
    IIf(C>=Ref(C,-20),1,-1);
    */

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

  11. Akki says

    I have back tested this formula & it really works great hope this gets a add on to the pages of the book by Rajandran sir I got this afl from my friend and works great..:)

    There is a request Sir can you help us find any afl which can scan the stocks which are about to hit UC or LC in bse or nse stock exchange, can it scan the filter of the stocks and help us find and hunt down those stocks which can hit uc or lc, as per there are so many stocks which keep on hitting uc and give more then 50% return in just 1 week time, so if possible plz post a article where we can scan the stocks which can hit uc in bse or nse :)

    Thx a lot sir n keep rocking n hope the afl works and help the family

    regards

  12. says

    Akki iam holding this afl got from traderji.com long time back… and this is the source of inspiration to write the above post. And Thanks! for posting those AFL codes.

    Making! 50% in a week…. man you are damm crazy!
    Anyways will post more!

  13. Jagan says

    Hi Akki,

    Can you please send me the AFL to my mail id.
    As I am getting lot of errors and I am new to Amibroker.

    Rajendran,
    Thanks a lot for starting this wonderful thread.

    Hoping to make 50% weekly by the Circuit breaker AFL :)

    TIA.
    -JK

  14. Akki says

    Thx & i am really happy to see :) the reply from your side, :) no no I dont want 50% returns in a week but if you see the recent 15 days stocks then one can find so many stocks which have run more then 50% in just one week, I just wanted to scan out the stocks in nse or bse which are near to uc levels so that when they are about to hit the uc we can catch them and get out at the right time and like this we can also get into manipulation plan which is done by big players, would be grateful to know if you can create a afl plz :)

    The abv afl was shared with me by one of my friends & i am always there to hlp the family.

    Hoping to see a afl soon

    Thx a lot once again :) keep rocking tc

  15. kalyan says

    hello sir , i am not so experienced with amibroker, specially how to use afl. but today in inditraders i saw a afl by karthikmarar( a famious contributer in inditraders), that is “trend manager”. i have downloaded it. u can search it in inditraders.
    pls make us know how to use it and will it work with amibroker trial.
    if such a expert adviser available in metastock.
    if ur site have uploading facility i will try to upload mr rajendran sir.

  16. Akki says

    Thx jagan & ravi well I hav ebeen using the same afl and its working fine with me just follow the right steps and copy paste the code in the right way i am using ami 5.3 version may be a lower version is not supportive with the same, so try with 5.3 version and follow the right steps

    Rajandran Sir can you post a article on afl related to scan stocks which can hit uc in coming sessions or near to the circuit filters in bse?

    Thx all for responses

  17. Ravi says

    little change to my previous comment. the excel sheets give buy/sell call, based on pr.day high and low. results will be good if orders are placed before market open. the idea is not to miss the open gap.

    regards

  18. vishal says

    Hi,Rajendran
    I have following error at adding ur formula for 5-20EMA scanner

    Filter=Cross(EMA(C,5),EMA(C,20)) AND C>50;
    AddColumn(EMA(C,5),”EMA-5″,1.2);
    AddColumn(EMA(C,20),”EMA-20″,1.2);

    Ln:2,col:26: error 31,syntax error,expecting’)’ or ‘,’

    I tried above changes but it did’nt work pls help me.

  19. snv says

    Hi Rajandran,

    I am trying to identify all the stocks that are trading with in 5% of the historical high. I am a new user of amibroker FL, and trying to figure out how this can be done. My original code is

    Filter = EndValue(Close) > 0.95*Highest(Close);
    AddTextColumn(“FullName()”,”Name”);
    AddColumn(Close, “Last Close”);
    AddColumn(Highest(Close), “Historical High”);

    And it did’nt work the way I wanted it. Can you help me out? thanks and rgds,

  20. Alex says

    hi

    I have a awesome oscillator as afl file in custom folder in ami broker , i want to use it to filter stocks, I want to know whn the awesome osillator crosses the zero line , can you help in the code for this

    regards

    Alex

  21. prithviraj aithal says

    on the above afl code in the comment section: all in one afl code, I am getting an error…
    _SECTION_BEGIN(“
    ————--^

    Error 31.
    Syntax error, unexpected $end, expecting ‘)’ or ‘,’

    I did as follows..
    1. copied code, pasted in formuls editor, saved it as .afl code.
    2. —-->automatic anaylsis—-->pick-->saved afl—->(scan, explore,backfill)
    3. the error pops up!

    Please help!

  22. says

    Dear Rajandran,

    I added some more columns to the exploration. Posting for others

    Filter=Cross(EMA(C,5),EMA(C,12)) AND C>25;
    AddColumn(EMA(C,5),”EMA-5″,1.2);
    AddColumn(EMA(C,12),”EMA-12″,1.2);
    AddColumn(O,”Open”,1.2);
    AddColumn(H,”High”,1.2);
    AddColumn(L,”Low”,1.2);
    AddColumn(C,”Close”,1.2);
    AddColumn(V,”Volume”,1);

  23. Ajit says

    Dear Amit,

    Got from traderji forum….give it a try

    fa=5;
    sa=15;
    st=21;

    FastAvg = EMA(Close, FA);
    SlowAvg = EMA(Close, SA);
    StopAvg = EMA(Close, ST);

    UpTrend = Cross(FastAvg, SlowAvg);
    StopUpTrend = Cross( Max(SlowAvg, StopAvg), FastAvg);
    downTrend = Cross(SlowAvg, FastAvg);
    StopDownTrend = Cross(FastAvg, Max(SlowAvg, StopAvg));

  24. Eshwar says

    hello Rajandran,

    the above afl is not running first line only some error at the start of the bracket it is showing what is required kindly help I am new to amibroker

  25. Amit says

    Pls help no formula is working i tried explorations and Afl’s from above list but it is showing errors.i tried 5 20 crossover exploration but it is aslo showing errors.

  26. Vinod says

    Hello, I am new to ami broker. As i am not capable of writing codes in amibroker so could any one help in writing a filter with slow stochastic for any time frame, to show which and how many stocks are trading in overbought and oversold conditions with price more than Rs. 100. If any body could help me in this, specially Mr. Rajandran sir. Please help.

  27. niraj says

    Hi, Mr. Rajandran R
    I request you to I want to make my own afl , the subject are as under
    “Stock open gap up or gap down and current rate are running above open or below open afl scanner for amibroker” please send me.
    thanking you.

  28. amit says

    Hi Rajandran,

    The afl that u demonstrated , showed 100’s of stocks in amibroker.

    How to choose best among them?

    I can not buy 100’s of stock.I can buy max of 5,how choose 5 from 100.

    Thanks

  29. sumit says

    dear rajandran

    there are many buy sell arrow indicators in marketcalls

    if i take any such indicator . and i want notification in real time say whenever a buy arrow comes or a sell arrow comes a notification comes. from a watch list of say 100 stocks further can the same be done across multi tfs also ?

    please put a you tube video using your own supertrend afl .

    • says

      Will try it out. Personally Amibroker i dont prefer setting an rule based Popup or Sound Alerts with Amibroker. Apart from that Amibroker is the Best.

      • sumit says

        even if the results are displayed in the analysis window itself after every arrow on the selected time frames across a universe of say 50 symbols it is enuf.

        but the arrow signal shud be notified in real time

        ps -- i use 5 min tf

  30. Rajesh says

    Hello Rajendran,

    I am reading your old posts from a few months now , i am really happy for helping out new bies like me with important materials.

    Just a question, if i want to use amibroker exploration to find daily RSI high low for all scrips in watchlist than what code should i use , This can help me in selecting stocks for next days trades.

    The format should be:

    Scrip RSI -H RSI-L

  31. Aman says

    Sir,

    Would like to get Alerts when a particular condition is triggered in my database of Stocks.

    Ex-

    I use explore function to get list of Stocks breaking Prv day HI- low.

    Need a Alert option so that it gives me alert when the price breaks High or low of Previous day during the day.Alert could be a Pop up window so that i dont have to run Explore again and again

    Thanks in Advance

    Regards

Leave a Reply

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