You have Pine Script code — from a tutorial, a friend or an AI generator — and you want to see it on your chart. TradingView makes this quick, and you don't need a paid plan to add your own scripts. Here's the whole process, from an empty editor to an indicator with alerts.
What you need
- A TradingView account. The free plan is enough to add your own scripts; paid plans raise limits such as the number of indicators per chart.
- The script's complete source code, starting with
//@version=6for Pine Script v6.
If you'd like something to practise with, use this small indicator. It draws two moving averages and marks where they cross:
//@version=6
indicator("EMA cross helper", overlay = true)
fastLen = input.int(9, "Fast EMA", minval = 1)
slowLen = input.int(21, "Slow EMA", minval = 1)
fast = ta.ema(close, fastLen)
slow = ta.ema(close, slowLen)
bullCross = ta.crossover(fast, slow)
bearCross = ta.crossunder(fast, slow)
plot(fast, "Fast EMA", color = color.teal, linewidth = 2)
plot(slow, "Slow EMA", color = color.orange, linewidth = 2)
plotshape(bullCross, title = "Bullish cross", style = shape.triangleup, location = location.belowbar, color = color.teal, size = size.small)
plotshape(bearCross, title = "Bearish cross", style = shape.triangledown, location = location.abovebar, color = color.orange, size = size.small)
alertcondition(bullCross, "Bullish cross", "Fast EMA crossed above slow EMA")
alertcondition(bearCross, "Bearish cross", "Fast EMA crossed below slow EMA")
Step 1: Open the Pine Editor
- Open a chart on TradingView — any symbol will do.
- Open the Pine Editor. Depending on your layout, it's a tab at the bottom of the chart or an icon in the side panel.
Step 2: Create a new script
- In the editor's script menu, choose to create a new Indicator — or a Strategy, if your code starts with
strategy(. - Select all of the template code and delete it. Leftover template lines are the most common cause of confusing errors.
- Paste your code.
Step 3: Save and add it to the chart
- Click Save and give the script a name. It's stored privately in your account.
- Click Add to chart.
That's it. The indicator appears on the price chart, or in a new pane below it for scripts without overlay = true. Strategies also open a Strategy Tester report with the simulated trades and performance metrics.
From now on you'll find the script among your own scripts in the Indicators dialog, so you can add it to any chart without opening the editor.
Step 4: Change the settings
Hover over the indicator's name on the chart and click the settings (gear) icon. The Inputs tab shows every input.*() value in the code — lengths, sources, thresholds — and the Style tab controls colours and line widths. Changing inputs here doesn't modify the code itself.
Step 5: Create an alert
If the script contains alertcondition() calls, or uses alert():
- Click the Alert button (the alarm-clock icon) in the top toolbar.
- Under Condition, choose your script, then the specific alert condition.
- Choose how often it can trigger and how you want to be notified, then create it.
Alerts run on TradingView's servers, so they keep working when your browser is closed. How many alerts you can keep active depends on your plan.
Fixing common errors
When compilation fails, the console under the editor shows an error with a line number. The usual suspects:
| Error message (roughly) | What it usually means | Fix |
|---|---|---|
| Undeclared identifier | A name is misspelled, or used before it's defined | Check spelling and the order of lines |
| Mismatched input / syntax error | Missing bracket, wrong indentation, or stray characters from copying | Re-copy the code; local blocks need four-space indentation |
| Could not find function or function reference | The function doesn't exist in this Pine version, or its namespace is missing | Write ta.ema, not ema; check the //@version line |
| Cannot call ... with argument ... | Wrong argument type or name | Check the function's parameters in the reference manual |
| Script must have at least one output function call | An indicator that draws nothing | Add a plot(), plotshape() or similar output |
Fix the first error first — a single missing bracket can produce several messages.
Upgrading v5 code
Scripts that start with //@version=5 still run. If you want to move one to v6, the Pine Editor can convert it from its menu. The main differences are covered in Pine Script v6 for beginners.
Indicator or strategy: which do you need?
- Indicator — draws signals and triggers alerts. You place the trades yourself.
- Strategy — simulates orders on historical data so you can backtest. It doesn't place real trades on its own.
If you want fully automated execution on a broker account, MetaTrader 5 Expert Advisors are a more direct route — see how to install an Expert Advisor on MT5.
Before you rely on it
Check a few signals by eye against your rules, watch the script on a live chart to make sure its signals don't repaint, and if it's a strategy, read backtesting mistakes that inflate results before trusting the report. Pair signals with sensible sizing — the risk/reward calculator helps you check each setup before you take it.
Try it with Edgoro
Describe the indicator you want — "plot the 20 and 50 EMA, colour the background green when the 20 is above the 50, alert on crosses" — and Edgoro writes the Pine Script v6 code for you to paste using the steps above. If TradingView shows an error, paste it back into the chat and Edgoro fixes it. Try it free.
Trading involves substantial risk of loss. Indicators describe the past; they don't predict the future.