How can I create user input boxes in Pine Script?

Asked by Radhesh Joshi · SOLVED
1 reply 333 views Jump to solution Reply
Radhesh Joshi Original Post
Strategy Builder

I’m creating my own TradingView indicator in Pine Script, but currently all the values like EMA length, RSI period, colors, and other settings are hardcoded.

I want users to be able to change these values directly from the indicator settings without editing the code every time.

Is there any way to create input boxes, dropdowns, checkboxes, or color pickers in Pine Script?

Posted Aug 5
Reply

    1 Reply

    Tech Support AlgoDelta
    Tech Support AlgoDelta Automation Expert ·

    Yes sir, Pine Script provides built-in input() functions that allow you to create configurable settings for your indicator.

    Instead of hardcoding values, you can let users modify them directly from the indicator’s Settings window.

    For example, to create an integer input:

    //@version=6
    indicator("Input Example", overlay=true)
    
    emaLength = input.int(20, "EMA Length")
    
    emaValue = ta.ema(close, emaLength)
    
    plot(emaValue)

    Now, when you add the indicator to the chart, users can open the indicator settings and change the EMA Length without modifying the code.

    You can also create different types of inputs depending on your requirements.

    -Integer Input

    length = input.int(20, "Length")

    -Float Input

    multiplier = input.float(2.5, "Multiplier")

    -Boolean (Checkbox)

    showEMA = input.bool(true, "Show EMA")

    -String Dropdown

    maType = input.string(
        "EMA",
        "Moving Average",
        options = ["EMA", "SMA", "WMA"]
    )

    -Color Picker

    lineColor = input.color(color.blue, "Line Color")

    -Timeframe Selector

    higherTF = input.timeframe("60", "Higher Timeframe")

    -Price Source

    priceSource = input.source(close, "Price Source")

    Once these inputs are created, users can change them anytime by opening:

    -Indicator Settings
    -> Inputs

    There is no need to edit or save the Pine Script again.

    Using inputs is considered a best practice because it makes your indicator reusable and user-friendly. Instead of creating multiple versions of the same indicator with different values, you can create one configurable indicator that users can customize according to their trading style.

    Verified Solution
      Markdown supported · ```json for code blocks · paste or drop screenshots

      Be specific and kind. Never share API keys, passwords or personal account details.

      Welcome to the community

      Log in or create your account in under a minute.

      1. 1Mobile
      2. 2E-mail
      3. 3Password
      +91

      Have a password?

      By continuing you agree to the community guidelines. We’ll send a one-time code by SMS.