Putting output on the chart
A script draws by calling output functions. Each call adds one thing to the chart.
| Call | What it does |
|---|---|
plot(series, title, color, linewidth, style, histbase, offset, display) | Styles: line, stepline, histogram, columns, circles, cross, area, linebr, areabr. color can change per bar. display = display.none hides it, and fill can still use it. |
hline(price, title, color, linestyle, linewidth) | A horizontal level. |
fill(plot1, plot2, color) | Shades between two plots, or a plot and an hline. |
bgcolor(color) | Stripes behind the candles. |
barcolor(color) | Recolours the candle (body, border and wick) on that bar. na leaves it alone. When several scripts colour the same bar, the later one wins. |
plotshape(cond, title, style, location, color, text, size), plotchar | Markers above or below candles. |
plotarrow(series, colorup, colordown) | An up arrow under the bar where the series is above 0, a down arrow over it where below 0. The arrow size does not scale with the value. |
plotcandle(open, high, low, close, title, color, wickcolor, bordercolor), plotbar(...) | A candle or OHLC-bar series of the script's own, on the price chart (overlay = true) or in its own pane. A bar with any na price is skipped. |
indicator(title, shorttitle, overlay) | overlay = true draws on the price chart. Otherwise the script gets a pane of its own. |
A script with indicator(overlay = false) and no plot has nothing to put in a pane, so its markers and stripes go on the price chart.
Colouring by condition
//@version=5
indicator("Inside Bar", overlay = true)
inside = high < high[1] and low > low[1]
bgcolor(inside ? color.new(color.yellow, 80) : na)
plotshape(inside, "Inside bar", shape.circle, location.abovebar, color.yellow, size = size.tiny)
Pass na to a colour argument to draw nothing on that bar. color.new(color, 80) makes a colour 80% transparent.
Your own candles
//@version=5
indicator("Heikin Ashi")
haClose = (open + high + low + close) / 4
var haOpen = na
haOpen := na(haOpen[1]) ? (open + close) / 2 : (haOpen[1] + haClose[1]) / 2
haHigh = math.max(high, math.max(haOpen, haClose))
haLow = math.min(low, math.min(haOpen, haClose))
plotcandle(haOpen, haHigh, haLow, haClose, "Heikin Ashi", color = haClose >= haOpen ? color.teal : color.red)