Pine Script v5 · Strategy
Best TradingView Strategy - For NASDAQ and DOW30 and other Index
A Pine Script v5 strategy built on SMA (source1, 9), Stdev (source1, 9) and RMA or Change (14). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade is one contract and pays no commission. 9 settings; defaults include Length1 9, Mult1 2.0 and RSI Length 14.
Generated from the script's code by a template: every clause is a fact read from the source. Not written by a person or a model, and not taken from the author's description.
- Does Best TradingView Strategy - For NASDAQ and DOW30 and other Index repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 4 of 4 trades.
- How did Best TradingView Strategy - For NASDAQ and DOW30 and other Index do on BTCUSDT 1D with default settings?
- +2.25%
- From 26 Jan 2024 to 21 Oct 2026, over 17 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Best TradingView Strategy - For NASDAQ and DOW30 and other Index run in Pine Script v6?
- No
- The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 17 before, 17 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download.
- Does Best TradingView Strategy - For NASDAQ and DOW30 and other Index use a stop loss?
- Yes
- strategy.exit sets a stop on line 76, 77.
- Does Best TradingView Strategy - For NASDAQ and DOW30 and other Index run in Zeal Terminal?
- Yes
- It compiles in 30 ms and runs 1,000 bars in 67 ms, in the browser.
BTCUSDT · 1D · default settings
- RSI Upper Band
- RSI Middle Band
- RSI Lower Band
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +2.25%
- $22,480.70
- Buy and hold
- +102.5%
- same period
- Closed trades
- 17
- 10 won · 7 lost
- Profitable
- 58.8%
- of closed trades
- Profit factor
- 1.41
- gross profit ÷ gross loss
- Max drawdown
- 3.40%
- −$33,986.30
One run with the author's default settings, $1,000,000 starting capital, commission as the script sets it. A long position was still open at the last bar. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Likely bug
ta.sma(close, 14) ignores the settings line 60
Line 60 hard-codes 14 where line 9 uses “Length1”. Changing those settings moves one band but not this one.
ta.sma(close,14)ta.sma(close, length1) -
Likely bug
ta.sma(close, 42) ignores the settings line 61
Line 61 hard-codes 42 where line 9 uses “Length1”. Changing those settings moves one band but not this one.
ta.sma(close,42)ta.sma(close, length1) -
Likely bug
ta.change(high) ignores the settings line 47
Line 47 hard-codes high where line 29 uses “Source”. Changing those settings moves one band but not this one.
ta.change(high)ta.change(rsiSourceInput) -
Likely bug
ta.change(low) ignores the settings line 48
Line 48 hard-codes low where line 29 uses “Source”. Changing those settings moves one band but not this one.
ta.change(low)ta.change(rsiSourceInput) -
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
2 settings have no label
In the settings dialog length1 (line 7), mult1 (line 8) show an empty name. The labels on this page come from the variable names.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses an argument v6 removed
when = on line 76, 77. The upgraded version below moves each call inside an if block.
Settings
Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Length1 (no label in the script) | 9 | int · min 1 | basis1 dev1 |
| Mult1 (no label in the script) | 2.0 | float · min 0.001 · max 50 | dev1 |
| ADX Smoothing | 14 | int | adx sig |
| DI Length | 14 | int | plus minus sig |
| RSI Settings | |||
| RSI Length | 14 | int · min 1 | up down |
| Source | close | source | up down |
| MA Settings | |||
| MA Type | SMA | string · options ["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"] | rsiMA isBB |
| MA Length | 14 | int | rsiMA Upper Bollinger Band Lower Bollinger Band |
| BB StdDev | 2.0 | float · min 0.001 · max 50 | Upper Bollinger Band Lower Bollinger Band |
What it calculates
- SMAsource1, Length1 (9)
basis1 · line 9 - Stdevsource1, Length1 (9)
dev1 · line 10 - RMA / Changemath.max(ta.change(rsiSourceInput), 0), RSI Length (14)
up · line 29 - RMA / Change-math.min(ta.change(rsiSourceInput), 0), RSI Length (14)
down · line 30 - Changehigh
up1 · line 47 - Changelow
down1 · line 48 - RMAta.tr, len
truerange · line 51 - RMAmath.abs(plus - minus) / (sum == 0 ? 1 : sum), ADX Smoothing (14)
adx · line 58 - SMAclose, 14
out · line 60 - SMAclose, 42
sma1 · line 61 - EMAclose, 200
ema200 · line 62
Signal flow
How price data and settings reach the orders. Each box is a name in the script, or several computed the same way; each arrow is a value one of them reads. Hover a box for its members.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open long long | (longCondition ) | On | 65 |
| Open short short | (shortCondition ) | On | 69 |
| Exit longclose stop | ta.crossover(sma1,out) | On | 76 |
| Exit shortclose stop | ta.crossover(out,sma1) | On | 77 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- ClearHigher-timeframe dataThe script requests no other symbol or timeframe.
- ClearFuture-bar referencesNo negative history offsets such as close[-1].
- ClearIntrabar recalculationNo varip, calc_on_every_tick or realtime-only state. Orders are decided once per closed bar.
- ClearOrder timingOrders fill at the next bar's open, after the signal bar has closed.
The checks read the source; the replay runs it. Together they catch the common causes, not every possible one.
Other markets
The same script with default settings on 8 Binance markets. Each row is a separate backtest over the most recent 1,000 bars.
| Market | Net | Buy and hold | Trades | Won | Profit factor | Max drawdown | Period |
|---|---|---|---|---|---|---|---|
| BTCUSDT 1D | +2.2% | +102.5% | 17 | 59% | 1.41 | 3.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −0.9% | +5.5% | 18 | 50% | 0.71 | 2.6% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.2% | +9.8% | 16 | 69% | 1.77 | 0.2% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +0.0% | +8.4% | 15 | 80% | 1.31 | 0.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.0% | +16.7% | 15 | 67% | 2.47 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.0% | +21.5% | 18 | 33% | 0.36 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.0% | +148.3% | 16 | 81% | 0.99 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −0.0% | +17.1% | 17 | 65% | 0.62 | 0.0% | 8 May 2026 – 21 Oct 2026 |
Backtests are simulations on historical data and are not investment advice.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 5 | 40% | −$17,868.60 |
| Sideways market | 8 | 75% | $33,556.40 |
| Falling market | 4 | 50% | $6,792.84 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
4.2%
The 95th percentile of the worst drawdown when the same 17 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 1.8% to 4.2%; the tick is what actually happened, 2.7%. Order luck alone moves it this much.
All 17 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 21 Mar 2024 67,840.50 | 1 May 2024 60,672.00 | 41 | −$7,168.50 |
| short | 1 May 2024 60,672.00 | 13 Jun 2024 68,264.00 | 43 | −$7,591.97 |
| long | 13 Jun 2024 68,264.00 | 25 Jun 2024 60,293.30 | 12 | −$7,970.68 |
| short | 25 Jun 2024 60,293.30 | 3 Aug 2024 59,850.50 | 39 | $442.80 |
| long | 4 Aug 2024 60,698.00 | 10 Aug 2024 60,837.50 | 6 | $139.50 |
| short | 6 Sep 2024 56,180.00 | 3 Oct 2024 60,649.30 | 27 | −$4,469.27 |
| long | 3 Oct 2024 60,649.30 | 31 Dec 2024 92,791.60 | 89 | $32,142.30 |
| long | 4 Feb 2025 101,329.00 | 25 Feb 2025 91,552.90 | 21 | −$9,775.63 |
| short | 25 Feb 2025 91,552.90 | 7 Jun 2025 104,288.00 | 102 | −$12,735.50 |
| long | 7 Jun 2025 104,288.00 | 23 Jun 2025 106,074.00 | 16 | $1,785.27 |
| long | 3 Aug 2025 112,546.00 | 22 Aug 2025 117,429.00 | 19 | $4,882.20 |
| long | 24 Sep 2025 111,999.00 | 21 Oct 2025 114,000.00 | 27 | $2,000.70 |
| short | 5 Nov 2025 101,497.00 | 8 Jan 2026 91,364.70 | 64 | $10,132.60 |
| long | 22 Jan 2026 89,454.70 | 30 Jan 2026 84,650.20 | 8 | −$4,804.57 |
| short | 30 Jan 2026 84,650.20 | 15 Mar 2026 70,859.30 | 44 | $13,790.80 |
| long | 29 Mar 2026 66,377.00 | 2 Apr 2026 68,652.90 | 4 | $2,275.84 |
| short | 28 May 2026 74,449.30 | 15 Jul 2026 65,044.50 | 48 | $9,404.82 |
Similar scripts
Indicators and strategies built from the same calculations, run on BTCUSDT 1D with their own defaults so they can be compared directly.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Best TradingView Strategy - For NASDAQ and DOW30 and other Index this page | — | v5 strategy | +2.2% | 17 | 3.4% |
| Contrarian Scalping Counter Trend Bb Envelope Adx and Stochastic by exlux99 | sma stdev ema rma | v5 strategy | +1.9% | 15 | 3.2% |
| Strategy Myth-Busting #3 - BB_BUY+SuperTrend - [MYN] by myncrypto | ema sma stdev rma | v5 strategy | −115.1% | 6 | 123.3% |
| Volume Weighted Bollinger Bands Strategy by Ankit_1618 | ema sma stdev | v4 strategy | +10.0% | 15 | 27.5% |
| BB21_MA200_Strategy by mohanee | ema sma stdev | v4 strategy | No trades on this market | ||
| Optimized Keltner Channels SL-TP Strategy for BTC by chanu_lev10k | sma ema rma | v4 strategy | −19.4% | 36 | 70.0% |
Upgrade and export
Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.
- 2 strategy calls use the when = argument (line 76, 77). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
- 2 settings use the untyped input() (line 44, 45). It still compiles in v6; input.int, input.float or input.source state the type.
- No v6-only features. v6 is not needed to run this script.
Same 17 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 44: input() → input.int()
- Line 45: input() → input.int()
- Line 76: when = ta.crossover(sma1,out) → if block
- Line 77: when = ta.crossover(out,sma1) → if block
⋯//ADX-adxlen = input(14, title="ADX Smoothing")+adxlen = input.int(14, title="ADX Smoothing")-dilen = input(14, title="DI Length")+dilen = input.int(14, title="DI Length")dirmov(len) =>⋯tptgtshort=strategy.position_avg_price-100-strategy.exit("longclose","long",trail_offset=50,trail_points=200,when=ta.crossover(sma1,out))+if ta.crossover(sma1,out)+ strategy.exit("longclose","long",trail_offset=50,trail_points=200)-strategy.exit("shortclose","short",trail_offset=50,trail_points=200,when=ta.crossover(out,sma1))+if ta.crossover(out,sma1)+ strategy.exit("shortclose","short",trail_offset=50,trail_points=200) ⋯Does it run in Pine Script v6?
No
The v6 version runs in Zeal Terminal's engine, but its results differ from the v5 version: Trades differ: 17 before, 17 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine. It is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © The_Bigger_Bull-//@version=5+//@version=6strategy("Best TradingView Strategy", overlay=true, margin_long=0, margin_short=0)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 30 ms | Yes 1,000 bars in 67 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.
Source
Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © The_Bigger_Bull//@version=5strategy("Best TradingView Strategy", overlay=true, margin_long=0, margin_short=0)//Bollinger Bandssource1 = closelength1 = input.int(9, minval=1)mult1 = input.float(2.0, minval=0.001, maxval=50)basis1 = ta.sma(source1, length1)dev1 = mult1 * ta.stdev(source1, length1)upper1 = basis1 + dev1lower1 = basis1 - dev1//buyEntry = ta.crossover(source1, lower1)//sellEntry = ta.crossunder(source1, upper1)//RSIma(source, length, type) => switch type "SMA" => ta.sma(source, length) "Bollinger Bands" => ta.sma(source, length) "EMA" => ta.ema(source, length) "SMMA (RMA)" => ta.rma(source, length) "WMA" => ta.wma(source, length) "VWMA" => ta.vwma(source, length)rsiLengthInput = input.int(14, minval=1, title="RSI Length", group="RSI Settings")rsiSourceInput = input.source(close, "Source", group="RSI Settings")maTypeInput = input.string("SMA", title="MA Type", options=["SMA", "Bollinger Bands", "EMA", "SMMA (RMA)", "WMA", "VWMA"], group="MA Settings")maLengthInput = input.int(14, title="MA Length", group="MA Settings")bbMultInput = input.float(2.0, minval=0.001, maxval=50, title="BB StdDev", group="MA Settings")up = ta.rma(math.max(ta.change(rsiSourceInput), 0), rsiLengthInput)down = ta.rma(-math.min(ta.change(rsiSourceInput), 0), rsiLengthInput)rsi = down == 0 ? 100 : up == 0 ? 0 : 100 - (100 / (1 + up / down))rsiMA = ma(rsi, maLengthInput, maTypeInput)isBB = maTypeInput == "Bollinger Bands"//plot(rsi, "RSI", color=#7E57C2)//plot(rsiMA, "RSI-based MA", color=color.yellow)rsiUpperBand = hline(70, "RSI Upper Band", color=#787B86)hline(50, "RSI Middle Band", color=color.new(#787B86, 50))rsiLowerBand = hline(30, "RSI Lower Band", color=#787B86)fill(rsiUpperBand, rsiLowerBand, color=color.rgb(126, 87, 194, 90), title="RSI Background Fill")bbUpperBand = plot(isBB ? rsiMA + ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Upper Bollinger Band", color=color.green)bbLowerBand = plot(isBB ? rsiMA - ta.stdev(rsi, maLengthInput) * bbMultInput : na, title = "Lower Bollinger Band", color=color.green)fill(bbUpperBand, bbLowerBand, color= isBB ? color.new(color.green, 90) : na, title="Bollinger Bands Background Fill")//ADXadxlen = input(14, title="ADX Smoothing")dilen = input(14, title="DI Length")dirmov(len) => up1 = ta.change(high) down1 = -ta.change(low) plusDM = na(up1) ? na : (up1 > down1 and up1 > 0 ? up1 : 0) minusDM = na(down1) ? na : (down1 > up1 and down1 > 0 ? down1 : 0) truerange = ta.rma(ta.tr, len) plus = fixnan(100 * ta.rma(plusDM, len) / truerange) minus = fixnan(100 * ta.rma(minusDM, len) / truerange) [plus, minus]adx(dilen, adxlen) => [plus, minus] = dirmov(dilen) sum = plus + minus adx = 100 * ta.rma(math.abs(plus - minus) / (sum == 0 ? 1 : sum), adxlen)sig = adx(dilen, adxlen)out = ta.sma(close,14)sma1=ta.sma(close,42)ema200=ta.ema(close,200)longCondition = (out>sma1) and ta.crossover(source1, lower1) if (longCondition ) strategy.entry("long", strategy.long) shortCondition = (out<sma1) and ta.crossunder(source1, lower1) if (shortCondition ) strategy.entry("short", strategy.short) stopl=strategy.position_avg_price-50tptgt=strategy.position_avg_price+100stopshort=strategy.position_avg_price+50tptgtshort=strategy.position_avg_price-100strategy.exit("longclose","long",trail_offset=50,trail_points=200,when=ta.crossover(sma1,out))strategy.exit("shortclose","short",trail_offset=50,trail_points=200,when=ta.crossover(out,sma1)) //if strategy.position_avg_price<0 plot(sma1 , color=color.blue)plot(out, color=color.green)//plot(ema200,color=color.red)