🎛️Script Inputs

Inputs are controls that let users configure parameters of your indicator or strategy. For example: a period for a moving average, a color for a line, or a switch to enable/disable a feature.

Important:

  • All inputs must be declared only inside the init control block.

  • Always start with input. followed by the method you want to use (e.g., input.int, input.bool, input.color).

Inputs API

File: inputs‑indicator.api.ts Provides UI controls so users can configure parameters.

Method
Signature (simplified)
Returns
Notes

int(title, value, id?, min?, max?, step?, tooltip?, group?, inline?)

number

Integer input

float(title, value, id?, min?, max?, step?, tooltip?, group?, inline?)

number

Decimal input

bool(title, value, id?, tooltip?,

group?, inline?

boolean

Checkbox

color(title, value, id?, group?, tooltip?, inline?)

string

Color picker

str(title, value, id?, options?, tooltip?, group?, inline?)

string

Single‑line text

session(title, value, id?, options?, tooltip?, group?, inline?)

string

TradingView session

textarea(title, value, id?, tooltip?, group?, inline?)

string

Multi‑line text

time(title, value, id?, min, max, tooltip?, group?, inline?)

number

Time of day (ms)

src(title,value,id?, group?,tooltip?,

inline?)

number

Source Input

Example

//@version=1
// This is a template for a custom indicator. You can use this as a starting 
// point to create your own custom indicator.

// This is the setup function.
// Here you can define the input parameters for the indicator.
init = () => {
  input.bool('show draws', true, 'show');
  input.bool('extend fvg', true, 'extend');
  input.int(
    'SMA Length',
    14,
    undefined,       // auto id: "smalength"
    1,               // min
    200,             // max
    1,               // step
    'Number of bars used to calculate SMA',
    'Moving Averages',
    'ma-row'
  );
  input.float(
    'ATR Multiplier',
    1.5,
    undefined,         // auto id: "atrmultiplier"
    0.1,               // min
    10,                // max
    0.1,               // step
    'Factor applied to ATR for stop calculation',
    'Risk Management',
    'risk-row'
  );

  // Example: Notes field
  input.textarea(
    'Strategy Notes',
    'Enter your notes here...',
    undefined,
    'Add optional comments or explanations',
    'General Settings'
  );

  // Example: List of symbols
  input.textarea(
    'Watchlist Symbols',
    'AAPL, MSFT, TSLA',
    undefined,
    'Comma-separated list of tickers',
    'Symbols'
  );

  input.time(
    'Session Start',
    930,          // default: 9:30
    undefined,    // auto id: "sessionstart"
    0,            // min (0 = 00:00)
    2359,         // max (2359 = 23:59)
    'Time when trading session begins',
    'Sessions',
    'session-row'
  );

  // Example: Trading session end time
  input.time(
    'Session End',
    1600,         // default: 16:00
    undefined,
    0,
    2359,
    'Time when trading session ends',
    'Sessions',
    'session-row'
  );

  input.session(
    'Trading Session',
    '0930-1600',
    undefined,                      // auto id: "tradingsession"
    ['0930-1600', '0800-1200'],     // dropdown options
    'Choose the active trading hours',
    'Sessions',
    'session-row'
  );
  
    input.color(
      'Line Color',
      color.blue,  // default color
      undefined,
      'Styles',
      'Choose the line color'
    );

  // Example: Pick a custom RGBA color
  input.color(
    'Background',
    { r: 255, g: 200, b: 50, a: 0.5 }, // semi-transparent orange
    undefined,
    'Styles',
    'Background color with transparency'
  );
}

// This is the main function. It is called every time a new candle is received.
// Here you can calculate the indicator values and draw the indicator on the chart.
onTick = (length, _moment, _, ta, inputs) => {

};

Warning

✅ Good Practice

Last updated