Pine Script v6 settings

Pine Script Inputs: Types, Groups and Recalculation

Pine Script input functions create controls in a script's Settings / Inputs tab. Use a typed input for each setting, group related controls, and keep defaults and limits constant. When a user changes a setting, Pine runs the script again across the available chart history. Most inputs return an input-qualified value; a source input returns a series float that can change on every bar.

Build a Pine Script input panel

Copy a complete input panel into Pine Editor

Add this indicator to a standard time-based chart. When prompted, click a time and price to set the anchor point. The main line uses the chart Source, Length, and Average controls. The optional upper band adds a percentage of the absolute average, so it stays at or above the line even with a negative offset. Reference symbol and timeframe affect only the Data Window reference close. Session shading and the anchor line are separate demonstrations, so changing them does not silently change the moving-average calculation.

  • Both averages execute on every bar. The enum selects the output after calculation; disabling the band also explicitly passes na to its plot.
  • An empty reference symbol or timeframe uses the chart context in request.security(). A requested open bar can change, and a lower-timeframe request provides limited intrabar information. This diagnostic is not a confirmed trading signal.
  • The session uses the exchange timezone by default and all seven days through the explicit 1234567 suffix. Test shading on an intraday chart with bars aligned to the session boundaries.
  • The anchor line starts at bars whose opening time is at or after the selected timestamp. A future anchor can leave the entire line absent. Choose a price near the chart to avoid stretching its scale.
Complete Pine v6 indicator: all 14 input functions in one panelpinescript
//@version=6
indicator("Input panel laboratory", overlay=true)

enum AverageMode
    sma = "Simple"
    ema = "Exponential"

const string CALC = "Calculation"
const string STYLE = "Appearance"
const string CONTEXT = "Reference and session"
const string ANCHOR = "Interactive anchor"

float sourceInput = input.source(close, "Source", group=CALC)
int lengthInput = input.int(3, "Length", minval=1, maxval=200, step=1, group=CALC)
AverageMode modeInput = input.enum(AverageMode.sma, "Average", group=CALC)
float offsetInput = input(0.0, "Additive offset", group=CALC, tooltip="Price units added after averaging.")
bool showBandInput = input.bool(true, "Upper band", group=CALC, inline="band")
float bandInput = input.float(10.0, "Percent", minval=0.0, maxval=100.0, step=0.5, group=CALC, inline="band", active=showBandInput)

color lineColorInput = input.color(color.blue, "Line", group=STYLE, inline="line")
int widthInput = input.int(2, "Width", options=[1, 2, 3, 4], group=STYLE, inline="line")
string labelInput = input.string("Test A", "Panel label", group=STYLE)
string notesInput = input.text_area("Record one input change at a time.", "Notes", group=STYLE, display=display.none)

string symbolInput = input.symbol("", "Reference symbol", group=CONTEXT)
string timeframeInput = input.timeframe("", "Reference timeframe", group=CONTEXT)
string sessionInput = input.session("0930-1600", "Shade session", group=CONTEXT)
bool shadeInput = input.bool(false, "Show session shading", group=CONTEXT)

int anchorTimeInput = input.time(timestamp("01 Jan 2025 00:00 +0000"), "Time", group=ANCHOR, inline="point", confirm=true)
float anchorPriceInput = input.price(100.0, "Price", group=ANCHOR, inline="point", confirm=true)

float smaValue = ta.sma(sourceInput, lengthInput)
float emaValue = ta.ema(sourceInput, lengthInput)
float average = (modeInput == AverageMode.sma ? smaValue : emaValue) + offsetInput
float upperBand = average + math.abs(average) * bandInput / 100.0
float referenceClose = request.security(symbolInput, timeframeInput, close, ignore_invalid_symbol=true)
bool inSession = not na(time(timeframe.period, sessionInput + ":1234567"))

plot(average, "Selected average", color=lineColorInput, linewidth=widthInput)
plot(showBandInput ? upperBand : na, "Upper band", color=color.orange)
plot(time >= anchorTimeInput ? anchorPriceInput : na, "Anchor price after time", color=color.gray, style=plot.style_linebr)
plot(referenceClose, "Reference close", display=display.data_window)
bgcolor(shadeInput and inSession ? color.new(color.blue, 92) : na)

var table panel = table.new(position.top_right, 1, 3)
if barstate.islast
    table.cell(panel, 0, 0, labelInput + " | " + str.tostring(modeInput), text_color=chart.fg_color, bgcolor=chart.bg_color)
    table.cell(panel, 0, 1, "Length: " + str.tostring(lengthInput) + " | Band: " + str.tostring(showBandInput), text_color=chart.fg_color, bgcolor=chart.bg_color)
    table.cell(panel, 0, 2, notesInput, text_color=chart.fg_color, bgcolor=chart.bg_color)

Choose a control by its returned type

A symbol, timeframe, or session selector returns text describing a context. It does not fetch data or filter bars by itself. The example connects these values to request.security() or time(). The generic input() infers its widget from its default; use typed numeric functions when you need bounds or a fixed options list.

