Inputs in Pine Script make it possible for traders to change the values that the script uses in its calculation logic. TradingView provided specific widgets for price and other types of input. Recently (late 2021), TradingView introduced a new interactive mode for time and price inputs that allows users to simply modify inputs by clicking on the chart.
This quick guide demonstrates how to set price input interactively from a chart in Pine Script.
Price Input in Pine Script
You may sometimes need to input price as a parameter to your indicator or strategies. Perhaps a good example is ‘entry prices’ for a custom trade to compute stop loss or profit target for it.
We typically use the usual input.float to input the price.
//@version=5 indicator("My script", overlay = true) p = input.float(40000, title = "Price") plot(p)
And here is how it looks like on the chart:
Note: while this works alright, it is not always convenient to enter price inputs manually. It would be much easier if you could select the price on the chart, which can fortunately now be achieved with the new special price input.
How to Set Price Interactively From Chart
We use the input.price function with a confirm parameter to add price interactively from the chart.
//@version=5 indicator("My script", overlay = true) p = input.price(40000, title = "Price", confirm = true) plot(p)
Evidently, this looks very different from the similar input.float function, but when you add it to the chart you see the following message and TradingView will ask you to select a level on your chart directly.
Once you select the level, Pine Script will compute the price you selected and automatically fill the input for you.
You can then make any desired changes from parameters.
Follow me on TradingView and YouTube.