🆕timeframe

Creates a timeframe (resolution) selector so users can choose which timeframe your logic should run on (for example 5m, 1h, 1D). This is essential for multi-timeframe indicators, higher-timeframe filters, or confirmation logic — without forcing users to edit code.

Syntax (one line)

input.timeframe(title, value?, id?, group?, tooltip?, inline?, includeChartOption?)

Parameters

title (string) · Label shown in the inputs panel (e.g., "Timeframe"). value (string) · Default timeframe value (must be one of the allowed aliases). id (string) · Optional unique identifier (defaults to a simplified version of title). group (string) · Optional group name to organize inputs in the UI. tooltip (string) · Optional helper text shown on hover. inline (string) · Optional inline key to place inputs on the same row. includeChartOption (boolean) · If true, adds "Chart" as an option (uses the current chart timeframe).

Allowed Timeframe Values

(case-insensitive)

  • "1m", "3m", "5m", "15m", "30m", "45m"

  • "1h", "2h", "3h", "4h"

  • "1D", "1W"

  • "Chart" (only if includeChartOption is true)

⚠️ Any value outside this list will throw an error.

Return Value

(string) · The selected timeframe value, which you can use inside onTick.

Example

What this does: Adds a timeframe selector so the user can choose whether calculations run on the current chart timeframe or a higher one (like 1H or 1D).

Result

circle-info

Tips

  • Use input.timeframe when you want to add higher-timeframe confirmation (for example: trend on 1H, entries on 5m).

  • "Chart" is ideal as a default option so the script behaves normally unless the user explicitly changes it.

  • Pair it with input.src so users can fully control what price and what timeframe drive your logic.

  • Keep timeframe inputs grouped (using group) to avoid clutter in indicators with many settings.

triangle-exclamation

Warning

circle-check

Good Practice

Last updated