Skip to main content
← Back to blog

7 Free Pine Script Strategies for TradingView, With Code

📅 Published
Updated
✍️ Strategy Arena
pine script tradingview backtest free tutorial

Short answer: Strategy Arena publishes seven free Pine Script v5 strategies for TradingView, each with complete code: RSI mean reversion, EMA ribbon 8/21/55, Bollinger Band bounce, MACD crossover, SuperTrend filter, Stochastic RSI and an ATR breakout with a fixed stop. Each page states entry and exit rules, declared costs and one weakness to investigate. On 31 October 2026, adapted versions of five of them went through our online judge on BTCUSDT: none survived, and neither did any of the seven exact scripts judged on 6 November 2026.

Already have your own Pine strategy? Test it for free in your browser with our online Pine Script strategy tester: no install, the last 20% of the data stays sealed.

Copy a free Pine Script v5 example, open a chart and inspect its trades. Seven approaches, with complete code, entry and exit rules, declared costs and a weakness to investigate for each one.

Examples to explore, not tested winners: none of the exact versions survived the judge. On 6 November 2026 it judged four of them (verdict under each example); adapted versions of five were judged on 31 October 2026.

No Strategy Arena account or Lab installation is needed to copy the code. The chart link above is not affiliated. The Starter separates first-time users from existing accounts; an eligible web subscription through a partner link may earn Strategy Arena a commission. No purchase is required for this exercise.

Choose your first experiment

Example Entry Exit Main question
RSI RSI crosses above 30 RSI crosses below 70 Does a rebound arrive before losses become large?
EMA ribbon EMA 8 > 21 > 55 EMA 8 < 21 What happens in a sideways market?
Bollinger Bands Close below the lower band Close above the upper band Does the price revert, or keep falling?
MACD MACD crosses above signal MACD crosses below signal How much does repeated switching cost?
SuperTrend Direction is bullish Direction is bearish How late does the filter react?
Stochastic RSI K crosses D below 20 K crosses D above 80 Do extra conditions leave positions open too long?
ATR breakout Prior 20-bar high breaks, with higher ATR Fixed signal-anchored ATR stop How do gaps and fill prices change the loss?

The names describe mechanisms, not evidence of which one is best. For a first reading, RSI or the EMA ribbon has relatively few moving parts.

What the judge said on 31 October 2026

We ran adapted versions of these rules through our online strategy judge, on BINANCE:BTCUSDT data up to 17 October 2026. None survived. Each cell gives the verdict and the return on the sealed period, the last 20% of the window, which the judge keeps apart.

Rule 1D (from Dec 2024) 4h (from Mar 2026) 1h (from Aug 2026) Try it
Buy and hold, for reference −23.3% +15.8% +27.1%
RSI Too few trades (3), +25.3% Too few trades (4), −3.4% Too few trades (8), +11.0% Judge it
EMA ribbon Mirage, −7.8% Inconclusive, +5.1% Mirage, +14.3% Judge it
Bollinger Bands Too few trades (8), −4.3% Mirage, −5.2% Mirage, +1.0% Judge it
MACD, adapted to a state rule Mirage, −16.1% Inconclusive, +4.6% Mirage, +6.6% Judge it
SuperTrend Too few trades (9), −30.0% Inconclusive, +2.7% Mirage, +12.0% Judge it

A loss stays a mirage even when buy and hold lost more. Stochastic RSI and the ATR breakout have no adapted version; their exact scripts are judged below each example since 6 November 2026.

These are not the exact scripts printed below. Until 6 November 2026 the judge refused slippage=1; it now counts the slippage as an extra fee at its worst case on this data (under 0.04 bps per fill on BTCUSDT) and judges all seven exact scripts, with the verdict under each example. It still refuses a conversion that would change the rule. In the judge, the versions behind the "Judge it" links invest 100% of equity, fill at the bar close and pay 10 bps per fill. The MACD version enters while MACD is above its signal line, not on the crossover, because the crossover exceeds the compute budget on 4h and 1h. The windows are 3,347 daily, 6,570 four-hour and 8,760 hourly bars.

We compared the RSI, Bollinger, MACD and SuperTrend versions with TradingView's own trade list on 31 October 2026: 204 of 206 trades matched on 1D and 399 of 400 on 4h. The EMA ribbon was not part of that check. These are measurements on past data for these scripts, not a guarantee for other Pine code, and not advice.

