October 20, 2021

Pine Scripts Are Now Interactive

A new interactive input mode for price and time inputs is now available. Instead of selecting price and time from input widgets, you can now select them by clicking on the chart. The interactive mode is activated by using confirm = true in input.time() and input.price().

This is code for an Anchored VWAP indicator where the anchor point is set interactively, just as with the drawing tool of the same name: 

//@version=5
indicator("Anchored VWAP", overlay=true)
src = input.source(hlc3, "Source")
startCalculationDate = input.time(timestamp("20 Jan 2021"), "Start Calculation", confirm=true)
vwap_calc() =>
    var srcVolArray = array.new_float(na)
    var volArray = array.new_float(na)
    if startCalculationDate <= time
        array.push(srcVolArray, src*volume)
        array.push(volArray, volume)
    else
        array.clear(srcVolArray), array.clear(volArray)
    array.sum(srcVolArray)/array.sum(volArray)
anchoredVwap = vwap_calc()
plot(anchoredVwap, "VWAP", linewidth=3)

When it is necessary to select both a price and time simultaneously, use an inline parameter with the same value in both function calls:

//@version=5
indicator("Point", overlay=true)
myPrice = input.price(100, inline="Point", confirm=true)
myTime = input.time(timestamp("2020-02-20"), inline="Point", confirm=true)
lblText = str.format("Price: {0, number}\nTime: {1, date} {1, time}", myPrice, myTime)
var l1 = label.new(myTime, myPrice, lblText, xloc=xloc.bar_time)

Reminders appear on the chart to guide users when they are in interactive input mode: 

After adding an indicator and making an initial interactive selection on the chart, you can modify the selection points by selecting the indicator and moving the points on the chart.

You can see the new feature in action in these publications:

CAGR by TradingView

AutoTrail by Bjorgum

To stay informed of new Pine features, keep an eye on our Pine User Manual’s Release notes. The PineCoders account also broadcasts updates from its Squawk Box Telegram channel, Twitter account, and from the Pine Script public chat on TradingView.

We hope you find this highly-requested feature useful. Please keep giving us your feedback and suggestions for improvement — we build TradingView for you, and we’re always keen to hear from you.

Look first / Then leap

Launch Chart