Skip to main content

Free Pine Script Library

Ten classic strategies with their full Pine Script v5 code, and five trend strategies exported and judged by the Lab. Copy one into TradingView, then test it on data it has never seen in the free Lab.

10+ Free Scripts Pine Script v5 Copy & Paste Ready No Signup
1. Public Pine Copy the baseline

Free scripts stay open for TradingView inspection and quick experiments.

2. ArenaScript Build privately

Builder turns ideas into readable ArenaScript with private backtests and Pine export.

3. World Arena Test hostile markets

Operator reports show where a strategy survives, dies, sits in cash, or beats Buy & Hold and a 200-day filter.

4. TradingView Export only after validation

The public exit remains TradingView; the free Lab is the validation before that exit.

Buy when RSI crosses back above 30 (oversold), exit when it crosses below 70 (overbought). The best-known Pine Script strategy.
//@version=5
strategy("RSI Mean Reversion", overlay=true, pyramiding=0, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, process_orders_on_close=true, margin_long=0)
rsiLen = input.int(14)
rsiVal = ta.rsi(close, rsiLen)
if (ta.crossover(rsiVal, 30))
    strategy.entry("Long", strategy.long)
if (ta.crossunder(rsiVal, 70))
    strategy.close("Long")
Not judged by the Lab yet. A short backtest on TradingView is not a verdict: test it on a sealed period it has never seen.
Classic trend following: buy when the fast EMA (9) crosses above the slow EMA (21), exit on the opposite cross.
//@version=5
strategy("EMA Crossover 9/21", overlay=true, pyramiding=0, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, process_orders_on_close=true, margin_long=0)
fast = ta.ema(close, 9)
slow = ta.ema(close, 21)
if (ta.crossover(fast, slow))
    strategy.entry("Long", strategy.long)
if (ta.crossunder(fast, slow))
    strategy.close("Long")
Not judged by the Lab yet. A short backtest on TradingView is not a verdict: test it on a sealed period it has never seen.
Three EMAs must be aligned (8 > 21 > 55) to enter. A stricter trend filter than a single crossover.
//@version=5
strategy("EMA Ribbon", overlay=true)
ema1 = ta.ema(close, 8)
ema2 = ta.ema(close, 21)
ema3 = ta.ema(close, 55)
if (ema1 > ema2 and ema2 > ema3)
    strategy.entry("Long", strategy.long)
if (ema1 < ema2)
    strategy.close("Long")
Not judged by the Lab yet. A short backtest on TradingView is not a verdict: test it on a sealed period it has never seen.
Buy below the lower Bollinger Band, exit above the upper band. Mean reversion based on standard deviation.
//@version=5
strategy("BB Bounce", overlay=true, pyramiding=0, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, process_orders_on_close=true, margin_long=0)
length = input.int(20)
mult = input.float(2.0)
[middle, upper, lower] = ta.bb(close, length, mult)
if (close < lower)
    strategy.entry("Long", strategy.long)
if (close > upper)
    strategy.close("Long")
Not judged by the Lab yet. A short backtest on TradingView is not a verdict: test it on a sealed period it has never seen.
Buy on a bullish MACD crossover, exit on a bearish crossover.
//@version=5
// MACD 12/26/9 : long tant que la ligne MACD est au-dessus de sa signal, plat sinon.
// Le croisement haussier ouvre, le croisement baissier ferme : ces etats en sont la lecture.
strategy("MACD Momentum", overlay=true, pyramiding=0, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, process_orders_on_close=true, margin_long=0)
[macdLine, signalLine, hist] = ta.macd(close, 12, 26, 9)
longSignal = macdLine > signalLine
exitSignal = macdLine < signalLine
if longSignal
    strategy.entry("Long", strategy.long)
if exitSignal
    strategy.close("Long")
Not judged by the Lab yet. A short backtest on TradingView is not a verdict: test it on a sealed period it has never seen.
ATR-based trend following: the SuperTrend line follows volatility, and the direction flip drives entries and exits.
//@version=5
// SuperTrend (facteur 3, ATR 10) : long en tendance haussiere, plat sinon.
strategy("SuperTrend", overlay=true, pyramiding=0, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, process_orders_on_close=true, margin_long=0)
// direction vaut -1 en hausse, +1 en baisse.
[supertrend, direction] = ta.supertrend(3.0, 10)
longSignal = direction < 0
exitSignal = direction > 0
if longSignal
    strategy.entry("Long", strategy.long)
if exitSignal
    strategy.close("Long")
