Mentis course
Lesson 7. Inputs
25 min, intermediate level
Make your script tunable with input.*. Each call adds a control to the settings dialog.
//@zscript 1
indicator("Tunable average", overlay=true)
len = input.int(20, "Length", minval=2, maxval=500)
src = input.source(close, "Source")
plot(ta.sma(src, len))
Give each input a plain title and a sensible default, set a min and max so nobody can type 0 as a length, and use group= to keep long lists tidy.
Exercises
- Three inputs. Add a length, a color and a show-labels switch to one of your scripts.
- Pick list. Use input.string with options to let the user choose between SMA and EMA, then switch on it.
Quick quiz
Why set minval?
Limits keep the settings sensible.
Which input gives a color picker?
input.color.
Education only. Not financial advice. Examples are teaching samples, not trading results.
