Amibroker: How to Add An Index Filter To Your Trading System Using AFL

Line1

Beginners Course  |  Intermediate Course  |  Amibroker Course

Adding an Index Filter to your trading system has the power to help keep you out of bear markets or severe downward periods in the stock market, by switching off your system as a market turns down.

There are many ways to do this, but in this video we show you how to Code a Moving Average Index Filter, that helps increase our gains in a simple trading system.

How We Enter Our Code:

  • From the main screen in Amibroker, open the formula Editor by going to Analysis > Formula Editor.
  • Type in the following code:

Index = Foreign(“XAO”, “C”, True);

IndexMA = MA(Index, 100);

What This Code Means

What we are asking Amibroker to do, is to bring in a “Foreign” ticker to our trading system – the ticker we want to use as an Index Filter and its closing price.  In our case, it is the All Ordinaries in Australia.

We have set it up as an object, or an “Array”, Index, that we can reference back to later in the code.  And we do – we use it next in the Moving Average we set up, by calling on a Moving Average of our array, Index.

Obviously you can use this any way you like – it doesn’t have to be with a Moving Average.  Test it out for yourself.

I hope this helps, happy trending and enjoy!

Dave McLachlan

Beginners Course  |  Intermediate Course  |  Amibroker Course Home

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:

  1. Amibroker Q & A: How To Do A Monte Carlo Test? (on ALL versions)
  2. Amibroker Q & A: Visualising Monte Carlo Data with Histograms and Scatter Plots
  3. Amibroker Q & A: How to Create the 52 Week High/Low Index with AddToComposite
  4. Amibroker Q & A: How to Code Trend Pilot: Five Consecutive Days Above or Below a Moving Average
  5. Amibroker Q & A: Three “Hacks” To Improve Your Coding Skills
  6. Amibroker Q & A: How to Remove Excess Signals

Read Related Articles:




  And, subscribe for free to stay in touch and receive the latest updates:

Enter Your Email Address:

.
(Check Your Junk Mail, Just In Case)

June 10, 2013  Tags: , , , ,   Posted in: Amibroker, Amibroker Course

4 Responses

  1. Nick M - August 18, 2015

    Hey Dave,

    Do you guys have interactivebrokers down under?
    They have a tool that works with amibroker to autotrade –
    have you worked with something like this before? I’m having some trouble getting mine setup

  2. Dave McLachlan - August 20, 2015

    Hey Nick,

    Unfortunately not! I am still going old school – manual trade entries 🙂

    Try the Yahoo Amibroker group maybe? And/or Aussie Stock Forums has a great Amibroker thread, with an excellent group of people.

    Cheers – Dave

  3. Markus - November 1, 2015

    Hi Dave,
    how would you code a volume filter instead of an index filter. Let’s say only those stocks can get a buy signal which average volume of the last 50 days is greater than x? I am new to Amibroker and struggling a bit.

  4. Michael - March 2, 2017

    Hi Dave,

    Thanks for you website….so unbelievably helpful.

    Is it possible to tighten a stop loss when the index filter says stop trading? For example, if price goes below xx MA then move stop to within 5% of recent high?

    I appreciate any help you can give.

    Many thanks,
    Mick

Leave a Reply