7 Free Pine Script Strategies for TradingView (Code + Testing Guide)
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: no measured performance is attached to these exact versions.
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.
Run one example, not all seven at once
- Copy one complete script, starting with
//@version=5. - Open TradingView on the web, use a standard candlestick chart and paste the code into a new Pine strategy. Select Add to chart.
- Inspect the strategy report and a few individual trades. Note the exchange, symbol, interval, available dates and settings before comparing another run.

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 result: not measured here.
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)
Investigate: Repeated small losses and fees when the market changes direction frequently. Exact-version result: not measured here.
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 result: not measured here.
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 result: not measured here.
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 result: not measured here.
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 result: not measured here.
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 result: not measured here.
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.
Choose the next step
- First chart: continue the TradingView Starter. No strategy verdict is required to learn the interface.
- Conversion: check the Pine converter's supported subset. Not all built-ins or execution settings translate; do not assume these seven examples all import unchanged.
- Research: inspect the published benchmark snapshot. Its strategies and results are different from these educational scripts.
- A strategy of your own: open the free Quick Check. Compatibility comes before an optional independent audit; copying a script does not buy or trigger one.
No Pine version has been executed in TradingView as part of this article revision. Compilation and the trade list must still be checked in the platform. There is no claim here that a simple indicator cannot outperform an AI-designed system: that question needs a matched experiment.
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.