StructureX

Home › Guides › Platforms

Pine Script inputs: turn any number into a setting

Every number in a script is a guess until you test it. Inputs turn those numbers into settings, so you can try 20, then 50, without touching the code.

Beginner guide · 8-minute read · Updated 2026-10-21

What an input is

An input is a setting. It shows up when you click the gear icon next to your script's name on the chart, under Inputs.

Without inputs, changing a number means opening the code, editing it and saving. With inputs, you just type a new value in the settings box. The chart updates right away.

It also makes your script easy to share. Someone else can change the settings without reading a line of code.

New to Pine Script? Start with Pine Script for beginners. This page picks up from there.

The basic pattern

Every input follows the same shape:

length = input.int(20, "Length")

In plain words:

The 6 input types you'll use most

Pine Script version 6 has a different input for each kind of value:

InputWhat it holdsExample use
input.intA whole numberHow many candles to average
input.floatA number with decimals1.5 times the average range
input.boolOn or off (a tick box)Show or hide a line
input.sourceA price to useClose, open, high or low
input.stringA choice from a list"SMA" or "EMA"
input.colorA color pickerThe line's color

There are others, like input.timeframe for picking a chart timeframe. That one gets its own page: Pine Script request.security.

A full example with every type

Here's a whole indicator. It draws a Moving average (the average price of the last few candles) with 5 settings:

//@version=6
indicator("Average with settings", overlay=true)
src = input.source(close, "Price", group="Average")
length = input.int(20, "Length", minval=1, maxval=500, group="Average", tooltip="How many candles to average")
maType = input.string("SMA", "Type", options=["SMA", "EMA"], group="Average")
showLine = input.bool(true, "Show the line", group="Look")
lineColor = input.color(color.orange, "Color", group="Look")
smaLine = ta.sma(src, length)
emaLine = ta.ema(src, length)
avg = maType == "SMA" ? smaLine : emaLine
plot(showLine ? avg : na, "Average", color=lineColor)

Line by line:

group puts settings under a small heading. Here, "Average" and "Look" become 2 neat sections.

Why lines 8 and 9 work out both averages

You might wonder why we don't only work out the one we need.

Functions like ta.sma and ta.ema keep a memory of past candles. If they only run on some candles, that memory has gaps, and the numbers can come out wrong. Pine Script warns you about this.

The safe habit: work out these values on every candle, then choose between them.

input.float: a setting with decimals

Use it when a whole number isn't enough:

mult = input.float(1.5, "Range multiplier", minval=0.1, step=0.1)

More useful extras

These work on most input types:

How to use inputs to test, not to tune

Here's the catch. Inputs make it easy to try 50 settings until the past looks perfect. That feels like progress. It usually isn't.

A setting picked because it fit the past is called overfitting. It's tuned to old candles that will never repeat exactly.

A better habit:

  1. Pick a setting for a reason you can say in one sentence. For example: "20 candles is about one month of trading days."
  2. Test it on past charts with bar replay, one candle at a time.
  3. Log what you see in a trading journal.
  4. Only change the setting if you can say why, then test again.

A better number won't fix a missing plan. No setting tells you where your stop goes or how big to trade. That comes from your rules, not your inputs.

Try it today

  1. Paste the full example into the Pine Editor, on a computer.
  2. Save it and add it to a chart.
  3. Click the gear icon. Find the 2 groups, "Average" and "Look".
  4. Switch Type from SMA to EMA. Watch the line react faster.
  5. Hover over the "i" next to Length. That's your tooltip.

Learning from a real script

Inputs are how a finished indicator stays flexible. Studying one shows you how many settings are useful, and how many are too many.

Our course includes the full source code of the StructureX chart tool, to learn from and customize, settings and all. It's source code, not a ready-made trading bot.

Fewer settings, clearer chart. If a setting has never changed your decision, think about removing it.

Common mistakes

Questions

How do I add a setting to a Pine Script indicator?

Replace the number with an input, like length = input.int(20, "Length"), then use length in the code. It appears under Inputs in the script's settings.

What is the difference between input.int and input.float?

input.int holds whole numbers like 20. input.float holds numbers with decimals like 1.5.

How do I make a drop-down menu in Pine Script?

Use input.string with an options list, for example input.string("SMA", "Type", options=["SMA", "EMA"]).

How do I group inputs in Pine Script?

Add group="Name" to each input. Inputs with the same group name appear together under that heading.

Want the next step? We'll walk you through it.

Four free lessons by email, one every few days — each with a 10-minute exercise on a real chart.

Send Me the Free Lessons 4 short emails · No spam · Unsubscribe anytime

Or see the whole method, step by step:

See What’s Inside the Course Try everything free first. Decide when you're ready. · Open the free chart tool (works in the TradingView phone app)

One chart idea a day, in plain English. Follow along:

Follow on XFollow on TradingView