Pine Script Several new features added to the Pine scripting language

A new “barstate.isconfirmed” variable has been added to the list of variables that return bar status (barstate.isrealtime, barstate.ishistory, barstate.islast etc.). It lets you create indicators that are calculated based on the closed (or updatable) bars only. “Barstate.isconfirmed” value is false when the bar is being updated in real-time except for the last update for the bar.

//@version=3
study("Price prediction, barstate.isconfirmed sample")
prediction = not barstate.isconfirmed ? 2 * close - close[1] : na
plot(close)
plot(prediction, style=cross, linewidth=3, offset=1)

chrome_2017-04-25_17-02-35


We’ve added an “options” argument for the “input” function. You’ve probably noticed that some built-in indicators have a setting that lets you choose several options. You can do the same in Pine Script now.

//@version=3
study(title="Average True Range, input with options sample", shorttitle="ATR", overlay=false)
length = input(14, minval=1)
smoothing = input(defval="RMA", options=["RMA", "SMA", "EMA", "WMA"])

ma(smoothing, src, length) => 
    if smoothing == "RMA"
        rma(src, length)
    else
        if smoothing == "SMA"
            sma(src, length)
        else 
            if smoothing == "EMA"
                ema(src, length)
            else 
                if smoothing == "WMA"
                    wma(src, length)
                else
                    src

plot(ma(smoothing, tr(true), length), color=red)

chrome_2017-04-25_18-42-36

Upcoming updates will significantly expand the possibility of using variables in functions (including the input function). The following call will be available among other features.

opt1 = "option1", opt2 = "option2"
i = input(opt1, options=[opt1, opt2])
if i == opt1
    <...>
April 26, 2017
spread the love