FunctionReturned qualified typeControl and use in the example
input()input int / float / bool / color / string, or series float for a sourceInferred control; additive price offset
input.int()input intBounded Length; separate Width dropdown
input.float()input floatBand percentage with numeric limits
input.bool()input boolBand and session shading checkboxes
input.color()input colorMain line color picker
input.string()input stringSingle-line panel label; options can restrict choices
input.text_area()input stringMultiline notes displayed in the table
input.timeframe()input stringTimeframe used by the reference request
input.symbol()input stringSymbol identifier used by the reference request
input.source()series floatBar-by-bar price or another indicator plot
input.session()input stringSession time range used by the shading condition
input.time()input intUNIX timestamp in milliseconds for the anchor
input.price()input floatPrice coordinate for the anchor
input.enum()input AverageMode in this scriptTyped SMA or EMA member

Keep bounds, defaults, and layout labels constant

Numeric inputs have two alternative signatures: use minval, maxval, and step for a numeric field, or use options for a dropdown. Do not combine these signatures. A dropdown default must occur in its options list. step controls the increment of the arrows; use options when only a discrete set of values is valid. Bounds restrict individual fields, but relationships between fields still need explicit validation.

  • title, group, inline, options, and numeric bounds require compile-time constants. An earlier input cannot supply another input.int() default or maxval.
  • active accepts input bool, including an expression derived from inputs. A series condition such as close > open cannot control active.
  • input.source() permits a series float default and returns a series float. Declaring the receiving variable as float does not weaken that qualifier.
  • Keep input declarations at the top level. Putting an input call inside a conditional does not create a widget only when that condition is true; input registration is independent of bar-by-bar branch execution.
  • display.none hides the value from the status line and Data Window, not from Settings / Inputs. For inline controls, the last specified tooltip on the row supplies the shared tooltip.
RequirementPanel implementationFailure to avoid
Positive average lengthLength accepts 1 through 200Zero is not a valid moving-average length
Numeric percentage rangePercent accepts 0 through 100; arrows move by 0.5Treating step as a complete business validation rule
Fixed line widthsWidth options are [1, 2, 3, 4], default 2Adding minval to the same options call
Section layoutIdentical group strings produce shared headingsDifferent capitalization splits intended groups
One-row controlsIdentical inline keys put related controls togetherAssuming inline keys are visible headings or prevent wrapping
Dependent controlPercent uses active=showBandInputAssuming a disabled setting stops calculations automatically

Verify changes with a numeric example and chart checks

For a hand-checkable SMA example, assume five consecutive source values of 100, 102, 104, 106, and 108, with zero offset and a 10% band. At the fifth value, Length 3 gives (104 + 106 + 108) / 3 = 106 and an upper band of 116.6. Length 5 gives 104 and an upper band of 114.4. These are synthetic arithmetic examples, not observed market results. Use the same formula with actual chart values in the Data Window.

ChangeExpected observable resultBoundary check
Length 3 to 5, Simple modeAll available history recomputes; the synthetic last average becomes 104 instead of 106With fewer than five valid source values, SMA can be na
Length to 1, offset to 0Selected average equals the selected source wherever it existsTry both Simple and Exponential
Upper band offPercent becomes dimmed and the orange band disappearsTurn it on again; disabled editing was not a reset of the stored percentage
Percent to 0The upper band equals the averageAt 100, a positive average doubles; a negative average reaches zero
Offset 0 to 2 in the synthetic Length 3 caseAverage becomes 108 and upper band becomes 118.8The percentage applies after the offset
Change Source from close to openThe main average uses opens; the reference request still reads closeWith Length 1, compare directly to the chosen source
Change label or notesThe on-chart table shows the supplied textA notes edit also restarts execution even though the average formula is unchanged
Change reference symbol/timeframeReference close in the Data Window changes contextUnavailable data can be na; an invalid symbol is handled without halting this script

Recalculation and confirmation solve different problems

Pine establishes input values before executing the script across chart bars. An input-qualified value stays fixed during that run. Applying new settings starts a new run over the available history, rebuilding calculations, drawings, tables, and var state. This is different from a source series changing on each bar or from an indicator updating on the realtime bar.

  • confirm=true asks for configuration when adding the script. Supported ordinary controls appear in the confirmation dialog; time and price inputs support chart selection.
  • The time and price pair in the example has the same unique inline key and group, so it creates one interactive point. Its fields can also be edited in Settings.
  • confirm is not barstate.isconfirmed. It does not wait for bar close, prevent repainting, or confirm a trade.
  • Changing settings can alter historical signals and strategy results throughout the dataset. Record the settings when comparing runs.
  • Running alerts use a saved snapshot of their script and inputs. Recreate an alert when it must use changed chart settings; editing the chart instance does not update the existing alert.

Use the panel as a specification for a script revision

Give the Pine Script AI Coding Agent the full script, a list of controls with their defaults and ranges, and a result to check for each change. For this example, ask it to preserve the Length 1 source identity, the 0% band identity, and the separation between the chart source and reference request. Request a syntax check, then compare the returned script on a chart. Successful compilation cannot prove the intended calculations or widget behavior.

Where Pineify fits

Pine Script AI Coding Agent

Draft or revise a Pine Script input panel from explicit types, defaults, dependencies, and expected outputs. Review the source and syntax diagnostics, then run the chart checks for your settings.

Build a Pine Script input panel

Frequently asked questions

Educational programming example, not investment advice. Syntax validation does not verify chart interactions, data availability, or trading performance. The example places no orders.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.