Language
Strings and colours
Format numbers for labels and tables, build text, and make colours with transparency and gradients.
Strings#
Strings are text in double or single quotes. Join them with +.
str.tostring(x, format.mintick)formats a price to the symbol's precision;"#.00"gives two decimals;format.percentadds a percent sign.str.format("{0} at {1}", "RSI", r)fills placeholders.str.contains,str.replace_all,str.split,str.upper,str.lengthdo what they say.
//@version=6indicator("Price tag", overlay = true)if barstate.islast txt = str.format("{0} RSI {1}", str.tostring(close, format.mintick), str.tostring(ta.rsi(close, 14), "#.0")) label.new(bar_index, high, txt, style = label.style_label_down, color = color.new(#100e18, 0), textcolor = color.white)Colours#
- Named colours:
color.teal,color.red,color.orange,color.purple,color.grayand more. - Hex:
#8b7cff, or with transparency#8b7cff80. color.new(c, transp)sets transparency from 0 (solid) to 100 (invisible).color.rgb(r, g, b, transp)builds one from channels.color.from_gradient(value, lo, hi, loColor, hiColor)blends by where a value sits.
//@version=6indicator("Gradient RSI")r = ta.rsi(close, 14)plot(r, "RSI", color = color.from_gradient(r, 30, 70, color.red, color.teal), linewidth = 3)hline(70)hline(30)A colour can change per bar: pass a series (often a ternary) wherever a color is accepted.