ⓘ Disclaimer

This page may contain affiliate links. We may earn a commission if you make a purchase through these links. Nothing on this website should be construed as financial advice. Learn more.

How to Use Pine Script in TradingView (Beginner’s Guide)

Every custom indicator and strategy on TradingView is built with one tool: Pine Script, TradingView’s own programming language. If you have ever wanted to tweak an indicator, run someone else’s script, or code your own setup instead of paying for a black box, this is where you start. This guide walks you from opening the Pine Editor to running your first working script, in plain language, with no coding background required. If you are still finding your way around the platform itself, our beginner’s guide to using TradingView covers the basics first.

Key Takeaways

  • Pine Script is TradingView’s built-in language for creating indicators, strategies, and alerts that run on TradingView’s servers, with no install or external software needed.
  • You write and apply scripts in the Pine Editor (the “Pine” tab at the bottom of any chart); free and paid TradingView plans can both use it, with higher tiers raising script and alert limits.
  • Indicators draw on your chart, strategies can be backtested in the Strategy Tester, and both can fire alerts, but Pine Script cannot place live orders by itself; live automation needs a broker connection or a third-party execution bridge.
Financial Tech Wiz Trading Journal

A script only matters if it actually makes you money. Log the trades your Pine Script signals trigger, then see win rate and P&L across your positions, broken down by symbol and hold duration, so you know whether the indicator works on your account, not just on a backtest.

Track your trades free

What Is Pine Script?

Pine Script is the programming language TradingView built specifically for traders. It lets you create custom indicators, design strategies, and define alert conditions, then run them directly on TradingView’s charts and servers. You do not download anything or install a separate program; everything happens inside the browser or the TradingView desktop app. The current version is Pine Script v6, and TradingView maintains older versions (v4 and v5) for scripts written before the upgrade.

Because the language was designed around price and time series data, a few lines of Pine can do what would take far more code in a general-purpose language like Python or JavaScript. Built-in variables such as close, high, and volume give you the current bar’s data automatically, and a deep library of technical-analysis functions means you rarely have to build common calculations from scratch. To answer the question that shows up most in search: yes, TradingView uses Pine Script as its native scripting language, and it is the only language for building indicators and strategies on the platform.

Free or Paid: What You Need to Use Pine Script

You do not need a paid TradingView plan to write Pine Script. The Pine Editor is available on the free plan, and you can write, save, and apply your own scripts at no cost. What the paid tiers buy you is capacity: more indicators per chart, more saved scripts, server-side and multi-condition alerts, and access to features like second-based timeframes. If you are learning, start on the free TradingView plan, and only upgrade when you hit a limit that actually blocks your workflow.

In practical terms, the free plan is genuinely enough to learn on and to run a handful of personal indicators. Where traders most often run into a wall is alerts: the free tier caps how many active alerts you can hold and limits server-side alerts, so a script that relies on always-on notifications across many symbols is the usual reason to upgrade. The other common trigger is wanting more than a couple of indicators on a single chart at once. Neither of those affects writing or testing Pine, only running it at scale.

How to Open the Pine Editor

The Pine Editor is where every script is written and edited.

  1. Open any chart on TradingView.
  2. Look at the bottom of the screen for the Pine Editor tab (sometimes labeled just “Pine”). Click it to expand the editor panel.
  3. The editor opens with a blank or sample script. From here you can type code, open saved scripts, or paste in code from elsewhere.

Pine Editor not showing? If you do not see the tab, the panel may be collapsed; click the small upward arrow at the bottom edge of the chart to reveal the bottom toolbar, then select Pine Editor. On smaller screens TradingView hides it behind the bottom panel menu. The editor is not available in some embedded or widget views, only on full chart pages.

Adding an Existing or Community Script

You do not have to write code to benefit from Pine Script. Thousands of community scripts are published in the TradingView public library, and most are free and open source.

  1. On a chart, open the Indicators dialog (the “Indicators, Metrics & Strategies” button at the top).
  2. Search by name, or open the Community Scripts tab to browse published indicators and strategies.
  3. Click a script to add it to your chart. Open-source scripts can be opened in the Pine Editor with Source code, where you can read and edit them.

