Pine Script v5 · Strategy
Quantitative Trend Strategy- Uptrend long
A Pine Script v5 strategy built on SMA (close, 20), Pivothigh (close, 46) and Pivotlow (close, 46). It has 7 order rules, 1 entry among them, and trades long only with the default settings. Exits use a stop loss and a profit target. Each trade commits 100% of equity and pays 0.01% commission. 7 settings; defaults include Length 20, Source close and Offset 0.
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 Quantitative Trend Strategy- Uptrend long repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 12 of 12 trades.
- How did Quantitative Trend Strategy- Uptrend long do on BTCUSDT 1D with default settings?
- +5.94%
- From 26 Jan 2024 to 21 Oct 2026, over 28 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Does Quantitative Trend Strategy- Uptrend long 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: 28 before, 37 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 Quantitative Trend Strategy- Uptrend long use a stop loss?
- Yes
- strategy.exit sets a stop on line 65, 67.
- Does Quantitative Trend Strategy- Uptrend long run in Zeal Terminal?
- Yes
- It compiles in 23 ms and runs 1,000 bars in 47 ms, in the browser.
BTCUSDT · 1D · default settings
- Basis
- Resistance
- Support
- p
- s
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +5.94%
- $89.12
- Buy and hold
- +102.5%
- same period
- Closed trades
- 28
- 5 won · 23 lost
- Profitable
- 17.9%
- of closed trades
- Profit factor
- 1.08
- gross profit ÷ gross loss
- Max drawdown
- 32.78%
- −$769.03
One run with the author's default settings, $1,500 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(vol, 20) ignores the settings line 27
Line 27 hard-codes 20 where line 7 uses “Length”. Changing those settings moves one band but not this one.
ta.sma(vol, 20)ta.sma(vol, length) -
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
1 setting has no label
In the settings dialog length (line 5) shows 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.
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 |
|---|---|---|---|
| Length (no label in the script) | 20 | int · min 1 | basis |
| Source | close | source | basis |
| Offset | 0 | int · min -500 · max 500 | Basis |
| LookbackLeft | 46 | int | l1 S1 |
| LookbackRight | 32 | int | l1 S1 |
| Take Profit | 2 | float | Take_S Take_L |
| Stop Loss | 1.75 | float | Stop_L Stop_S |
What it calculates
- SMASource (close), Length (20)
basis · line 7 - Pivothighclose, LookbackLeft (46), LookbackRight (32)
l1 · line 12 - Pivotlowclose, LookbackLeft (46), LookbackRight (32)
S1 · line 13 - Valuewhenl1, close, 0
l1V · line 16 - ValuewhenS1, close, 0
S1V · line 17 - SMAvol, 20
volma · line 27 - Valuewhenna(Plotl1), l1V, 0
Plotl1C · line 28 - Valuewhenna(PlotS1), S1V, 0
PlotS1C · line 29
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 | Lc1 | On | 37 |
| cancel Long | Priceforshort | On | 41 |
| cancel Short | Priceforlong | On | 43 |
| Close Long | strategy.openprofit >= 0 and sL | On | 49 |
| Close Short | strategy.openprofit >= 0 and sS | On | 51 |
| Exit Close Long stop and limit | strategy.position_size > 0 and not (Lc1) | On | 65 |
| Exit Close Short stop and limit | strategy.position_size < 0 and not (Sc1) | On | 67 |
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 | +5.9% | +102.5% | 28 | 18% | 1.08 | 32.8% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | +3.3% | +5.5% | 20 | 30% | 1.12 | 11.2% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −41.5% | +9.8% | 23 | 9% | 0.31 | 43.6% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +13.5% | +8.4% | 26 | 31% | 1.30 | 13.2% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −70.4% | +16.7% | 39 | 5% | 0.36 | 72.5% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +25.6% | +21.5% | 18 | 22% | 1.96 | 12.7% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | +20.4% | +148.3% | 22 | 23% | 1.36 | 19.2% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +4.0% | +17.1% | 23 | 35% | 1.13 | 15.4% | 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 | 7 | 29% | −$9.56 |
| Sideways market | 15 | 20% | $481.50 |
| Falling market | 6 | 0% | −$382.66 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
38.4%
The 95th percentile of the worst drawdown when the same 28 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 21.2% to 38.4%; the tick is what actually happened, 32.2%. Order luck alone moves it this much.
All 28 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 23 Apr 2024 66,819.30 | 25 Apr 2024 64,289.60 | 2 | −$57.08 |
| long | 16 May 2024 66,206.50 | 19 May 2024 67,530.60 | 3 | $28.56 |
| long | 20 May 2024 66,274.00 | 19 Jun 2024 65,114.20 | 30 | −$26.04 |
| long | 20 Jul 2024 66,660.00 | 25 Jul 2024 65,376.00 | 5 | −$28.13 |
| long | 26 Jul 2024 65,799.90 | 1 Aug 2024 64,628.00 | 6 | −$25.52 |
| long | 28 Sep 2024 65,769.90 | 30 Sep 2024 64,619.00 | 2 | −$24.63 |
| long | 15 Oct 2024 66,084.00 | 19 Jan 2025 104,556.00 | 96 | $795.50 |
| long | 22 Jan 2025 106,144.00 | 23 Jan 2025 103,707.00 | 1 | −$50.08 |
| long | 25 Jan 2025 104,871.00 | 27 Jan 2025 102,620.00 | 2 | −$45.75 |
| long | 31 Jan 2025 104,723.00 | 1 Feb 2025 102,430.00 | 1 | −$45.67 |
| long | 3 May 2025 96,887.10 | 4 May 2025 95,191.60 | 1 | −$35.77 |
| long | 7 May 2025 96,834.00 | 24 Jun 2025 105,334.00 | 48 | $173.84 |
| long | 25 Jun 2025 106,083.00 | 15 Sep 2025 115,268.00 | 82 | $186.49 |
| long | 16 Sep 2025 115,350.00 | 22 Sep 2025 113,331.00 | 6 | −$41.51 |
| long | 2 Oct 2025 118,595.00 | 11 Oct 2025 112,774.00 | 9 | −$113.53 |
| long | 10 Nov 2025 104,723.00 | 12 Nov 2025 102,890.00 | 2 | −$38.77 |
| long | 17 Feb 2026 68,892.40 | 18 Feb 2026 67,503.50 | 1 | −$43.81 |
| long | 5 Mar 2026 72,666.80 | 7 Mar 2026 68,114.00 | 2 | −$132.47 |
| long | 11 Mar 2026 69,948.60 | 23 Mar 2026 67,859.00 | 12 | −$59.40 |
| long | 24 Mar 2026 70,906.40 | 27 Mar 2026 68,820.30 | 3 | −$56.75 |
| long | 6 Apr 2026 69,034.20 | 3 Jun 2026 66,760.80 | 58 | −$61.59 |
| long | 14 Jun 2026 64,458.00 | 19 Jun 2026 62,958.00 | 5 | −$42.19 |
| long | 21 Jun 2026 64,298.00 | 22 Jun 2026 65,584.00 | 1 | $34.76 |
| long | 23 Jun 2026 64,020.00 | 24 Jun 2026 62,734.60 | 1 | −$36.30 |
| long | 6 Jul 2026 63,650.00 | 8 Jul 2026 62,536.10 | 2 | −$31.04 |
| long | 11 Jul 2026 64,161.70 | 14 Jul 2026 62,334.50 | 3 | −$49.41 |
| long | 15 Jul 2026 65,044.00 | 1 Aug 2026 62,887.90 | 17 | −$55.80 |
| long | 5 Aug 2026 64,106.60 | 13 Aug 2026 62,984.70 | 8 | −$28.63 |
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 |
|---|---|---|---|---|---|
| Quantitative Trend Strategy- Uptrend long this page | — | v5 strategy | +5.9% | 28 | 32.8% |
| Alert(), alertcondition() or strategy alerts- by Peter_O | sma pivothigh pivotlow valuewhen | v4 strategy | +7,640,000.0% | 191 | 919.9% |
| Moving Stop-Loss mechanism + alerts to MT4-MT5 by Peter_O | sma pivothigh pivotlow valuewhen | v5 strategy | −9,857,600.0% | 191 | 4,436.8% |
| TradingView Alerts to MT4 MT5 - Forex, indices, commodities by Peter_O | sma pivothigh pivotlow valuewhen | v4 strategy | −699,283.0% | 382 | 3,138.7% |
| Qullamaggie Breakout V2 by millerrh | sma pivothigh pivotlow valuewhen | v5 strategy | +35.4% | 33 | 16.9% |
| Golden Triangle Strategy by mohanee | sma pivothigh pivotlow | v4 strategy | +156.1% | 10 | 101.2% |
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.
- 1 setting uses the untyped input() (line 6). 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 28 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 6: input() → input.source()
⋯length = input.int(20, minval=1)-src = input(close, title="Source")+src = input.source(close, title="Source")basis = ta.sma(src, length)⋯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: 28 before, 37 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.
⋯// © CheatCode1-//@version=5+//@version=6strategy("Quantitative Trend Strategy- Uptrend long", 'Steady Uptrend Strategy', overlay=true, initial_capital = 1500, default_qty_value = 100, commission_type = strategy.commission.percent, commission_value = 0.01, default_qty_type = strategy.percent_of_equity)⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 23 ms | Yes 1,000 bars in 47 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/// © CheatCode1//@version=5strategy("Quantitative Trend Strategy- Uptrend long", 'Steady Uptrend Strategy', overlay=true, initial_capital = 1500, default_qty_value = 100, commission_type = strategy.commission.percent, commission_value = 0.01, default_qty_type = strategy.percent_of_equity)length = input.int(20, minval=1)src = input(close, title="Source")basis = ta.sma(src, length)offset = input.int(0, "Offset", minval = -500, maxval = 500)plot(basis, "Basis", color=#FF6D00, offset = offset)inp1 = input.int(46, 'LookbackLeft')inp2 = input.int(32, 'LookbackRight')l1 = ta.pivothigh(close, inp1, inp2)S1 = ta.pivotlow(close, inp1, inp2)// plot(l1, 'Pivothigh', color.red, 1)// // plot(S1, 'Pivot Low', color.red)l1V = ta.valuewhen(l1, close, 0)S1V = ta.valuewhen(S1, close, 0)Plotl1 = not na(l1) ? l1V : naPlotS1 = not na(S1) ? S1V : naplot(Plotl1, 'Resistance', color.green, 1, plot.style_stepline, true)plot(PlotS1, 'Support', color.red, 1, plot.style_stepline, true)Priceforlong = close > l1V ? true : naPriceforshort = close < S1V ? true : naplotshape(Priceforlong ? high : na, 'p', shape.arrowup, location.abovebar, color.green, size = size.small)plotshape(Priceforshort ? low : na, 's', shape.arrowdown, location.belowbar, color.red, size = size.small)vol = volumevolma = ta.sma(vol, 20)Plotl1C = ta.valuewhen(na(Plotl1), l1V, 0)PlotS1C = ta.valuewhen(na(PlotS1), S1V, 0)//Strategy Executionvolc = volume > volma Lc1 = Priceforlong Sc1 = PriceforshortsL = Plotl1 < PlotS1 ? close : nasS = PlotS1 > Plotl1 ? close : naif Lc1 strategy.entry('Long', strategy.long)// if Sc1 and C2// strategy.entry('Short', strategy.short)if Priceforshort strategy.cancel('Long')if Priceforlong strategy.cancel('Short')// Stp1 = ta.crossover(k, d)// Ltp1 = ta.crossunder(k, d)// Ltp = d > 70 ? Ltp1 : na// Stp = d < 30 ? Stp1 : naif strategy.openprofit >= 0 and sL strategy.close('Long')if strategy.openprofit >= 0 and sS strategy.close('Short')takeP = input.float(2, title='Take Profit') / 100stopL = input.float(1.75, title='Stop Loss') / 100// // Pre DirectionalityStop_L = strategy.position_avg_price * (1 - stopL)Stop_S = strategy.position_avg_price * (1 + stopL)Take_S= strategy.position_avg_price * (1 - takeP)Take_L = strategy.position_avg_price * (1 + takeP) // sL = Plotl1 < PlotS1 ? close : na// sS = PlotS1 < Plotl1 ? close : na // //Post Excecutionif strategy.position_size > 0 and not (Lc1) strategy.exit("Close Long", stop = Stop_L, limit = Take_L)if strategy.position_size < 0 and not (Sc1) strategy.exit("Close Short", stop = Stop_S, limit = Take_S)