Amibroker: How To Use Explore To Find And Filter Stocks


Beginners Course  |  Intermediate Course  |  Amibroker Course

The Explore function in Amibroker is one of the most useful, and yet many Amibroker users never get to use it.  It can find stocks that meet your criteria by doing a very simple scan, when you know how.

Using this tool can shave hours off your analysis when it finds everything you need automatically with just a little bit of Amibroker AFL language.

Using Amibroker’s Explore Function To Scan For Stocks

First, open up the Formula Editor so we can put in our AFL code:

  • Up the top bar, go to Analysis > Formula Editor
  • In the box that appears, type in this code below:
 pchng = ((C - Ref(C,-1)) / Ref(C,-1)) * 100;
 Filter = pchng;
 AddColumn(Close, "Close Price" );
 AddColumn(pchng, "Percent Change" );
  • I say type it in, because sometimes it formats wrongly from the website.  If it works using copy and paste, then great!
  • Save the file if you want to.
  • Click from the top bar: Tools > Send To Automatic Analysis
  • Now, we work from left to right.  Under “Apply To”, select either “Current Symbol” or “Use Filter”.  If you are using a filter, select the watchlist you want to scan.
  • Under “Range” select “n Last Days” and set it to 1.
  • Click the Explore button

You should see a list of your stock or stocks with the percentage change next to them!

A Closer Look At The Amibroker AFL

Just a quick look at the Amibroker AFL – we’ll go into more detail in other lessons.  The “pchng” you see first is setting up an Array, or rule for future use.  Basically, by saying “pchng =” we make those rules that follow it happen whenever Amibroker sees the word “pchng” again.  That word could be anything you like, but the rules we assign are limited to ones that Amibroker can recognize.

To do the Explore, we simply need to have the “Filter” command.  And our filter in this case, is the rule assigned to “Pchng” which gives us the percentage changes.  After that, we are just adding columns to display the data for us.

Happy trending!

– Dave McLachlan

Videos in the FREE Amibroker Course:

  1. Amibroker: How To Import A Watchlist With A CSV File
  2. Amibroker: How To Backtest A Single Stock Or Index
  3. Amibroker: How To Backtest a Portfolio or Group of Stocks
  4. Amibroker: How To Optimize A Trading System
  5. Amibroker: How To Scan The Market For Buy And Sell Signals
  6. Amibroker: How To Use Explore To Find And Filter Stocks
  7. Amibroker: How To Add Position Sizing Using AFL
  8. Amibroker: How to Add An Index Filter To Your Trading System Using AFL
  9. Amibroker: How To Plot Your Trading System On A Chart (incl. Buy/Sell Arrows)
  10. Amibroker: How to Use the If, Then Else Function (IIF)
  11. Amibroker: How to Code the ATR Trailing Stop (Chandelier) using ApplyStop
  12. Amibroker: How to Plot ApplyStop on a Chart
  13. Amibroker: How to Code Van Tharp Position Sizing (Fixed Fractional)
  14. Amibroker: How to “Scale In” to Positions (1) – Buying Once a Month
  15. Amibroker: How to “Scale In” to Positions (2) – Pyramiding Three Times
  16. Amibroker: How to Use “Cross”, When One Thing Crosses Another
  17. Amibroker Advanced: How to Compare Equity Curves

FREE Trading System Video Lessons:

  1. 7 Free Trading Systems and Their Returns From The Last 13 Years
  2. Seven Full Trading Systems Revisited, With Completely New Data
  3. Trading System: How to Create A Buy and Hold Trading System
  4. Trading System: How to Code “Sell In May And Go Away”
  5. Trading System: How to Code a Moving Average Channel That Made 23% p.a
  6. Trading System: How to Code Highest Highs As Used In 52 Week Highs Or Turtle Trading System
  7. Trading System: How to Code a Bollinger Band Breakout Trading System
  8. Trading System: How to Code a Moving Average Crossover That Returned 28% per annum
  9. Trading System: How to Refer to Previous Signals For MAup Trading System
  10. Trading System: How to Code the Leap Of Faith (Gaps) Trading System That Returned 24% p.a.
  11. Trading System: How to Code a Short Selling System (Plus Results)
  12. Trading System: Meb Faber Trading System Using Different Timeframes
  13. Trading System: How to Code the Three Billion Dollar Trading System