Pasting In Code You Found Elsewhere

If you copied code from a tutorial, a GitHub repo, or a forum, paste it into the Pine Editor, then click Add to chart. If the code uses an older Pine version, TradingView will tell you, and you may need the version annotation (for example //@version=6) at the top to match. The editor underlines errors as you type, so a script that will not compile usually points you to the exact line that needs fixing.

Anatomy of a Pine Script

Most scripts share the same skeleton, and recognizing it makes other people’s code readable:

  • Version annotation: //@version=6 tells TradingView which language version to use.
  • Declaration: indicator() for something that draws on the chart, or strategy() for something that can be backtested with simulated entries and exits.
  • Inputs: values the user can change in the settings panel, created with input() (for example, a moving-average length).
  • Calculations: the logic, using built-in series like close, high, and low, and functions like ta.ema().
  • Output: plot() to draw a line, or strategy.entry() and strategy.exit() to simulate trades.

Understanding these five pieces is enough to read and lightly modify the majority of community scripts, even if you never write one from a blank file.

Write Your First Pine Script (Worked Example)

Here is a complete, minimal indicator that plots a 20-period exponential moving average. Paste it into the Pine Editor and click Add to chart:

//@version=6
indicator("My First EMA", overlay=true)
length = input.int(20, "EMA Length")
emaValue = ta.ema(close, length)
plot(emaValue, color=color.blue, linewidth=2, title="EMA")

Line by line: the version annotation sets v6; indicator(..., overlay=true) puts the line on the price chart instead of a separate pane; input.int() creates an editable length you can change in settings; ta.ema(close, length) calculates the EMA on closing prices; and plot() draws it. Change the 20 default or swap ta.ema for ta.sma and you have already customized your first indicator. That loop, change one thing, re-add to chart, see the result, is how most people actually learn Pine.

Once a script compiles, save it with the Save button so it lands in your personal script list, and give it a clear name in the indicator() title so you can find it later in the Indicators dialog. Saved scripts are private to your account until you choose to publish them to the community library. Renaming the title argument changes how the indicator is labeled on the chart and in settings, which matters once you have a dozen of your own.

Indicators vs Strategies (and the Strategy Tester)

The difference between the two declaration types matters. An indicator() only visualizes data; it cannot record hypothetical trades. A strategy() can, which unlocks the Strategy Tester tab: when you add a strategy to a chart, TradingView simulates its entries and exits over historical data and reports net profit, win rate, drawdown, and a list of trades. This is how you sanity-check an idea before risking money.

Keep in mind the standard backtesting caveats: results depend on the date range, repainting can flatter a script, and historical performance is not a promise of future returns. For a deeper walkthrough of validating a strategy on past data, see our guide to backtesting a strategy on TradingView.

Free Trading Journal Template

New to all of this? Before you automate anything, get the habit of recording every trade. Our free Google Sheets trading journal template is the simplest way to start tracking the setups your scripts flag, no signup friction, no spreadsheet building.

Get the free template

Alerts and the Limits of Automation

Pine Script can define alert conditions with alert() or alertcondition(), so your script can notify you the moment a setup triggers. If you want to turn a script’s signals into notifications, our walkthrough on setting up TradingView alerts covers the full process.

What Pine Script cannot do on its own is place a live order. Scripts run on TradingView’s servers in a sandbox; they read market data and draw or notify, but they have no direct connection to your brokerage. To act on a Pine alert automatically you either trade through a broker that TradingView connects to and place the order manually when the alert fires, or route the alert’s webhook through a third-party execution service such as SignalStack, which converts the alert into a broker order. Treat any “fully automated Pine bot” claim with skepticism; the script is one half, the execution bridge is the other.

AI and Pine Script

A growing shortcut for non-coders is using an AI assistant to draft Pine Script. You describe the indicator or rule in plain English, the model returns code, and you paste it into the Pine Editor. It works well for simple, well-defined requests and is a fast way to learn by reading generated code. Two cautions: AI models sometimes mix Pine versions or invent functions that do not exist, so test every generated script on a chart before trusting it, and always confirm the //@version line matches current syntax. AI is a drafting aid, not a replacement for reading the TradingView reference.

If you do use AI, give it the specifics it needs: name the Pine version, describe the exact condition (for example, “plot a buy marker when the 50 EMA crosses above the 200 EMA”), and say whether you want an indicator or a strategy. Vague prompts produce vague code. When the model returns something, read it against the five-part anatomy above before you run it, and if the editor throws an error, paste that error back to the model rather than guessing. Used this way, AI is a fast feedback loop, not a black box.

Free Pine Scripts and Where to Find Them

You do not have to start from a blank editor. The TradingView public library holds tens of thousands of free, open-source scripts you can add to a chart and, if open source, open in the Pine Editor to study. Editors’ Picks and the Community Scripts tab are good starting points. If you want a curated shortlist rather than an endless library, our roundup of the best TradingView indicators is a faster way in. When you use someone else’s script, read the source if it is available, check the comments and reviews, and never assume a flashy backtest reflects live behavior.

Common Beginner Mistakes

  • Version mismatch: pasting v4 or v5 code without updating the //@version line, then getting cryptic errors.
  • Repainting confusion: trusting signals that only look perfect because they recalculated on historical bars.
  • Overlay vs pane: forgetting overlay=true, so a price-based line plots in a tiny separate pane.
  • Backtest over-optimization: tuning a strategy until it fits the past perfectly, which rarely survives live trading.
  • Treating alerts as execution: assuming an alert places a trade. It does not, by itself.

How to Keep Learning Pine Script

The fastest path is reading and modifying. Start with the official TradingView Pine Script v6 User Manual and reference for syntax, then open community scripts’ source code and change one variable at a time to see what moves. Keep a running note of functions you have used. When you write something that produces signals, the real test is not the backtest, it is whether it holds up on your own trades, which is where the Financial Tech Wiz Trading Journal comes in: it tracks the live results of the setups your scripts flag so you can tell a genuinely useful indicator from one that only looked good on history.

FAQ

Does TradingView use Pine Script?

Yes. Pine Script is TradingView’s own programming language and the only way to build custom indicators and strategies on the platform. Every script in the community library, and every custom indicator you add, is written in Pine.

Is Pine Script free to use in TradingView?

Yes. The Pine Editor and the ability to write, save, and apply your own scripts are available on the free TradingView plan. Paid plans raise limits on indicators per chart, saved scripts, and server-side alerts, but you can learn and use Pine Script without paying.

How do I open the Pine Editor in TradingView?

Open any chart and click the Pine Editor tab at the bottom of the screen. If you do not see it, expand the bottom panel using the upward arrow at the bottom edge of the chart, then select Pine Editor. It is available on full chart pages, not in embedded widgets.

Can Pine Script place trades automatically?

No, not on its own. Pine Script runs on TradingView’s servers and can draw on charts and fire alerts, but it cannot send orders to a broker by itself. To automate execution you either act on the alert manually through a connected broker or route the alert through a third-party execution service such as SignalStack.

How do I run a script I copied from somewhere else?

Paste the code into the Pine Editor and click Add to chart. If the script was written for an older Pine version, update the //@version line at the top to match, and fix any functions the editor flags as renamed in v6.

FREE RESOURCES

Get Your Free Trading Resources

Grab the free trading journal template plus the same tools we use to stay organized, consistent, and objective.

  • Free trading journal template
  • Custom indicators, watchlists, and scanners
  • Access our free trading community
What you get
Journal Indicators Scanners Community

Enter your email below to get instant access.

No spam. Unsubscribe anytime.

Related Resources

  • stock rover review
    Stock Rover Review 2026: Features, Pricing, Pros and Cons
  • tradervue review
    Tradervue Review
  • trade ideas dashboard
    Trade Ideas Review 2026: Holly AI, Money Machine, Pricing
  • tradingview review
    TradingView Review (2026): Is It Worth It?
  • trendspider review image
    TrendSpider Review (2026): Charting, AI, and Scanning in One Workspace
  • optionomegareviewthumbnail
    Option Omega Review 2026: Backtest, Automate, Pricing
  • best options backtesting software
    Best Options Backtesting Software
  • tradingview vs trendspider comparison
    TrendSpider vs TradingView – Which Charting Software is Best?