Settings and Rendering
Input.* settings in the indicator window, plot lines and their styles, hline levels, fills, background and candle color, markers, labels, line segments, boxes, tables, colors and transparency. Limits: three plottable plots and 500 objects of each type.
This page covers what the user sees and can change. It describes the settings a script exposes in the indicator window, lines and their styles, levels and fills, background and candle color, markers, labels, line segments, boxes, and tables, plus colors and transparency. A section on limits worth knowing in advance is at the end.
Settings: input.*
Each input.* call becomes a row on the Inputs tab in the indicator settings window. Rows appear in the order the calls are written in the script. The first argument sets the default value, the second sets the row label.
| Call | What appears in the settings window |
|---|---|
input.int |
Field for an integer |
input.float |
Field for a decimal number |
input.bool |
Checkbox |
input.color |
Color picker |
input.string |
Dropdown list if options is set; otherwise a text field |
input.source |
Dropdown list of series: open, high, low, close, hl2, hlc3, ohlc4, hlcc4, volume |
input.enum |
Dropdown list of enum labels |
input.timeframe |
Text field; with options, a dropdown list |
input.symbol |
Text field |
The example below brings together five kinds of settings in one script:
indicator("Средняя на выбор", overlay = true)
enum Basis {
sma = "Простая"
ema = "Экспоненциальная"
wma = "Взвешенная"
}
basis = input.enum(Basis.ema, "Тип средней")
length = input.int(50, "Период", minval = 1, maxval = 500)
src = input.source(close, "Источник")
lineColor = input.color(color.orange, "Цвет линии")
showBg = input.bool(false, "Подсвечивать фон")
avg = switch basis {
Basis.sma => ta.sma(src, length)
Basis.ema => ta.ema(src, length)
=> ta.wma(src, length)
}
plot(avg, "Средняя", color = lineColor, linewidth = 2)
bgcolor(showBg and close > avg ? color.new(color.teal, 40) : na, title = "Фон")The settings window will show a dropdown list “Тип средней” with the items “Простая”, “Экспоненциальная”, and “Взвешенная”. Below it are a length field, a source list, a color picker, and a checkbox. How to declare enums is covered in Свои типы и перечисления.
Number and string parameters
minvalandmaxvalset bounds: the field will not accept a period belowminvalor abovemaxval.steponinput.floatsets how many decimal places the field shows: withstep = 0.1, one decimal is visible. The field has no arrows; the value is typed.optionsoninput.stringandinput.timeframeturns the field into a dropdown list. The default value must be one of the items, otherwise the compiler raises an error.tooltip,group, andinlineare accepted by the compiler but currently have no effect on the settings window appearance.
indicator("Цена для расчёта")
mode = input.string("Закрытие", "Считать по", options = ["Закрытие", "Середина свечи"])
price = mode == "Закрытие" ? close : hl2
plot(ta.rsi(price, 14), "RSI", color = color.purple)For input.source, the default can also be a market data series, for example delta.cum. Such a series appears as the first item in the list, before price series. If the default is an expression like (high + low) / 2, no row appears in the settings window: there is nothing to choose from.
There are currently no dedicated settings for time, trading session, or a price chosen by clicking on the chart.
Where selected values are stored
Values are remembered separately for each indicator on each chart: two copies of the same script on different panels can have different periods. The Defaults button in the settings window restores the values written in the code.
The value is tied to the variable name that stores the input.* call. The row label can be changed freely; the selected value is kept. Rows can also be reordered. But if the variable is renamed (length to period), the setting resets to the value from the code.
The settings window opens by double-clicking the indicator row in the chart legend or by clicking the settings icon in that row. Besides the Inputs tab, it has Style and Visibility — covered below.
Lines: plot
plot draws a series, one value per bar. Only the first argument — the series itself — is required. The rest of the parameters are passed by name:
title— the line name in the legend and in the settings window;color— the color, constant or calculated on each bar;linewidth— the thickness;style— the rendering style, see the table;offset— shift by a number of bars: positive to the right, negative to the left;show_last— draw only the last N bars;join = true— connect the points ofcirclesandcrossstyles with a line;editable = false— remove the line from the settings window;display = display.none— hide the line when added; it can be enabled on the Visibility tab.
| Style | Appearance |
|---|---|
plot.style_line |
Polylined line, the default style |
plot.style_linebr |
Same as line |
plot.style_stepline |
Step line |
plot.style_stepline_diamond |
Step line with diamonds |
plot.style_histogram |
Thin bars from zero, line width |
plot.style_columns |
Bars from zero, candle width |
plot.style_area |
Area filled to zero |
plot.style_areabr |
Same as area |
plot.style_circles |
Dots |
plot.style_cross |
Crosses |
The line always breaks where the series has no value (na) and does not jump over a gap with a straight segment. That is why the pairs line/linebr and area/areabr render the same.
indicator("Стили линий")
d = close - open
plot(d, "Тело свечи", style = plot.style_histogram, color = d >= 0 ? color.teal : color.red)
plot(ta.sma(d, 10), "Средняя 10", style = plot.style_stepline, color = color.orange, linewidth = 2)
plot(ta.sma(d, 30), "Средняя 30", style = plot.style_circles, color = color.gray)Color by bar
The color can be an expression: it is then recalculated on each bar. A color of na means there is no line on that bar:
indicator("Средняя только над ценой", overlay = true)
m = ta.sma(close, 50)
plot(m, "Средняя", color = close > m ? color.teal : na)What a line gets in the settings window
- On the Style tab, the thickness of each line can be adjusted. A color row appears only for a line with a constant color: if the script picks the color on each bar, there is nothing to change in the window.
- On the Visibility tab, each line has a show checkbox. It appears when there is more than one line or when the line is hidden via
display. - A line with
editable = falsegets no rows on either tab.
Levels and fills
hline draws a horizontal line at a constant price — for example, RSI zone boundaries. The price must be a number or an input.* setting: a series that changes bar by bar does not fit here. For such a line, use plot. The line style is set with hline.style_solid, hline.style_dashed, and hline.style_dotted.
fill shades the area between two boundaries. To get a boundary, save the result of hline or plot to a variable:
indicator("RSI с зонами")
length = input.int(14, "Период", minval = 1)
r = ta.rsi(close, length)
top = hline(70, "Перекупленность", color = color.gray, linestyle = hline.style_dashed)
bottom = hline(30, "Перепроданность", color = color.gray, linestyle = hline.style_dashed)
fill(top, bottom, color = color.new(color.purple, 30), title = "Зона")
plot(r, "RSI", color = r > 70 ? color.red : r < 30 ? color.teal : color.purple)Both boundaries must be of the same kind: two hline levels or two plot lines. A fill between a line and a level is not accepted by the compiler.
The fill color between two lines can change bar by bar. This is how a “cloud” of two moving averages is made:
indicator("Облако", overlay = true)
fast = ta.ema(close, 9)
slow = ta.ema(close, 21)
pf = plot(fast, "Быстрая", color = color.teal)
ps = plot(slow, "Медленная", color = color.orange)
fill(pf, ps, color = fast > slow ? color.new(color.teal, 50) : color.new(color.red, 50), title = "Облако")There is also gradient fill. Set top_value and bottom_value to indicate the heights where the color equals top_color and bottom_color; between them the color transitions smoothly. These heights must be constant numbers. If you need a fill to a constant level, make it a line, plot(50). But remember that is one of the three plotted lines.
indicator("RSI с градиентом")
r = ta.rsi(close, 14)
pr = plot(r, "RSI", color = color.purple)
pm = plot(50, "Середина", color = color.gray)
fill(pr, pm, top_value = 80, bottom_value = 50,
top_color = color.new(color.teal, 160), bottom_color = color.new(color.teal, 0))Background and candle color
bgcolor shades the background under a bar, barcolor recolors the candle itself. Both accept a color calculated on each bar; on bars with a color of na, nothing changes.
indicator("Подсветка объёма", overlay = true)
avgVol = ta.sma(volume, 20)
spike = volume > avgVol * 2
bgcolor(spike ? color.new(color.orange, 40) : na, title = "Всплеск объёма")
barcolor(close > open ? color.teal : color.red, title = "Цвет свечей")Markers: plotshape and plotchar
plotshape places an icon on bars where a condition is true. plotchar does the same with any character.
indicator("Пересечения", overlay = true)
fast = ta.ema(close, 9)
slow = ta.ema(close, 21)
plotshape(ta.crossover(fast, slow), "Вверх", style = shape.triangleup,
location = location.belowbar, color = color.teal, size = size.small)
plotshape(ta.crossunder(fast, slow), "Вниз", style = shape.triangledown,
location = location.abovebar, color = color.red, size = size.small)
plotchar(volume > ta.sma(volume, 20) * 3, "Объём", char = "●", location = location.top, color = color.orange)- Shape,
shape.*:triangleup,triangledown,arrowup,arrowdown,circle,square,diamond,cross,xcross,flag,labelup,labeldown. - Location,
location.*:abovebar— above the candle,belowbar— below the candle,topandbottom— at the top and bottom edge of the panel. In a separate panel below the chart, “above the candle” and “below the candle” also mean the top and bottom edge: such a panel has its own scale, and candle prices are not plotted on it. - Size,
size.*:auto,tiny,small,normal,large,huge. textadds a short label next to the icon. When the chart is zoomed out far and candles are narrow, labels are hidden, but icons remain.
Drawing objects
Besides series, a script can draw individual objects: labels label.new, line segments line.new, boxes box.new, and tables table.new. Each *.new call returns an object. It can be moved with set_* functions (label.set_xy, line.set_x2, box.set_top, and so on), read with get_*, copied with copy, or deleted with delete.
Horizontally, an object is bound by default to the bar number, bar_index. With the parameter xloc = xloc.bar_time, the coordinate is set by bar time. For a line segment and a box, the parameter extend (extend.right, extend.left, extend.both) extends the edge to the chart boundary.
An object stays on the chart until it is deleted. The script runs on every bar, so an unconditional label.new would create a label on every bar. To keep one object and move it, store it in a var variable and delete the old one:
indicator("Последний пивот", overlay = true, maxLabelsCount = 50)
ph = ta.pivothigh(high, 10, 10)
var line level = na
if not na(ph) {
label.new(bar_index - 10, ph, str.tostring(ph), style = label.style_label_down,
color = color.orange, textcolor = color.white, size = size.small)
line.delete(level)
level := line.new(bar_index - 10, ph, bar_index, ph, extend = extend.right,
color = color.orange, style = line.style_dashed)
}The script labels each found high and extends a dashed line to the right from the latest one. It deletes the previous dashed line.
No more than 500 live objects of each kind can exist at once. When the five hundred and first appears, the oldest one disappears. The maxLinesCount, maxLabelsCount, and maxBoxesCount parameters in indicator() lower this limit. A value above 500 is capped at 500.
Tables
A table is anchored not to bars but to a corner or edge of the panel and does not move when the chart scrolls. The position is set by position.*: top_left, top_center, top_right, middle_left, middle_center, middle_right, bottom_left, bottom_center, bottom_right. Cells are filled by table.cell. It is convenient to do this only on the last bar, to avoid rewriting the table across the entire history:
indicator("Сводка", overlay = true)
var t = table.new(position.top_right, 2, 2, bgcolor = color.new(color.black, 160))
if barstate.islast {
table.cell(t, 0, 0, "RSI", text_color = color.white)
table.cell(t, 1, 0, str.tostring(math.round(ta.rsi(close, 14), 1)), text_color = color.white)
table.cell(t, 0, 1, "ATR", text_color = color.white)
table.cell(t, 1, 1, str.tostring(math.round(ta.atr(14), 2)), text_color = color.white)
}A table has no more than 200 columns and 200 rows. A table with more than 2000 cells is not created.
Colors
Named colors: color.red, color.green, color.blue, color.teal, color.orange, color.purple, color.yellow, color.white, color.black, color.gray, color.silver, color.maroon, color.navy, color.olive, color.lime, color.aqua, color.fuchsia.
A color can also be written as a code: #FF8800 — opaque, #FF880040 — with transparency. The last pair of digits sets opacity: 00 — fully transparent, FF — solid.
color.rgb(r, g, b)builds a color from components from 0 to 255. The fourth argument is opacity, default 255.color.from_gradient(value, bottomValue, topValue, bottomColor, topColor)returns a color between the two extremes based on the position ofvaluein the range. Handy for coloring an oscillator from cool to hot.nain place of a color means “do not draw”.
indicator("RSI в цвете")
r = ta.rsi(close, 14)
heat = color.from_gradient(r, 30, 70, color.rgb(0, 150, 136), color.rgb(244, 67, 54))
plot(r, "RSI", color = heat, linewidth = 2)
bgcolor(r > 70 ? color.new(color.red, 30) : r < 30 ? color.new(color.teal, 30) : na, title = "Зоны")