Introduction to TradingView and Pine Script#

What is TradingView#

TradingView is a cloud-based charting and social trading platform that supports real-time quotes and technical analysis across stocks, futures, forex, cryptocurrencies, and other markets.

Key features of TradingView:

  • Cloud-based: No software installation required — works directly in your browser
  • Cross-platform: Works on desktop, mobile, and tablet with automatic chart sync
  • Community: Publish public scripts and share strategies with traders worldwide
  • Broker integration: Supports automated order placement via Webhook, allowing connection to broker APIs worldwide

Comparison with MultiCharts:

TradingViewMultiCharts
InstallationCloud-based, no installLocal installation
CostFree tier availablePaid license required
LanguagePine ScriptPowerLanguage
Target usersBeginner to advancedIntermediate to advanced
Auto-tradingVia WebhookDirect broker API integration

What is Pine Script#

Pine Script is TradingView’s built-in programming language, designed specifically for developing:

  • Indicators: Draw lines, markers, background colors, and other visual elements on charts
  • Strategies: Define buy/sell logic and run backtests
  • Libraries: Encapsulate reusable functions for other scripts to import

Pine Script is a language designed for financial trading. Its syntax is concise and the learning curve is gentle. The biggest difference from general-purpose languages is its Series concept — every variable records the historical value of each bar, making access to past data very intuitive.

Opening the Pine Script Editor#

  1. Go to TradingView and open any chart
  2. Click the Pine Editor icon in the right toolbar
  3. The editor panel will expand on the right side of the screen

Your First Script#

Enter the following code in the Pine Editor and click Add to chart:

//@version=6
indicator("My First Indicator", overlay=true)

plot(close, title="Close Price", color=color.blue)

After running it, a blue line will appear on the chart, tracking each bar’s closing price.

Line-by-line explanation:

CodeDescription
//@version=6Declares the use of Pine Script version 6 (current latest)
indicator(...)Declares this is an indicator script; overlay=true means it overlays on the main chart
plot(close, ...)Draws a line using each bar’s close price as the value

Choosing a Script Type#

Every script must declare its type on the first line:

//@version=6
indicator("Indicator Name")   // Indicator: for drawing, cannot place orders
//@version=6
strategy("Strategy Name")   // Strategy: for backtesting and automated trading
//@version=6
library("Library Name", overlay=true)  // Library: encapsulates functions for other scripts

Key differences between indicators and strategies:

IndicatorStrategy
DrawingYesYes
Order instructionsNoYes
Backtest reportNoYes
PerformanceFasterSlower (needs P&L calculation)

During early development, it’s recommended to use an indicator to verify logic first, then switch to a strategy for backtesting.

Reference#