FREE Amibroker Q & A Videos:

June 3, 2012  Tags: , , , ,   Posted in: Amibroker, Amibroker Course, Articles On Building Wealth

12 Responses

  1. Michael - April 4, 2014

    I have a strategy & applied it on the backtest mode & explore mode, the result is difference, could you pls advise how I can do in order to make the result of explore mode same as the backtest mode? Thx!

  2. Chris - October 12, 2014

    One question:

    If at one points pchng equals 0, does that filter this particular stock out as 0 is the same as False?

  3. Dave McLachlan - December 10, 2014

    Hey Chris,

    Love the question. As for the answer: not that I’m aware. With my limited understanding, the “1 / 0, True / False” in this case is not relating to the actual percentage change of the stock (i.e. 0%, 1%, or whatever), rather the RETURNING of the percentage change. So it will return a value, no matter what that value is (from negative ones to positive ones).

    Hope that makes sense. Sorry, I am terrible at maths, so someone could probably explain it better 🙂


  4. Guwe - April 28, 2015

    Hi Dave,

    following your instructions (copying your formula in AFL editor), I will receive an Error 32. Syntax error.
    I use amibroker 5.9

    There seems to be a problem with line 1.


  5. Dave McLachlan - May 3, 2015

    Hey Guwe,

    You’ll have to type in the code manually yourself, unfortunately. Copying it from he website does funny things to the characters and it will give you that syntax error.

    Alternatively you can just delete the character it takes you to when it errors, and retype it then. It will happen on around 3 lines, mostly around the ” “s.

    The code itself is correct.

    Cheers, Dave

  6. A. Bhula - May 11, 2015

    Hi Guwe

    I’m having the same problem it’s showing syntax 32 on the first line. It’s saying Is there a semicolon missing. I typed it out 11 times already from the website even copy paste nothing working.

    pchng = ((C – Ref(C,-1)) / Ref(C,-1)) * 100;

    Filter = pchng;

    AddColumn(Close, “Close Price”);
    AddColumn(pchng, “Percent Change”);

  7. Dave McLachlan - May 16, 2015

    Ok guys.

    If it’s getting the syntax error, then you have most likely copied the text from the website, which I advised not to do.

    Either type it in from scratch, or do the following:

    When it gives you the error, it will take your cursor to the place where the error is in the code. Simply delete the symbol after your cursor and retype it. It will be the minus symbol (-), and the inverted commas (“”).

    Hope this helps – Dave

  8. A. Bhula - May 19, 2015

    Hi Dave, i did type it out 11 times and still it did not work. But I did as you instructed deleting the symbols and retyping and that worked. Thank you very for all your time and efforts.

  9. Dave McLachlan - May 19, 2015

    Ah, perfect! Glad we got it to work.

    Even better though – this is a good instruction for us for the future, if you or I get a syntax error we can look at where the cursor takes us and use that to troubleshoot.

    All the best – Dave

  10. RAVINDRA - July 9, 2015

    can some one help me to explore/scan stocks which is meeting my search<=0.
    i mean i want to search stocks with above citeria.


  11. Pat - September 13, 2015

    Hi Dave,

    Thanks for the code. I am newbie to AFL. I cannot understand the purpose for the line “Filter = pchng;”. If I delete this line. No results come up. I always think that the AFL function “Filter” is to tell AFL where the code apply to. However, in you example, it seems that “filter” serve another function.

    Can you further elaborate the line “Filter = pchng;”.

    Thanks again for the example.

  12. Dave McLachlan - September 15, 2015

    Hey Pat,

    Of course! Now – my understanding is only basic, but the way I see it is that Filter is what allows us to do the “Explore” function.

    So for an exploration, we use it instead of “Buy” and “Sell” rules, for example.

    By assigning the Array we created (pchng – we could call it anything we wanted though) to the Filter, it shows us the percent change when we click Explore.

    Hope this helps 🙂


Leave a Reply