How to put a marker on a specific bar
plotshape takes a condition as its first argument and marks the bars where it
holds. To mark one bar, write a condition that is true on one bar.
plotshape(series bool series, const string title, input shape shape, input location location, series color color, input int offset, const string text, series color textcolor, input size size, const bool force_overlay) → voidindicator("Mark the last bar", "lastbar", true)
plot(close, title = "Close", color = color.gray)
plotshape(barstate.islast, title = "Last bar", shape = shape.flag, location = location.abovebar, color = color.blue, size = size.small)Choosing the condition
| To mark | Test |
|---|---|
| the first bar of the chart | barstate.isfirst |
| the last bar of the chart | barstate.islast |
| the last confirmed historical bar | barstate.islastconfirmedhistory |
| the first bar of each session | session.isfirst |
| a bar you can name by position | bar_index == 250 |
bar_index is a series int, so it changes bar by bar and a comparison
against it picks out one bar.
If you want a character rather than a shape
Use plotchar. It takes the same arguments with char in place of shape.
Pass one character: a longer string is cut to its first character, with no
warning and no error.
If the mark’s size should follow a measured value
Use plotarrow, which takes a number rather than a condition. It has no
location, no shape, no size and no text — where the arrow sits follows from the
number you give it.
If the mark should sit beside the bar rather than on it
offset shifts it. The parameter is input-form, so one fixed shift applies to
every mark; it cannot vary from bar to bar.
The failure to watch for
All three functions must be called at the top level. Two conditions mean two calls, not one call inside a branch.
See Text and markers.