A script's settings, and everything it draws — lines, levels, fills, marks, background and bar colours — with alerts.
Inputs: the script's settings
Each input.* call is a row of the study's settings card, under Inputs. The script reads what the person sets; the default is the first argument.
len = input.int(14, "Length", minval = 1, maxval = 500)
mult = input.float(2.0, "Width", step = 0.5)
src = input.source(close, "Source")
tf = input.timeframe("", "Timeframe")
show = input.bool(true, "Show the band")
lineC = input.color(color.blue, "Line colour")
mode = input.string("Fast", "Mode", options = ["Fast", "Slow"])
title names the row, tooltip adds its hover, group puts rows under one heading and inline keeps rows on one line. A number is kept to its step and its limits. input.source offers the bar's seven prices and ohlc4; a plot of another study on the chart is not a source in BENTRIX. input.timeframe offers Bentrix's interval ladder, input.symbol the markets of the workbench, input.session a session as HHMM-HHMM, and input.enum the members of an enum the script declares. See input.
01Lines and levels
p = plot(ta.rsi(close, 14), "RSI", color = color.purple, linewidth = 2)
hline(70, "Upper", color = color.gray, linestyle = hline.style_dashed)
hline(30, "Lower", color = color.gray, linestyle = hline.style_dashed)
plot draws a series as a line (or, with style, as a histogram, columns, circles, crosses, an area or steps); its colour may change from bar to bar. offset shifts it; show_last keeps only the last bars; display decides where it shows. hline draws a level fixed for the script's life.
02Fills, backgrounds and bar colours
fill(p1, p2, color = color.new(color.blue, 85))
bgcolor(ta.rsi(close, 14) > 70 ? color.new(color.red, 90) : na)
barcolor(close > open ? color.teal : color.maroon)
fill fills between two plots or two levels, with one colour or a gradient (top_value, bottom_value, top_color, bottom_color). bgcolor colours the pane's background bar by bar; barcolor colours the candles — on candles, hollow candles, OHLC, HLC and high-low bars and Heikin Ashi; on a chart type that cannot carry a bar colour, the legend says so rather than ignoring it.
03Marks
plotshape draws a shape, plotchar a character and plotarrow an arrow on each bar where its series is true (or, for an arrow, positive or negative). location places it above or below the bar, at a price, or at the pane's top or bottom; text writes beside it.
04Candles of your own
plotcandle and plotbar draw candles or bars from four series of your own — a smoothed candle, another market's candles — in the study's pane.
05Colours
color.red and the other named colours, color.rgb(r, g, b, transp), color.new(c, transp) for a transparency from 0 (opaque) to 100, and color.from_gradient between two colours. See color.
06Alerts
A script can give Bentrix's alerts something to watch:
crossUp = ta.crossover(fast, slow)
alertcondition(crossUp, "Fast crossed above slow", "Fast crossed above slow on {{ticker}}")
if crossUp
alert("Fast crossed above slow", alert.freq_once_per_bar_close)
alertcondition declares a condition an alert on the study may follow; in the alert editor it is one of the study's conditions. alert() makes the study's condition alert() call true on a closed candle that called it, and the alert's notice carries the call's message. In Bentrix both hold at a candle's close, whatever frequency the call names — an alert never fires on a value the forming candle may take back.
07Logs
log.info, log.warning and log.error write a line into the IDE's Console while the script runs there — the way to see a value on a given bar without drawing it.