DrawOnLastBarOnly
DrawOnLastBarOnly in ProBuilder is a DEFPARAM flag that limits graphical drawings to the last bar, cutting redraw cost and keeping the chart clean.
Syntax
DEFPARAM DrawOnLastBarOnly = trueParameters
| Name | Type | Default | Description |
|---|---|---|---|
DrawOnLastBarOnly | boolean | false | When true, graphical objects are drawn only on the last bar. Declared with DEFPARAM at the top of the script. |
How it works
DrawOnLastBarOnly is a DEFPARAM flag set once at the start of a ProBuilder indicator. When it is true, any DRAW command that follows draws only on the last bar of the chart, rather than repeating on every historical bar. This matters because drawing instructions run on each bar by default, so a line or label placed without the flag is redrawn thousands of times, which slows the chart and can leave overlapping objects.
It is well suited to objects that describe the current state, such as support and resistance lines, pivots or a status label. It is often paired with CalculateOnLastBars to limit calculation as well as drawing. Because the drawing happens on the last bar, coordinate lookups over history still work: the loop that finds a swing point runs on the last bar and the object is drawn there.
Examples
Example 1, A single label on the last bar (Indicator)
// Print "LastBar" once, at the current close
DEFPARAM DrawOnLastBarOnly = true
ONCE font = "Arial"
DRAWTEXT("LastBar", BarIndex, close) COLOURED(255, 0, 0)
RETURNThe text is drawn only on the current bar rather than on every bar in history.
Example 2, Recent high and low lines (Indicator)
// Draw the 15-bar high and low once
DEFPARAM DrawOnLastBarOnly = true
hh = Highest[15](high)
ll = Lowest[15](low)
DRAWHLINE(hh) COLOURED(0, 200, 0)
DRAWHLINE(ll) COLOURED(200, 0, 0)
RETURNWithout the flag these two lines would be redrawn on each bar. With it they appear once.
Example 3, A trend line built on the last bar (Indicator)
// Find two lows across 20 bars and connect them, once
DEFPARAM DrawOnLastBarOnly = true
period = 20
y2 = Lowest[period](low)
FOR i = 0 TO period DO
IF low[i] = y2 THEN
x2 = BarIndex[i]
ELSIF low[i] < y2 THEN
y1 = low[i]
x1 = BarIndex[i]
ENDIF
NEXT
DRAWLINE(x1, y1, x2, y2) COLOURED(0, 120, 255)
RETURNThe loop scans history on the last bar and the single line is drawn there.
Common errors and gotchas
- Indicator setting only.
DrawOnLastBarOnlyapplies to ProBuilder indicator drawings. It has no meaning in ProScreener, ProOrder or ProBacktest. - Declare with DEFPARAM at the top. It must be set with
DEFPARAMbefore the drawing code, not mid-script. - Affects drawings, not calculation. It limits where objects are drawn, not how much is calculated. Pair it with
CalculateOnLastBarsto also reduce calculation. - History markers disappear. With the flag on, past signals are not drawn. If you want an arrow at every past event, leave it off and gate each drawing with its own condition.
Related instructions
DRAWLINE, a drawing that benefits from being limited to the last bar.DRAWHLINE, a level line usually drawn once.DRAWVLINE, a vertical marker usually drawn once.DRAWTEXT, a label usually drawn once.CalculateOnLastBars, limits calculation to recent bars.IsLastBarUpdate, another way to run code on the last bar.ONCE, initialises a value a single time.BarIndex, supplies coordinates for the drawings.
