Amibroker Q & A: Three “Hacks” To Improve Your Coding Skills


Beginners Course  |  Intermediate Course  |  Amibroker Course Home

Last week I posted an article on how to code five consecutive bars above or below a Moving Average, similar to the way the Trend Pilot trading system is used.

Well, when I figured out how to do it, I figured it out the LONG way.

Two great viewers at my site graciously pointed out a total of three easier ways to code it!  Of course I checked them out myself, and even though it took me a while to understand them, when I finally did I realised how powerful these three faster methods were.

They helped me with my coding – thinking of better ways to code things – and I know they can help you too.

A big thanks to Gordon, and Maurice, and the great Cezar Alvarez, who Maurice credited.

It’s great readers and viewers that help make great things happen.  Thank you so much guys!

3Hacks_1 3Hacks_2

Hope you enjoyed, and happy trending!

– 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

January 31, 2016  Tags: , , , , ,   Posted in: Amibroker Q & A

5 Responses

  1. Neha - March 1, 2016

    Hi Dave,

    Hope you are trending high as always! One observation here, the four BuySigs that you have shown to us have three of them (1, 2 and 3) doing exactly the same job and one of them (4) slightly differs. The first three would require all the 5 consecutive bars’ closes to be above the MA whereas the fourth one requires only the 5th bar’s close to be above the MA. Think about it.

    Thanks & Regards,

  2. David McLachlan - March 1, 2016

    Hey Neha,

    Thanks for your comment!

    You know, at first I thought that as well, and I spoke about the process a bit in the video. I thought “using C > MA, only the last one would need to be above the MA”.

    But when I looked at it, every time the Cross function occurs – closing above the MA – it RESETS. So if it Crosses above, then below, then above again, our BarsSince() == 4 will only reach 4 if it hasn’t closed below the MA again, and has closed above it 4 times!

    Then of course, the last day (5) needs to be above the MA as well, so we use that “C > MA” to make it so.

    Now, I could be wrong. But that’s how it looks to me. Try plotting it on a chart too – you’ll see that it is the same 🙂

    Happy trending – Dave

  3. Neha - March 2, 2016


    YOU ARE ABSOLUTELY CORRECT! I am extremely sorry to have bothered you and taken your time on this one. Thanks for the detailed explanation, really helped as always.


  4. David McLachlan - March 4, 2016

    Hey Neha,

    My pleasure. I wish I could take credit for that one! I’m blessed to have such good readers and viewers – and Maurice and Gordon are the real heroes here.

    Happy trending – Dave

  5. harry - January 28, 2017

    Can you please share the AFL for this as I screwed up mine in process to write / correct my previous code.

    Thanks in advance.

Leave a Reply