Amibroker: How to “Scale In” to Positions (2) – Pyramiding Three Times

Line1

Beginners Course  |  Intermediate Course  |  Amibroker Course Home

This is the second video on “Scaling In” to positions using Amibroker Formula Language.  It will give you more tools to use in your own back testing!

Now that we have the basics down, this video will look at how to “pyramid”.  Traditionally, the term “Pyramiding” is used because we are reducing the amount we buy each time.  In other words, we might first buy 1000 shares, then 500, then 250, for example.

This example scales in, or pyramids into positions as long as price is above our Moving Average. As you can imagine, we could end up with LOTS of positions if it’s above the Moving Average for quite some time.  To limit positions I show you how to add a Counter, and we count three positions and then stop buying.

I also show you how to change your position size – reduce the amount we are buying – each time and with each successive pyramid. The idea behind that is we are adding to positions, but not TOO much, as the trend ages and becomes likely to reverse.

Check it out!

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

February 7, 2016  Tags: , , , , , ,   Posted in: Amibroker Course

4 Responses

  1. Neha Lele - March 1, 2016

    Hi Dave,

    How are you? Hope your equity is only rising higher!

    For this video you used:
    X = Sum(BuySig1, BarsSince(SellSig1));
    XSigs = X <=3;
    FirstTrade = X <= 1;

    Here X as an array is created where all the buy signals are summed up. So the array will first hold zeros(where buy signal IS NOT generated) and ones(where buy signal IS generated) and then sum it up. Now, when ever the first buy signal will be generated, we will have a 'one'(because less than one i.e zero would mean no signal).

    Thus, first trade == 1 should be the code according to me.

    I backtested using your code (FirstTrade = X <= 1) and my code(First trade == 1) and got different results. Can you please explain what wrong am I doing in my thinking and decoding?

    Thanks and regards,
    Neha

  2. David McLachlan - March 1, 2016

    Hey Neha,

    Thanks for the comment! Great comment, too. I don’t think you’ve done anything wrong at all. It is more likely to be my error. But I will have to have a look into it, because I’m not too quick at this 🙂

    I’ll figure it out and let you know!

    Happy trending – Dave

  3. Neha - March 2, 2016

    Dave,

    I am really a big fan of your modesty. Hope god blesses me too with this virtue of being so grounded.

    Stay Blessed,
    Neha

  4. A.v.satyanarayan a - September 7, 2017

    Mcx chart I need

Leave a Reply