Golden Cross SMA 50/200 — Pine Script v5 strategy
This script applies the most quoted moving-average cross: it buys when the 50-period simple moving average moves above the 200-period average, and sells when it falls back below. It trades very rarely, which keeps fees low but leaves few trades to judge.
Full code (free to copy)
//@version=5
strategy("SMA 50/200 Golden Cross", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1)
fastLen = input.int(50, "Fast SMA", minval=10, maxval=120)
slowLen = input.int(200, "Slow SMA", minval=80, maxval=400)
smaFast = ta.sma(close, fastLen)
smaSlow = ta.sma(close, slowLen)
if ta.crossover(smaFast, smaSlow)
strategy.entry("Long", strategy.long)
if ta.crossunder(smaFast, smaSlow)
strategy.close("Long")
plot(smaFast, "SMA 50", color=color.yellow)
plot(smaSlow, "SMA 200", color=color.blue)Judge this code on BTCUSDT 1D →Free, in your browser, on the same candles as the table below.
Online judge verdict on BTCUSDT (measured 29 November 2026)
| Timeframe | Sealed period | Trades | Return | Buy & hold | Verdict |
|---|---|---|---|---|---|
| 1d | The judge does not open the sealed period: 6 trades on the training part, at least 10 are needed. No return is shown. | Not enough trades to judge yet | |||
| 4h | 2026-03-12 → 2026-10-17 | 4 | 13.92 % | 15.83 % | Not enough trades to judge yet |
| 1h | 2026-08-05 → 2026-10-17 | 4 | 17.03 % | 27.14 % | Not enough trades to judge yet |
Past data, 10 bps per fill, last 20% of the bars sealed. Windows: full history on 1d, last 3 years on 4h, last year on 1h. Research, not advice: no result is promised.
This reading has not been compared with a real TradingView run.
Measured on 29 November 2026 with the online judge’s Pine v5 engine (sa-pine-vm 0.2.0), on Binance BTCUSDT candles up to 16/10/2026 on 1D and up to 17/10/2026 on 4h and 1h. Differences with TradingView’s Strategy Tester remain possible. Binance data, CC BY-NC-SA 4.0.
Open this code in the free judge (1 click) →
Replay each verdict yourself, in your browser: 1d · 4h · 1h. The script is filled in; nothing runs until you click “Judge”.
How the script works
Two inputs, fastLen (50) and slowLen (200), feed ta.sma(close, fastLen) and ta.sma(close, slowLen). Both averages use the close of each bar and are plotted on the chart.
ta.crossover(smaFast, smaSlow) triggers strategy.entry("Long", strategy.long); ta.crossunder(smaFast, smaSlow) triggers strategy.close("Long"). There is no stop and no target: the position stays open as long as the short average stays above the long one.
Parameters in the code
| Parameter | Value | Role |
|---|---|---|
fastLen | 50 | Input "Fast SMA" created with input.int, from 10 to 120. |
slowLen | 200 | Input "Slow SMA" created with input.int, from 80 to 400. |
initial_capital | 10000 | Starting capital declared in strategy(). |
default_qty_type | percent_of_equity, 100 | Each entry commits 100% of available equity. |
commission_value | 0.1 (%) | 0.10% commission per order declared in the script; the judge applies it (10 bps per fill). |
process_orders_on_close | not set | Orders fill at the open of the next bar, the Pine default. |
Known limits of this rule
- The 200 SMA reacts late: the entry often comes after much of the rise, the exit after much of the fall.
- With so few signals, a handful of trades decides the whole result; this is why the judge often answers "not enough trades".
- No stop in the code: a sharp drop is endured until the opposite cross.
Before you trust it: test it on data it never saw
A backtest in TradingView's Strategy Tester shows one past path with the settings you picked. Strategy Arena Lab (free, Windows and Linux) replays this Pine on your PC, compares its trades one by one with TradingView's for supported Pine, counts the variants you try, then judges the rule on a period kept sealed during the search: survives, no evidence of an edge or inconclusive.
FAQ
What does the online judge say about this script?
On BTCUSDT, with 10 bps fees per fill, measured on 29 November 2026: 1D: "Not enough trades to judge yet" (sealed period not opened, 6 training trades); 4h: "Not enough trades to judge yet" (4 trades, 13.92% on the sealed period); 1h: "Not enough trades to judge yet" (4 trades, 17.03% on the sealed period). No timeframe reaches "Survives". These verdicts concern past data and say nothing certain about the future.
Why does the judge not conclude on the Golden Cross?
The judge needs at least 10 trades on the training part and 10 on the sealed period. A 50/200 cross gives too few, especially on the daily timeframe: the verdict stays "not enough trades", which says neither that the rule works nor that it fails.
Can I change the script's settings?
Yes, the settings are inputs you can edit in TradingView. Each setting you try is one more trial: a setting chosen after seeing the sealed period is no longer a test on unseen data. The judge and the Lab count trials for this reason.
Other free Pine Script v5 strategies
More TradingView paths
Educational code on past data. No investment advice; no result is promised.