# 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.

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

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.

## Plotting Day Wise Equity Curve using Amibroker

We know that Amibroker provides an equity curve for the whole strategy. Is there a way where we can build a simple Day Wise...

## 62 Replies to “Start Scanning Stocks using Amibroker Exploration”

1. CoolDude says:

In this formula:

What is 1.2 doing? Can you please tell

2. 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.

Regards,

Veer

4. @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));

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

_SECTION_END();

5. Kalyan says:

give the procedure for metastock 8 also for eod sir

6. Kalyan says:

i am using amibroker trial for realtime manshi rt. can i use this afl for realtime

7. 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

8. Veer says:

Dear Rajendran,

Thank you very much. I noticed just now.

Regards,

Veer

9. 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

10. 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.

11. 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

12. @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.

13. Bijoy says:

above afl is showing so many syntax errors..would u rectify plzz..Bijoy

1. @Bijoy use this afl only for exploration…. it doesnt plot any charts on the amibroker window

14. Ravi says:

dear sir

i need afl to explore ema-3,ema-13,ema26 crossover pls help

15. 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;
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;

_SECTION_END();

16. 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

17. 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!

18. @Ravi will post tommorow morning….

19. 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

20. 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

21. Ravi says:

dear akki

afl posted by u shows some error-13 excepting “)” or ‘,’

regards

22. 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.

23. 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

24. 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

25. 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;

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

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

26. 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);

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

27. 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

28. 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!

29. CHINTAN SHAH says:

HELLO SIR MUJHE APNA EK KHUD KA AFL BANWANA HAI . CAN U HELP ME SIR

30. Dharani says:

1. @Dharani : The article is nothing but scanning stocks based on mathematical conditions.

31. Ajit 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;

32. Amit says:

Rajan Sir

Can I get an exploration for cross over of 3 moving averages ? Please advise

33. 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));

34. 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

35. 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.

36. 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.

37. 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.

38. 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

39. 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 .

1. 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.

1. 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

40. 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

41. 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

Regards

42. ashvin says:

Rajandran,

I have NSE data from 2000 in Txt format, but in this time a lot of stocks have got delisted etc. Now how can delete or atleast omit them from my amibroker

1. Will shortly try to put a video on that

1. ashu says:

hey man,

any luck with the video, if you have found out the solution can you tell me where is the link to the video??

43. sanjay says:

looking for scan/Exploration afl which filter 1st fib retracement from last swing high 2nd stock above 20,50,100 ema 3rd price above up trend line in case of up trend and in Dw trend 2nd and 3rd is just opposite.
thanks

44. prince says:

dear sir please send how pop up window will creat in amibroker,please mail me

45. Vinod Sakaram says:

Need a exploration formula

Base volume – open to 9:30 AM
Volume 1 – 9:30 to 10:30 AM

at 11:00 AM, 10:30 data shall become base and volume ended at 11:00
at 11:30 AM, 11:00 data shall become base and volume ended at 11:30
so on upto 3 : 30 PM

columns required.

Scrip Code, Volume of Base, Volume 1, Average price of Volume1, O, H, L C

46. KANAKA RAJA C says:

I m new to amibroker. I take guidence from market calls in the course of learning amibroker and daytrading. I encountered one problem in scanning/exploration in amibroker. I get correct results only for few scrips which charts are open. rest of the scrips give results which does not pertain to current price/volume resulting in wrong results. any solution for getting scan results for current data for say nifty cash scrips.

47. Krishnamoorthy S says:

Dear Rajendran Sir,
I need 200 DMA crossover stocks in the latest session only. Will you please help me with amibroker code. I tried parameter n=1 and also I tried BarsSince function unsuccessfully. I need your help please.

48. vishal kapoor says:

Dear Rajandran,

Please help me code this strategy, I follow this for stock selection to trade the next day but i need to run this in the scanner so that I don’t have to manually scan all the stocks. The strategy is:

Buy when EMA 15 is above EMA 30 irrelevant of the stock price BUT the important thing here is William’s %R(3)
is below -80(oversold)

Sell when EMA 30 is above EMA 15 irrelevant of the stock price BUT the important thing here is William’s %R(3)
is below -20(overbought)

Please mail me the AFL if you can, Looking for a positive reply.

1. vishal kapoor says:

Slight typo

Sell when EMA 30 is above EMA 15 irrelevant of the stock price BUT the important thing here is William’s %R(3)
is above -20(overbought)

1. Amibroker is a perfect tool for automating your trading process. All you need know is how to play with tools like COM and OLE programming. Rest is all time effort.

49. Tony says:

Hi Rajan,

can you please help me, I need a filter for MA9 crossing above WMA45 with RSI above 50 but not greater than 70 as buy signal, and MA9 crossing below WMA45 and RSI below 40.

Hope you can help me.

Thanks A lot

50. Umesh Wakhare says:

Dear Shri Rajandran,

Can you please help me to make available the following condition AFL as well as stock scanner.

BUY = EMA 5 crossing above EMA 20 with RSI above 60 and awesome > 0
SELL = EMA 5 crossing below EMA 20 with RSI below 40 and awesome < 0

I Hope you will help me.

Thanks a lot.