Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (7)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$2,086$3,038Equity from $1,500
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
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.

SettingDefaultType and rangeFeeds
Length (no label in the script)20int · min 1basis
Sourceclosesourcebasis
Offset0int · min -500 · max 500Basis
LookbackLeft46intl1 S1
LookbackRight32intl1 S1
Take Profit2floatTake_S Take_L
Stop Loss1.75floatStop_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, 0l1V · line 16
  • ValuewhenS1, close, 0S1V · line 17
  • SMAvol, 20volma · line 27
  • Valuewhenna(Plotl1), l1V, 0Plotl1C · line 28
  • Valuewhenna(PlotS1), S1V, 0PlotS1C · 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.

closecloseprice datalengthLengthsetting · 20inp1LookbackLeftsetting · 46inp2LookbackRightsetting · 32volumevolumeprice datastopLStop Losssetting · 1.75takePTake Profitsetting · 2highhighprice datalowlowprice databasisSMA→ basisl1Pivothigh→ l1S1Pivotlow→ S1l1VValuewhen→ l1VS1VValuewhen→ S1VvolmaSMA→ volmaPlotl1CValuewhen→ Plotl1CPlotS1CValuewhen→ PlotS1CPlotl1Plotl1valuePlotS1PlotS1valuePriceforlongPriceforlongvaluePriceforshortPriceforshortvaluevolvolvalueLc1Lc1valueSc1Sc1valuesL, sSsL · sS2 valuesStop_L, Stop_SStop_L · Stop_S2 valuesTake_S, Take_LTake_S · Take_L2 valuesvolcvolcconditionentry:LongOpen Longstrategy.entrycancel:Longcancel Longstrategy.cancelcancel:Shortcancel Shortstrategy.cancelclose:LongClose Longstrategy.closeclose:ShortClose Shortstrategy.closeexit:Close Longexit Close Longstrategy.exitexit:Close Shortexit Close Shortstrategy.exitplot:9Basisplotplot:20Resistanceplotplot:21Supportplotplotshape:24plotshapeplotshapeplotshape:25plotshapeplotshape

Order rules

OrderFires whenBy defaultLine
Open Long longLc1On37
cancel LongPriceforshortOn41
cancel ShortPriceforlongOn43
Close Longstrategy.openprofit >= 0 and sLOn49
Close Shortstrategy.openprofit >= 0 and sSOn51
Exit Close Long stop and limitstrategy.position_size > 0 and not (Lc1)On65
Exit Close Short stop and limitstrategy.position_size < 0 and not (Sc1)On67

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.

12/12trades identical when replayed liveThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, four per bar, and compared with the historical run. Orders are decided once per closed bar, so nothing can change mid-bar.
  • 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.

MarketNetBuy and holdTradesWonProfit factorMax drawdownPeriod
BTCUSDT 1D+5.9%+102.5%2818%1.0832.8%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+3.3%+5.5%2030%1.1211.2%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−41.5%+9.8%239%0.3143.6%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+13.5%+8.4%2631%1.3013.2%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−70.4%+16.7%395%0.3672.5%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+25.6%+21.5%1822%1.9612.7%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+20.4%+148.3%2223%1.3619.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+4.0%+17.1%2335%1.1315.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 barsTradesWonP&L
Rising market729%−$9.56
Sideways market1520%$481.50
Falling market60%−$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.

0%44%
All 28 trades
SideEntryExitBarsP&L
long23 Apr 2024 66,819.3025 Apr 2024 64,289.602−$57.08
long16 May 2024 66,206.5019 May 2024 67,530.603$28.56
long20 May 2024 66,274.0019 Jun 2024 65,114.2030−$26.04
long20 Jul 2024 66,660.0025 Jul 2024 65,376.005−$28.13
long26 Jul 2024 65,799.901 Aug 2024 64,628.006−$25.52
long28 Sep 2024 65,769.9030 Sep 2024 64,619.002−$24.63
long15 Oct 2024 66,084.0019 Jan 2025 104,556.0096$795.50
long22 Jan 2025 106,144.0023 Jan 2025 103,707.001−$50.08
long25 Jan 2025 104,871.0027 Jan 2025 102,620.002−$45.75
long31 Jan 2025 104,723.001 Feb 2025 102,430.001−$45.67
long3 May 2025 96,887.104 May 2025 95,191.601−$35.77
long7 May 2025 96,834.0024 Jun 2025 105,334.0048$173.84
long25 Jun 2025 106,083.0015 Sep 2025 115,268.0082$186.49
long16 Sep 2025 115,350.0022 Sep 2025 113,331.006−$41.51
long2 Oct 2025 118,595.0011 Oct 2025 112,774.009−$113.53
long10 Nov 2025 104,723.0012 Nov 2025 102,890.002−$38.77
long17 Feb 2026 68,892.4018 Feb 2026 67,503.501−$43.81
long5 Mar 2026 72,666.807 Mar 2026 68,114.002−$132.47
long11 Mar 2026 69,948.6023 Mar 2026 67,859.0012−$59.40
long24 Mar 2026 70,906.4027 Mar 2026 68,820.303−$56.75
long6 Apr 2026 69,034.203 Jun 2026 66,760.8058−$61.59
long14 Jun 2026 64,458.0019 Jun 2026 62,958.005−$42.19
long21 Jun 2026 64,298.0022 Jun 2026 65,584.001$34.76
long23 Jun 2026 64,020.0024 Jun 2026 62,734.601−$36.30
long6 Jul 2026 63,650.008 Jul 2026 62,536.102−$31.04
long11 Jul 2026 64,161.7014 Jul 2026 62,334.503−$49.41
long15 Jul 2026 65,044.001 Aug 2026 62,887.9017−$55.80
long5 Aug 2026 64,106.6013 Aug 2026 62,984.708−$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.

ScriptSharesTypeNetTradesMax drawdown
Quantitative Trend Strategy- Uptrend long this page—v5 strategy+5.9%2832.8%
Alert(), alertcondition() or strategy alerts- by Peter_Osma pivothigh pivotlow valuewhenv4 strategy+7,640,000.0%191919.9%
Moving Stop-Loss mechanism + alerts to MT4-MT5 by Peter_Osma pivothigh pivotlow valuewhenv5 strategy−9,857,600.0%1914,436.8%
TradingView Alerts to MT4 MT5 - Forex, indices, commodities by Peter_Osma pivothigh pivotlow valuewhenv4 strategy−699,283.0%3823,138.7%
Qullamaggie Breakout V2 by millerrhsma pivothigh pivotlow valuewhenv5 strategy+35.4%3316.9%
Golden Triangle Strategy by mohaneesma pivothigh pivotlowv4 strategy+156.1%10101.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.

Clean v5

VerifiedDownload the v5 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 23 msYes 1,000 bars in 47 msNot measured
PineTSNot testedNot testedNot 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)