Source Input

Yaser Rahmati | یاسر رحمتی

Goals

This script creates a simple indicator named "Input Source" that allows the user to select a data source (like close, open, high, low) for the indicator through a drop-down menu.

Pine Script Code

//@version=5
indicator("Input Source")

source = input.source(defval = close, title = "Select Source")

plot(source)

Code Output

Explanation

//@version=5
  • This line specifies the version of the Pine Script being used, which is version 5. Pine Script has multiple versions, and this line ensures the script is interpreted correctly by TradingView.

indicator("Input Source")
  • This line defines the indicator. The "Input Source" string is the name of the indicator that will be displayed on the chart.

source = input.source(defval = close, title = "Select Source")
  • input.source: This function creates an input option for the user, allowing them to select a data source for the indicator (such as close, open, high, low, etc.).

  • defval = close: This sets the default value of the input to the closing price of each bar.

  • title = "Select Source": This is the label that will appear in the input settings dialog, allowing the user to know what the input is for.

plot(close)

This line plots the source price of the asset on the chart. Even though the input source is defined earlier, the script is set to plot the closing price by default, regardless of the user input.

Keywords

pine script, trading view, script editor, indicators, strategies, backtesting, alerts, custom scripts, stock analysis, charting tools, technical analysis, built-in functions, pine script syntax, trading bots, automated trading, scripting language, market data, trading signals, financial markets, programming trading strategies

Visit me on:

Last updated