src

Creates a dropdown input so the user can choose which price source to use (open, high, low, close, or common blends like hl2/hlc3/ohlc4). Perfect for letting users switch the data feeding your calculations without editing code.

Syntax

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

Parameters

  • title (string) · Label shown in the inputs panel (e.g., "Price Source").

  • value (SourceType) · Default option: 'open' | 'high' | 'low' | 'close' | 'hl2' | 'hlc3' | 'ohlc4'.

  • id (string) · Optional unique key for this input (defaults to a simplified version of title).

  • group (string) · Optional group name to organize inputs under a collapsible section.

  • tooltip (string) · Optional helper text shown on hover.

  • inline (string) · Optional inline group ID to place inputs on the same row.

Return Value

{ id: string } · The unique identifier you’ll use to read the selected value inside onTick.

Example

What this does: Adds a “Price Source” dropdown. On each draw cycle, it reads the choice and plots that source as a simple line.

//@version=1
init = () => {
// Show the indicator in the main panel
  indicator({ onMainPanel: true, format: 'inherit' });

  // Create a dropdown for the price source
  // Default = 'close', grouped under "Inputs", with a short tooltip.
  input.src(
    "Price Source",
    "close",                // default
    "price_source",         // id (optional but recommended)
    "Inputs",               // group (optional)
    "Choose which price feeds the plot", // tooltip
    "row1"                  // inline group (optional)
  );
};

onTick = (length, _moment, _, ta, inputs) => {

    // Read the user’s selection from inputs using the returned id
    const sel = inputs.price_source; // one of: 'open','high','low','close','hl2','hlc3','ohlc4'

    // Plot style (kept in a single const)
    const style = {
      color: color.blue
      // (plot.line also accepts plottype and id as extra args if needed)
    };

    // Build the plot using the chosen source
    plot.line("Selected Source", v, style.color);
  }
};

Tips

  • Use input.src whenever you want your indicator to adapt to different price feeds — for example, allow the user to decide if your moving average should run on close, high, or HL2 (average of high and low).

  • Combine it with other inputs like length, multiplier, or offset to make your logic more modular and reusable.

Warning

Good Practice

Last updated