To compare on your own chart, paste a script into TradingView. New to TradingView? Create an account (partner link: an eligible subscription may earn us a commission; the free plan is enough for this exercise).

Run one example, not all seven at once

  1. Copy one complete script, starting with //@version=5.
  2. Open TradingView on the web, use a standard candlestick chart and paste the code into a new Pine strategy. Select Add to chart.
  3. Inspect the strategy report and a few individual trades. Note the exchange, symbol, interval, available dates and settings before comparing another run.
TradingView daily BTCUSDT candlestick chart with the symbol and daily interval visible
TradingView interface captured for the Starter on 11 September 2026. A navigation example, not a result from one of these strategies or a current price quote.

The practice link uses BINANCE:BTCUSDT, daily bars as a navigation example, not a tested market recommendation. Available history can differ between accounts. Code editing may be more comfortable on a larger screen; the Starter can begin with a chart instead.

All seven examples use the same declared starting assumptions: 10,000 units of simulated capital, 10% of equity per entry, no pyramiding, 0.1% commission per order, one tick of slippage and 100% long margin. The first six exit on a signal; they have no protective stop. Instrument quantity constraints can prevent small positions from opening.

Market orders use the platform's default execution timing, normally the next available tick after the signal. One tick is an instrument-specific price increment, not one percent. These simplified costs do not represent a broker quote or cover every spread, financing charge or gap. See the official strategy documentation for execution assumptions and settings.

1. RSI mean reversion

Enter when RSI recovers above 30. Exit when it crosses back below 70. This is not a sell at the first touch of 70: a position can remain open through a long decline if that exit never occurs.

//@version=5
strategy("SA example - RSI", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, pyramiding=0, commission_type=strategy.commission.percent, commission_value=0.1, slippage=1, margin_long=100)
rsiValue = ta.rsi(close, 14)
if ta.crossover(rsiValue, 30)
    strategy.entry("Long", strategy.long)
if ta.crossunder(rsiValue, 70)
    strategy.close("Long")

Investigate: Position duration and losses during persistent downtrends, not just the win rate. Exact-version verdict (judge, 6 Nov 2026, BTCUSDT, settings as printed): too few trades on 1d (3), 4h (4) and 1h (8). Judge the adapted version →

2. EMA ribbon: 8, 21 and 55

Enter when all three averages align upwards. Exit when the fastest falls below the middle average. The entry checks an alignment on each bar, not only the first crossover.

//@version=5
strategy("SA example - EMA ribbon", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, pyramiding=0, commission_type=strategy.commission.percent, commission_value=0.1, slippage=1, margin_long=100)
fast = ta.ema(close, 8)
middle = ta.ema(close, 21)
slow = ta.ema(close, 55)
if fast > middle and middle > slow
    strategy.entry("Long", strategy.long)
if fast < middle
    strategy.close("Long")
plot(fast, "EMA 8", color=color.teal)
plot(middle, "EMA 21", color=color.orange)
plot(slow, "EMA 55", color=color.gray)

Judge the adapted version in your browser → The online judge returns its verdict on BTCUSDT, with nothing to install. Since 6 November 2026 it also judges this exact script: verdict below; adapted versions in the verdicts.

Investigate: Repeated small losses and fees when the market changes direction frequently. Exact-version verdict (judge, 6 Nov 2026, BTCUSDT, settings as printed): mirage on 1d (11 trades), inconclusive on 4h (21), mirage on 1h (31).

3. Bollinger Band bounce

Enter below the lower band and exit above the upper band. A price below the band is an entry condition, not a guarantee of a rebound. The bands continue to move while the position is open.

//@version=5
strategy("SA example - Bollinger", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, pyramiding=0, commission_type=strategy.commission.percent, commission_value=0.1, slippage=1, margin_long=100)
[basis, upper, lower] = ta.bb(close, 20, 2.0)
if close < lower
    strategy.entry("Long", strategy.long)
if close > upper
    strategy.close("Long")
plot(upper, "Upper band", color=color.gray)
plot(lower, "Lower band", color=color.teal)

Investigate: The longest losing position and whether a few rebounds hide substantial unrealized losses. Exact-version verdict (judge, 6 Nov 2026, BTCUSDT, settings as printed): too few trades on 1d (8), mirage on 4h (14) and 1h (22). Judge the adapted version →

4. MACD crossover

Enter on a bullish MACD crossover and close on the inverse crossover. Both events use the standard 12/26/9 lengths; no parameter search has selected them for this page.

