Indicators
Can I create an indicator that plots like the built-in Volume or Volume Profile indicators?
The Volume and Visible Range Volume Profile indicators (along with some other built-in indicators) are written in Java. They display data on the main chart pane in a unique way:
- The bars are anchored to the bottom or right edge of the chart, not to an absolute x or y value.
- The length of the bars is a relative percentage of the available space and is not an absolute price or number of bars.
- The length of the bars adjusts automatically according to the data from the range of bars that are visible on the chart. The lengths of the bars are normalized so as never to appear too small or too large.
- The width of the bars adjusts automatically to fit the visible space.
It is difficult for Pine Script™ indicators to plot values in the same way.
Limitations of `plot.style_columns`
Limitations of drawings
The following example script demonstrates some techniques for approximating the way that the built-in Volume indicator displays.
- We use the chart.right_visible_bar_time and chart.left_visible_bar_time built-in variables, through the PineCoders’ VisibleChart library, to define the bars that are visible. Then we calculate the highest and lowest price, and the highest volume, for that period.
- We plot lines retroactively, after the visible window and all related values are known.
- We anchor the lines below the lowest visible price, so that it looks as if they are anchored to the bottom edge of the chart.
- We scale the length of all the volume bars so that the longest bar in the set is approximately 30% of the screen height, similar to the built-in Volume indicator.
- We adjust the width of the lines depending on how many bars are visible.
This script has some other limitations:
- The lines do not begin from the bottom of the chart if other indicators display plots or drawings below that level.
- In common with any script that uses the chart.right_visible_bar_time or chart.left_visible_bar_time built-in variables, the script must refresh each time the chart is moved or a new bar appears.
- There is a maximum limit of 500 lines per script.
- The width of the lines is calculated based on how many bars are visible. However, a Pine script has no way of knowing how much blank space there is to the right of the final bar. If the user scrolls to the right, the lines can appear too wide and overlap each other.
Can I use a Pine script with the TradingView screener?
The TradingView screener uses only its built-in filters, and cannot use a Pine script. Search for “screener” in the Community Collection to find scripts that use the request.security() function to screen pre-set lists of symbols.
See also this FAQ entry for an example script that generates alerts on multiple
symbols.
Note that using several request.security()
calls can cause scripts compile and run more slowly than expected.
How can I use the output from one script as input to another?
Scripts with an input of type input.source() can take a plot from another script (up to a maximum of ten) as an input. Select the script and plot to take as input in the script’s “Settings” tab. If the user removes the script from the chart and adds it again, they must select the correct inputs again.
The sources used as external inputs must originate from indicators; they cannot originate from strategies. However, plots originating from indicators can be used in strategies.
For further information, refer to this blog post and the Source input section in the User Manual.
Can my script draw on the main chart when it’s running in a separate pane?
Scripts that have the overlay
parameter in the indicator() or strategy() functions set to false
appear in a separate pane to the main chart.
Such scripts can affect the display of the main chart in only two ways:
- Changing bar colors, using the barcolor() function.
- Forcing plots to overlay, using
force_overlay = true
in the plotting function. Theforce_overlay
parameter is available in most functions that draw on the chart.
Is it possible to export indicator data to a file?
The option “Export chart data…” in the dropdown menu at the top right corner of the chart exports a comma-separated values (CSV) file that includes time, OHLC data, and any plots generated by your script. This option can also export strategy data.
To include specific information in the CSV file, ensure that it is plotted by the script.
If this extra information is far from the symbol’s price and the existing indicator plots, and plotting it on the chart could distort the scale of the script, or if you prefer not to display
certain plots, consider using the display
parameter in the plot() function.
Here is an example plot that displays the close only in the Data Window. The plot title “No chart display” becomes the column header for this value in the CSV file.
Alternatively, the “Scale price chart only” in the chart settings maintains the script’s scale. To access these settings, right-click on the chart’s price scale.
To determine if a condition is true or false, use the plotshape() function, which records a 1 (for true) or 0 (for false) in the CSV file.