session

Adds a session input to your indicator’s Inputs panel. A session is typically a time range like "0930-1600" that represents when markets or strategies are active. You can also provide options to let users pick from predefined sessions.

Syntax

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

Parameters

  • title string — Label shown in the Inputs panel.

  • value string — Default session string (e.g., "0930-1600").

  • id string (optional) — Unique key for referencing this input. If omitted, it is auto-generated from title (lowercased, spaces removed).

  • options string[] (optional) — Provides a dropdown menu of predefined sessions (e.g., ["0930-1600", "0800-1200"]).

  • tooltip string (optional) — Small text shown on hover.

  • group string (optional) — Groups this input under a collapsible panel.

  • inline string (optional) — Aligns multiple inputs in the same row if they share the same key.

Return Value

{ id: string } — The assigned id, either provided or auto-generated.

Example

//@version=1S

// This is the setup function.
// Here you can define the input parameters for the indicator.
init = () => {
  // Example: Market session input
  input.session(
    'Trading Session',
    '0930-1600',
    undefined,                      // auto id: "tradingsession"
    ['0930-1600', '0800-1200'],     // dropdown options
    'Choose the active trading hours',
    'Sessions',
    'session-row'
  );
}

// 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) => {

};

Result

Tips

  • Use options if your strategy only supports specific session windows.

  • Keep session strings consistent (always in "HHMM-HHMM" format).

Warning

Good Practice

Last updated