//@version=5
strategy("SA example - MACD", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, pyramiding=0, commission_type=strategy.commission.percent, commission_value=0.1, slippage=1, margin_long=100)
[macdLine, signalLine, histogram] = ta.macd(close, 12, 26, 9)
if ta.crossover(macdLine, signalLine)
    strategy.entry("Long", strategy.long)
if ta.crossunder(macdLine, signalLine)
    strategy.close("Long")

Investigate: How much of the gross result remains after frequent entries and exits. Exact-version verdict (judge, 6 Nov 2026, BTCUSDT, settings as printed): mirage on 1d (28 trades), inconclusive on 4h (49), mirage on 1h (65). Judge the adapted version →

5. SuperTrend direction filter

With ta.supertrend, a negative direction denotes the bullish state. This script uses that state to enter and the positive state to exit. The plotted line is not a stop order: there is no strategy.exit in this example.

//@version=5
strategy("SA example - SuperTrend", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, pyramiding=0, commission_type=strategy.commission.percent, commission_value=0.1, slippage=1, margin_long=100)
[trendLine, direction] = ta.supertrend(3, 10)
if direction < 0
    strategy.entry("Long", strategy.long)
if direction > 0
    strategy.close("Long")
plot(trendLine, "Trend filter", color=direction < 0 ? color.teal : color.orange)

Investigate: Reversals before the filter changes, and gaps between the signal and its simulated fill. Exact-version verdict (judge, 6 Nov 2026, BTCUSDT, settings as printed): too few trades on 1d (9), inconclusive on 4h (17 trades), mirage on 1h (24). Judge the adapted version →

6. Stochastic RSI

Enter when K crosses above D while K is below 20. Exit on a cross below D while K is above 80. Crossing D outside those zones does not trigger an order.

//@version=5
strategy("SA example - Stochastic RSI", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, pyramiding=0, commission_type=strategy.commission.percent, commission_value=0.1, slippage=1, margin_long=100)
rsiValue = ta.rsi(close, 14)
k = ta.sma(ta.stoch(rsiValue, rsiValue, rsiValue, 14), 3)
d = ta.sma(k, 3)
crossUp = ta.crossover(k, d)
crossDown = ta.crossunder(k, d)
if crossUp and k < 20
    strategy.entry("Long", strategy.long)
if crossDown and k > 80
    strategy.close("Long")

Investigate: Missing exits and periods with little activity. More conditions are not automatically better timing. Exact-version verdict (judge, 6 Nov 2026, BTCUSDT, settings as printed): mirage on 1d (14 trades), 4h (30) and 1h (33).

7. ATR breakout with a fixed stop

Enter above the previous 20-bar high when ATR exceeds its own 20-bar average. Fix the stop at two ATR below the signal close. This is neither a trailing stop nor a stop anchored to the later entry fill. It stays unchanged until the position closes.

//@version=5
strategy("SA example - ATR breakout", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, pyramiding=0, commission_type=strategy.commission.percent, commission_value=0.1, slippage=1, margin_long=100)
atrValue = ta.atr(14)
priorHigh = ta.highest(high, 20)[1]
atrAverage = ta.sma(atrValue, 20)
var float stopPrice = na
if strategy.position_size == 0
    stopPrice := na
    if close > priorHigh and atrValue > atrAverage
        stopPrice := close - 2 * atrValue
        strategy.entry("Long", strategy.long)
if not na(stopPrice)
    strategy.exit("ATR stop", "Long", stop=stopPrice)
plot(stopPrice, "Fixed stop", color=color.orange, style=plot.style_linebr)

Investigate: Next-bar gaps, intrabar assumptions and the requested stop versus its fill. A stop does not guarantee its execution price. There is no profit target or time exit. Exact-version verdict (judge, 6 Nov 2026, BTCUSDT, settings as printed): too few trades on 1d and 4h (8 and 0 trades in the training part, the proof needs 10 before it opens the sealed period), and too few trades on 1h (3).

Record a result you can compare

Keep these details with your report, including an unprofitable one:

Record Information needed
Script Exact code and settings, not just "RSI strategy"
Market Exchange, symbol, quote currency and chart type
History Interval, first and last bars, timezone and gaps
Execution Capital, sizing, margin, commission, slippage and fill settings
Outcome Net result, drawdown, closed trades and any position still open
Reference Buy-and-hold and cash under stated, comparable assumptions

Changing settings after looking at the outcome is exploration. It is useful, but it is not a fresh validation. Reserve another period before selecting a final candidate.

