Amibroker: How to Plot ApplyStop on a Chart


Beginners Course  |  Intermediate Course  |  Amibroker Course Home

We recently looked at the ATR Trailing Stop Loss and how to code it in Amibroker, as used by thousands of traders over a number of decades.

More often than not, we want to actually see our stop loss on the chart, so we know if we have coded it correctly and if it is having the impact we want it to on our trading system.  Plotting part of our trading system on a chart can also help us “debug” it, if it’s not acting correctly or doing what we want, we can see it straight away.

Normally, Plotting a line on a chart would be a fairly easy process.  However if we want to show our stop loss correctly, we have to take things up a notch and add some new pieces of code so that we:

  • Only show the stop loss when we are in a trade
  • Ensure it reflects our exact buy and sell signals

That’s where this video comes in.  Check it out, to learn how to Plot any ApplyStop function in the future!

I hope you enjoy, and please leave a comment below 🙂

The first part of our code is:

  • Equity( 1, 0 );

Which evaluates the stops, over all quotes.  Next we need to tell Amibroker when we are in a trade, using our “light switch”, the Flip() function.  This function is really cool.

  • InTrade = Flip( Buy, Sell );

From there we need only three things:  To check that there are no “Null” bars (this would throw off our stop loss), set up the Array that we will use to plot our stop loss line, and the use Plot() to plot that array on the chart along with PlotShapes to show our buy and sell arrows.

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 10, 2016  Tags: , , , , ,   Posted in: Amibroker Course

6 Responses

  1. Neha Lele - February 9, 2016

    Hi Dave,

    You recommend the use of the function Equity to plot ApplyStop. However the description page of the function says:
    This function is left here for backward compatibility and is using old, single-security backtester. New coding should rather use portfolio-level equity (special ~~~EQUITY ticker).

    Would you like to comment please. What should be the updated way of doing the same?


  2. David McLachlan - February 10, 2016

    Hey Neha,

    Wow, good question. I checked it out. Looks like the Equity() function is called the “older” one, but still used for individual stocks (such as plotting a single stock’s stop loss).

    The other “new” method is using the ~~~EQUITY symbol (you can search for it in your ticker window). This symbol generates afresh every time you do a back-test, and shows you your Portfolio Equity (including the effect of multiple positions, position sizing, missed trades, etc).

    You can actually calculate Portfolio level equity using the “old” Equity(), if anyone ever wanted to – Herman Van Den Bergen gave some code for this at-

    Thanks for the question! That helped me too.

    Happy trending,


  3. Neha Lele - February 10, 2016


    Thank you once again. Seems like just for plotting ApplyStop purpose, the Equity() seems to be doing fine. Thanks once again.

    Happy Trending to you too 🙂


  4. David McLachlan - February 11, 2016

    No problems 🙂 I should also say – if anyone knows better, please feel free to post!

    I have no problems being corrected, because it means we all get the right info 🙂 But it seems to work well.

  5. Sarids - June 13, 2016

    Hi Dave,
    Your website is very easy to learn for new Amibroker user. I have a few problem with coding. Do you have email address to contact ? It would be appreciated if you can help me and I think some people may have the same problem.


  6. DCGSyd - March 27, 2017

    Hi Dave, Thanks for the great explanation & videos. Is it possible to output the value of the Chandelier stop to an exploration/scan each day in order to take the value of the stops for all relevant stocks that may be in trade each day and amend them with the broker as distinct from reading each one from the chart plotted?

Leave a Reply