βœ–

Home Forums Trading view How can I create user input boxes in Pine Script?

How can I create user input boxes in Pine Script?

  • Author
    Posts
    • 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?

    • 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.

Viewing 1 reply thread
×

Start a Discussion

Get help from the AlgoDelta community.

×

Welcome Back!

Enter your email to sign in or create an account. No passwords needed.

⚠️

Delete This?

Are you sure you want to delete this? This action is permanent and cannot be undone.

Scroll to Top