Check an example in the Lab, trade by trade

Copying a script into TradingView shows one report. To know whether the rule holds on data it was never tuned on, paste the Pine into the Lab, let the judge replay it trade by trade, then export it back to TradingView. Strategy Arena Lab is free for Windows (NVIDIA GPU optional) and Linux (CPU engine).

We pasted the seven scripts above into the Lab 241 Pine importer on 10 October 2026. This table is that dated check. The online judge is stricter since 31 October 2026: it refused all seven exact scripts until 6 November, and now judges all seven, and the downloadable Lab uses the same importer as the judge since version 254 (the 0.1.0-256 update adds SuperTrend, Stochastic RSI and the ATR stop). Start from the adapted versions. The Lab refuses a script rather than test a different strategy:

Example Lab 241 import Reason given by the Lab
RSI Accepted as is native path
EMA ribbon Accepted after 3 safe changes the three plot() lines stay on the TradingView side for visual review
Bollinger Bands Refused the exit strategy.close when close > upper band cannot be carried into a Lab exit, so the plan would not be the same strategy
MACD Refused the exit was read as a short entry, while the Pine is long-only
SuperTrend Refused same reason as MACD
Stochastic RSI Refused the importer supports ta.stoch(close, high, low, length) only
ATR breakout Refused the importer supports ta.sma(close, length) only (here ta.sma of the ATR)

For an accepted script, the judge runs it under TradingView's own rules (tv_exact_v1, the default since 241). In the real TradingView, the Lab's exports matched trade for trade: 234 of 234 for the 6 leaderboard strategies, 263 of 263 for the wider 241 export, and 361 of 361 on the short-with-margin-call case (Q7). Then the sealed proof scores the rule on a period kept closed during the search (PBO, deflated Sharpe, SPA test, CPCV, Monte Carlo) and returns a verdict: likely a mirage, inconclusive, not enough trades to judge, or survived the unseen test. The Pine v5 export covers SMA, EMA, RSI, ROC, Donchian, Bollinger and MACD (states, not band or MACD crosses), ATR stops and trailing stops.

A refused script is not a dead end: inside the Lab, your AI can report the missing piece, and requests reviewed by us are published on the AI loop. Research on past and simulated data, not advice.

FAQ

Do I need a Strategy Arena account to copy the code?

No. No Strategy Arena account or Lab installation is needed to copy the code; the examples are published with their complete scripts.

Which of the seven examples is easiest to start with?

For a first reading, the RSI example or the EMA ribbon has relatively few moving parts. Start with one complete script rather than running all seven at once.

Can these scripts be checked in Strategy Arena Lab?

Since 6 November 2026 the online judge accepts all seven exact scripts, slippage=1 included (counted as an extra fee of at most 0.04 bps per fill on BTCUSDT). On 31 October it also judged adapted versions of five of them. None survived on BTCUSDT.

Choose the next step

The seven exact scripts printed here have not been executed in TradingView as part of this revision: compilation and the trade list must still be checked in the platform. Only the adapted versions named above were compared with TradingView. There is no claim here that a simple indicator cannot outperform an AI-designed system: that question needs a matched experiment.

Revision note, 6 November 2026 (afternoon): the online judge runs the Lab 256 engine and now accepts the exact SuperTrend, Stochastic RSI and ATR breakout scripts too; their verdicts were added under each example. None of the seven survived.

Revision note, 6 November 2026: the online judge now counts slippage as an extra fee instead of refusing it, and gives verdicts on the exact RSI, EMA ribbon, Bollinger and MACD scripts; none survived.

Revision note, 31 October 2026: added the dated judge verdicts of the adapted versions, and corrected the link that sent the exact ribbon script to a refusal.

Revision note, 10 October 2026: added the Lab 241 import check of the seven examples; no performance figure was added.

Revision note, 13 September 2026: the former isolated return and comparison against AI strategies were removed because this article did not provide a matching dataset, period, execution settings and report.

⚠️ Disclaimer — This article is for informational and educational purposes only. It does not constitute investment advice or a buy/sell recommendation. Past performance does not guarantee future results. Strategy Arena is an educational simulator with virtual capital. Always do your own research before making investment decisions.

Enjoyed this article? Share it

𝕏 Share on X ✈️ Telegram

Turn a local result into durable proof

The Lab runs free on your PC. Paid options only keep or expand the work — they never change the verdict.

Get the Lab (free) Builder / Operator Publish a Lab Report Lab Reports Hall
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