Not judged by the Lab yet. A short backtest on TradingView is not a verdict: test it on a sealed period it has never seen.
Applies the stochastic oscillator to RSI: buy when %K crosses above %D below 20, exit when it crosses back below %D above 80.
//@version=5
strategy("Stoch RSI", overlay=true)
rsi1 = ta.rsi(close, 14)
k = ta.sma(ta.stoch(rsi1, rsi1, rsi1, 14), 3)
d = ta.sma(k, 3)
if (ta.crossover(k, d) and k < 20)
    strategy.entry("Long", strategy.long)
if (ta.crossunder(k, d) and k > 80)
    strategy.close("Long")
Not judged by the Lab yet. A short backtest on TradingView is not a verdict: test it on a sealed period it has never seen.
Enter on a break of the 20-bar high when ATR is above its average, with a stop at 2 ATR.
//@version=5
strategy("ATR Breakout", overlay=true)
atr = ta.atr(14)
upper = ta.highest(high, 20)
if (close > upper[1] and atr > ta.sma(atr, 20))
    strategy.entry("Long", strategy.long)
    strategy.exit("Exit", "Long", stop=close - atr * 2)
Not judged by the Lab yet. A short backtest on TradingView is not a verdict: test it on a sealed period it has never seen.
Buy when price crosses back above VWAP, exit when it crosses back below.
//@version=5
strategy("VWAP Bounce", overlay=true)
vwapVal = ta.vwap(hlc3)
if (close > vwapVal and close[1] < vwapVal[1])
    strategy.entry("Long", strategy.long)
if (close < vwapVal and close[1] > vwapVal[1])
    strategy.close("Long")
Not judged by the Lab yet. A short backtest on TradingView is not a verdict: test it on a sealed period it has never seen.
Two conditions: RSI leaves oversold AND price is above the 50 EMA.
//@version=5
strategy("RSI + EMA Combo", overlay=true)
rsiVal = ta.rsi(close, 14)
ema50 = ta.ema(close, 50)
if (ta.crossover(rsiVal, 30) and close > ema50)
    strategy.entry("Long", strategy.long)
if (rsiVal > 70 or close < ema50)
    strategy.close("Long")
Not judged by the Lab yet. A short backtest on TradingView is not a verdict: test it on a sealed period it has never seen.
Hold while the monthly close is above its 10-month average, go flat below it. Use a monthly chart.
//@version=5
strategy("Faber 10-Month Timing", overlay=true, pyramiding=0, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, process_orders_on_close=true, margin_long=0)
smaVal = ta.sma(close, 10)
if (close > smaVal)
    strategy.entry("Long", strategy.long)
if (close < smaVal)
    strategy.close("Long")
Not judged by the Lab yet. A short backtest on TradingView is not a verdict: test it on a sealed period it has never seen.

5 famous trend strategies, exported to Pine by the Lab, with their verdict

Original settings from the source, judged walk-forward (4 folds, 2019-2025, two markets never opened by the family, 10 bps fees). None beats buy-and-hold across several cycles. Each Pine is the Lab's TradingView-exact export of the judged rule (no inputs, trade log in Pine Logs).

Research on past public data, not a sealed proof and not investment advice. Method and limits: full article.

