Rajandran R Creator of OpenAlgo Sketchmaker, RagZ. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Now the recent curiosity on building Trading AI Agents.

Code Snippet: Price with Last Trade Price Marker in Amibroker AFL

2 min read

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() and LastVisibleValue(). FirstVisibleValue() needs AmiBroker 5.40 or later.

Amibroker chart with the last trade price marker

Amibroker Chart with LTP Marker
Amibroker last trade price marker at LTP

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.

OpenAlgo: one API for 35+ Indian brokers

FREE AND OPEN SOURCE

OpenAlgo: one API for 35+ Indian brokers

Self-hosted algo trading platform. Send orders from Python, AmiBroker, TradingView, Excel or a no-code flow through one consistent API.

  • Unified REST and WebSocket API
  • Works with AmiBroker, TradingView, ChartInk and Excel
  • Sandbox mode to test before going live
Get OpenAlgo →by Marketcalls

Amibroker Parameter Control Options
Line Style

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

  1. Open a new formula in the Amibroker Formula Editor.
  2. Paste the code above and save it, for example as Price-LTP-Marker.afl.
  3. Click Apply Indicator, or drag the formula from the Charts window onto a chart pane.
  4. Right-click the chart, choose Parameters, and set the price colour, style, LTP colour and line style.
  5. 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.

Marketcalls Elite Traders Club

MEMBERSHIP

Marketcalls Elite Traders Club

Every Marketcalls course and live mentorship in one membership: 127 courses and 2,500+ hours of learning.

  • Market Profile, Orderflow, AFL, Pine Script and Python
  • Live mentorship and TradEdge trading room
  • Premium tools and the Elite Slack community

Learn by watching: free videos every week

Market Profile, order flow, Python, AI and OpenAlgo tutorials on YouTube.

Rajandran R Creator of OpenAlgo Sketchmaker, RagZ. Building GenAI Applications. Telecom Engineer turned Full-time Derivative Trader. Mostly Trading Nifty, Banknifty, High Liquid Stock Derivatives. Trading the Markets Since 2006 onwards. Using Market Profile and Orderflow for more than a decade. Designed and published 100+ open source trading systems on various trading tools. Now the recent curiosity on building Trading AI Agents.

Leave a Reply

Get Notifications, Alerts on Market Updates, Trading Tools, Automation & More