Organize script inputs in sections and lines

Mar 12, 2021

Our latest Pine update introduces two improvements to inputs:

  • The new group parameter allows programmers to define a section header for a group of inputs.
  • The new inline parameter allows multiple inputs to be joined on one line. 

Using these new features you can organize inputs more neatly, as we do here for the Auto Fib Retracement indicator.

Using the new parameters in your scripts is easy! Take a look at this example of a VWAP indicator, which allows users to specify the start and end points of calculations, and control the display of anchors:

//@version=4
study(title = "Custom Period VWAP", shorttitle = "CPVWAP", overlay = true)

src = input(hlc3, "Source", input.source)
enableHighlight = input(true, "Highlight", input.bool, inline = "Highlight")
highlightType = input("Anchors", "", input.string, options = ["Anchors", "Background"], inline = "Highlight")
highlightColor = input(color.red, "", input.color, inline = "Highlight")
useStartPeriodTime = input(true, "Start", input.bool, group = "Date Range", inline = "Start Period")
startPeriodTime = input(timestamp("20 Jan 2021"), "", input.time, group = "Date Range", inline = "Start Period")
useEndPeriodTime = input(true, "End", input.bool, group = "Date Range", inline = "End Period")
endPeriodTime = input(timestamp("20 Feb 2021"), "", input.time, group = "Date Range", inline = "End Period")

start = useStartPeriodTime ? startPeriodTime >= time : false
end = useEndPeriodTime ? endPeriodTime <= time : false
calcPeriod = not start and not end

var srcVolArray = array.new_float(na)
var volArray = array.new_float(na)
var line startAnchor = line.new(na, na, na, na, xloc.bar_time, extend.both, highlightColor, width = 2)
var line endAnchor = line.new(na, na, na, na, xloc.bar_time, extend.both, highlightColor, width = 2)
useBgcolor = false

if calcPeriod
    array.push(srcVolArray, src*volume)
    array.push(volArray, volume)
else
    array.clear(srcVolArray), array.clear(volArray)

customVwap = array.sum(srcVolArray) / array.sum(volArray)
if enableHighlight
    if highlightType == "Anchors"
        if useStartPeriodTime
            line.set_xy1(startAnchor, startPeriodTime, low)
            line.set_xy2(startAnchor, startPeriodTime, high)
        if useEndPeriodTime
            line.set_xy1(endAnchor, not na(customVwap) ? time : line.get_x1(endAnchor), low)
            line.set_xy2(endAnchor, not na(customVwap) ? time : line.get_x1(endAnchor), high)
    if highlightType == "Background"
        useBgcolor :=  true

bgcolor(useBgcolor and calcPeriod ? highlightColor : na, editable = false)
plot(customVwap, title="CPVWAP", color = color.blue, linewidth = 2)

The group argument is used in two ways. The string is used as the header for the group, and it also defines which inputs belong to that group.

When an inline argument is used, all input() calls using the same inline argument will be joined on one line. The title argument of each input() call determines the field’s legend. If no title argument is used in the input() call, no legend will be used for the field. If the inputs combined using inline do not fit on one line, some of them will wrap to the next.

You can find a description of the new parameters in the Pine Reference Manual’s entry for input().

Read about all updates to Pine in our User Manual’s Release Notes.

We hope you find this much-requested feature useful. Please continue sending us your feedback for improvement. We build TradingView for our users and we love hearing from you.

Look first Then leap

TradingView is built for you, so make sure you're getting the most of our awesome features
Launch Chart