TSMOM 12M long/short · vol target 40%
TREND LAB VERDICT: INCONCLUSIVE
Long if price rose over 12 months, short otherwise. Wins the bear fold, gives it back in rallies. (Moskowitz, Ooi, Pedersen 2012 · BTC + ETH 1d)
OOS chain
+186%
Buy & hold
+1852%
Folds won
1/4
Indep. events
1 (579)
Does not beat buy-and-hold across 2019-2025. Judged rule (ArenaScript): entry: ROC(12, 1M) > 0 · short: ROC(12, 1M) < 0 · size: vol_target 40% window 60
Pine v5 · tv_exact_v1 · sha256 b70f42171725509bca001035d338ac333b67db529f05bc67c3210a1705ffc30f
Faber 10M (monthly)
TREND LAB VERDICT: INCONCLUSIVE
Long above the 10-month average, cash below. Does not even reduce max drawdown on LTC and XLM. (Faber 2007 · LTC + XLM 1d)
OOS chain
+5.4%
Buy & hold
+496.6%
Folds won
1/4
Indep. events
1 (383)
Does not beat buy-and-hold across 2019-2025. Judged rule (ArenaScript): entry: price > SMA(10, 1M) · exit: price < SMA(10, 1M) · monthly
Pine v5 · tv_exact_v1 · sha256 8c0fab06e6183ae813f0e9de51ca27e538f9bbc36db5f9c4a7a8f2a562a251a8
Donchian ensemble 9 windows · vol target 25%
TREND LAB VERDICT: INCONCLUSIVE
Nine channels vote. Best protection in the bear fold (-8.8% vs -55.2%). (Zarattini, Pagani, Barbon 2025 (approx.) · TRX + ETC 1d)
OOS chain
+368.2%
Buy & hold
+1207.8%
Folds won
1/4
Indep. events
1 (510)
Does not beat buy-and-hold across 2019-2025. Judged rule (ArenaScript): entry: VOTE(DONCHIAN_TREND(5…360)) >= 5 of 9 · size: vol_target 25% window 90
Pine v5 · tv_exact_v1 · sha256 72347b054eb66eca5e1a18603bdd1c13b05ecc25c0b511bd5410b79e9b1642a2
SMA 200d defense · vol target 40% (4h)
TREND LAB VERDICT: INCONCLUSIVE
Strongest on risk: max drawdown ÷1.7 (BTC) and ÷1.8 (ETH), DSR 98.9%. Loses the 2019-2020 fold. (Moreira, Muir 2017 · BTC + ETH 4h)
OOS chain
+766.7%
Buy & hold
+2012.9%
Folds won
1/4
Indep. events
2 (1 320)
Does not beat buy-and-hold across 2019-2025. Judged rule (ArenaScript): entry: price > SMA(200, 1d) · exit: price < SMA(200, 1d) · size: vol_target 40% window 360
Pine v5 · tv_exact_v1 · sha256 51c7a00188d5cb16a25a7070f39bbefe364e64f5b04028937e87fa307bcb213a
EMA 50/200 long/short
TREND LAB VERDICT: MIRAGE
Symmetric full-size shorting: complete ruin on ATOM over the full series. (Murphy 1999 · ATOM + LINK 1d)
OOS chain
-93.1%
Buy & hold
-21.0%
Folds won
1/4
Indep. events
1 (470)
Does not beat buy-and-hold across 2019-2025. Judged rule (ArenaScript): long: EMA(50) > EMA(200) · short: EMA(50) < EMA(200) · size: 100%
Pine v5 · tv_exact_v1 · sha256 8c76604425d0aadb7a18ff43cf8134f14ba53ebe307714032e690bc98f6a1ce5
TradingView Starter
Choose the account path. Prove the strategy separately.
Your first chart and price alert do not require the Lab. Strategy Arena proof remains required before trusting or exporting a strategy.
Partner attribution is for first-time users and web purchases only. Strategy Arena may earn a commission on eligible purchases; starting with a free account needs no payment.
I have never had an account · Start free I already have an account Check a strategy
More TradingView paths
Evidence-gated Pine review

Submit Your Pine Script

Got a strategy that beats cash, Buy & Hold and a 200-day filter on a sealed holdout? Submit it. A YouTube B&H win in a bear is not enough.

Submit & Test Your Script

By submitting, you agree that your strategy may be analyzed to improve our AI systems.

Free Pine Script Strategies, Then a Test on Unseen Data

The library separates reusable code from proof. A script that looks good on one chart has not been tested yet. Strategy Arena Lab can replay supported logic, search variants on training data and let the Rust CPU authority judge a sealed holdout.

Copy the Pine Script into TradingView for chart inspection, or check its supported subset before opening a local Lab proof. Strategy Arena performs research simulation and does not create broker automation.

What this Pine Script collection is, and is not

It is a small collection, kept readable on purpose: eleven classic //@version=5 strategies (RSI mean reversion, EMA crossover, EMA ribbon, Bollinger bounce, MACD, SuperTrend, stochastic RSI, ATR breakout, VWAP, RSI + EMA, Faber 10 months) with their full code on this page, and five trend strategies from the research literature, exported by the Lab with their verdict. It is not a repository of thousands of scripts: for that, TradingView's public library of community scripts is the place to browse.

What it adds is the step after copying: Strategy Arena Lab, free for Windows and Linux, runs a supported script on data it has never seen and compares its trades with TradingView's. Common Pine questions: using [1] on ta.dmi, ta.macd and other tuples, Pine Script alternatives.

More tools: AI Chart Analysis | Backtesting Tool | Best Pine Script Strategies 2026 | Pine Script to Python Guide

How to run your Pine Script on TradingView

A Pine strategy is only useful once you can see it on a live chart. Here is the exact order that avoids the usual traps.

  1. Test the Pine free first in the Lab — sealed verdict, no account.
  2. Create a TradingView account (the free plan is enough to plot).
  3. Open the Pine editor and paste your script.
  4. Add your alerts, then review the exact Strategy Arena report before relying on it.

Free or paid TradingView?

The free web account is enough to plot a script and create a few alerts. Paid plans add more indicators, alerts and layouts — they are decided on TradingView and never change a Strategy Arena verdict. Strategy Arena is not a broker and places no real order.

Why test before you run it

A naive backtest almost always overstates a strategy. The Lab uses a sealed chronological holdout and uncertainty diagnostics to reduce overfitting before anything reaches a live chart.