This last trade price marker AFL for Amibroker draws a dashed horizontal line at the last traded price (LTP) across the visible chart. It helps you see at a glance where the current market price sits relative to your support, resistance or other reference levels. Below is the original code snippet, a line-by-line explanation and the steps to use it.
Key takeaways
- The snippet plots the normal price chart plus a dashed line at the close of the last bar,
C[BarCount-1]. - The line spans only the bars visible on screen, so it stays readable when you scroll or zoom.
- Line colour and style can be changed from the Parameters window without editing code.
- It uses
LineArray(),FirstVisibleValue()andLastVisibleValue(). FirstVisibleValue() needs AmiBroker 5.40 or later.
Amibroker chart with the last trade price marker
Amibroker Chart with LTP Marker
Simple controls let you change the line colour and style. To access them, right-click on the chart and go to Parameters to change the required values.
Amibroker Parameter Control Options
Last trade price marker AFL code
//Coded by Rajandran R
//Founder of www.marketcalls.in
//Co-Founder - www.traderscafe.in
_SECTION_BEGIN("Price with LTP Line Marker");
SetChartOptions(0,chartShowArrows|chartShowDates);
_N(Title = StrFormat("{{NAME}} - {{INTERVAL}} {{DATE}} Open %g, Hi %g, Lo %g, Close %g (%.1f%%) {{VALUES}}", O, H, L, C, SelectedValue( ROC( C, 1 ) ) ));
Plot( C, "Close", ParamColor("Color", colorDefault ), styleNoTitle | ParamStyle("Style") | GetPriceStyle() );
bi= BarIndex();
sbi = FirstVisibleValue(bi);
ebi = LastVisibleValue(bi);
Plot(LineArray(sbi, C[BarCount-1], ebi, C[BarCount-1],1),"",ParamColor("LTP Color", coloryellow ), ParamStyle("LineStyle") | styleDashed | styleNoLabel | styleNoTitle);
_SECTION_END();
How the code works, line by line
- _SECTION_BEGIN / _SECTION_END: group the formula so its parameters appear under one heading, “Price with LTP Line Marker”.
- SetChartOptions(0, chartShowArrows|chartShowDates): shows trade arrows and the date axis on the pane.
- _N(Title = StrFormat(…)): builds the chart title with symbol, interval, date, OHLC values and the 1-bar percentage change,
ROC(C, 1), for the bar under the cursor. - Plot(C, “Close”, …): draws price using your chosen colour and style.
GetPriceStyle()keeps the candle or bar style set in preferences. - bi = BarIndex(): gives each bar its index number.
- sbi = FirstVisibleValue(bi) and ebi = LastVisibleValue(bi): return the index of the first and last bar visible on screen. Per the AmiBroker guide, FirstVisibleValue returns the array value at the first visible bar in charts and was added in version 5.40.
- C[BarCount-1]: the close of the latest bar, which during live trading is the LTP.
- LineArray(sbi, LTP, ebi, LTP, 1): builds a flat line from the first to the last visible bar at the LTP. The fifth argument, 1, extends the line to the right, as described in the LineArray reference.
- ParamColor(“LTP Color”, colorYellow) and ParamStyle(“LineStyle”) | styleDashed | styleNoLabel | styleNoTitle: make the marker yellow and dashed by default, and keep it out of the title and axis labels.
A note on QuickAFL
LineArray() reads x-coordinates as array positions by default. The AmiBroker guide notes that these can differ from BarIndex() values when QuickAFL is on. If the marker line ever starts at the wrong place, pass True as the sixth argument, usebarindex, so the line uses absolute bar indexes.
How to add the LTP marker to your chart
- Open a new formula in the Amibroker Formula Editor.
- Paste the code above and save it, for example as
Price-LTP-Marker.afl. - Click Apply Indicator, or drag the formula from the Charts window onto a chart pane.
- Right-click the chart, choose Parameters, and set the price colour, style, LTP colour and line style.
- Draw your support and resistance lines as usual. The dashed marker now shows how far price is from each level.
For traders: using an LTP marker
On intraday charts the marker makes it easy to read the distance between the current price and a breakout level, a stop or the prior day’s high and low. It pairs well with our prior daily OHLC AFL and the opening range breakout levels AFL. You can also add a countdown with the time left info snippet, so you know when the current candle closes.
Frequently Asked Questions
What does the last trade price marker AFL do?
It plots a dashed horizontal line at the close of the latest bar across the visible part of the Amibroker chart, so you can see the LTP against other levels.
Does the price marker update with the last trade?
Yes. With a real-time data feed, the last bar’s close changes with every tick and the line moves with it when the chart refreshes.
How do I change the colour of the LTP line?
Right-click the chart, choose Parameters and change “LTP Color” and “LineStyle”.
Which Amibroker version do I need?
FirstVisibleValue() was added in AmiBroker 5.40, so use that version or a later one.
Learn by watching: free videos every week
Market Profile, order flow, Python, AI and OpenAlgo tutorials on YouTube.

