How to Run Pine Script in TradingView: Beginner's Step-by-Step
Run Pine Script by opening TradingView's Pine Editor, creating or opening a script, saving it, and selecting Add to chart. Compilation checks the code; the chart shows its output. An indicator, a strategy backtest, and a live broker order are different things.
Open the editor and create an indicator
Sign in and open Supercharts on the web or desktop application. Current TradingView documentation places the Pine button on the right toolbar. Older layouts and tutorials may show a bottom tab. Open the script menu and choose a new indicator. TradingView's Pine Editor guide documents the current interface.
Replace the starter source with this complete example:
//@version=6
indicator("My First Script", overlay=true)
plot(close, title="Close", color=color.blue)
The version annotation selects Pine v6. indicator() declares the script type and places its output over the price chart. plot() draws each bar's close. This example is a display exercise, not a trading signal.
Save the script under a recognizable name, then select Add to chart. After editing an existing chart instance, use the editor's update action and check the chart's script title. Saving source, updating a chart instance, and publishing a script are separate actions.
Verify the result before adding complexity
Look for the blue close line and the script's name in the chart legend. Compare the value in the Data Window with the selected bar's close. Change the symbol or timeframe and confirm the series recalculates. If the line overlaps candles, temporarily hide the main price series or adjust the script's style to see it clearly.
The historical calculation proceeds bar by bar. On an open realtime bar, indicators normally recalculate as data updates, so the current close can change before the bar closes. Strategies normally calculate at bar close unless their settings change that behavior. See the execution model.
Diagnose the right kind of failure
| Symptom | Check |
|---|---|
| Compilation error | Read the reported message and nearby lines; confirm spelling, types, indentation, and version compatibility |
| Compiles but has no visible line | Check visibility, scale, pane placement, and whether values are na |
| Runtime error after adding | Inspect history references, array indices, and calculation limits |
| Chart still shows old behavior | Confirm the intended saved script and chart instance were updated |
| No simulated trades | Confirm it is a strategy with entry conditions that actually occur |
A script can display drawings, tables, or shapes without a plot() call. Omitting the version annotation makes Pine assume version 1; it does not universally cause a syntax error, but modern code will generally require its intended version. Script structure explains the declaration requirements.
Choose the next step by script type
An indicator calculates values, displays information, and can expose alert conditions. A strategy uses simulated orders and reports results in Strategy Tester. Historical results depend on data, fill assumptions, costs, and the rules you specified; compiling successfully does not validate their profitability.
To receive notifications, create an alert in TradingView using the script's supported conditions. Adding alert code does not itself create a running alert. A strategy also does not directly place live orders merely because it is attached to a chart.
Saved personal source is separate from published source. Public, private, open-source, protected, and invite-only publication choices have different visibility and access rules. Check permissions before copying or redistributing another author's script. Continue with the Pine Script tutorial when you are ready to add inputs and calculations.
Which Pine version should a new example use?
Use the current v6 documentation for new work. Existing older scripts may still run, but migration requires checking the relevant language changes.
Does running a strategy trade my account?
No. Strategy Tester simulates orders. Broker execution requires a separate supported workflow and appropriate account controls.
Must I publish a script to use it?
No. Save your personal script and add it to your own chart. Publishing is a separate sharing action.

