Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

J2S Backtest- Steven Primo`s Big Trend Strategy

A Pine Script v5 strategy built on SMA (close, 20) and Stdev (close, 20). It has 9 order rules and no entry of its own. Exits use a stop loss and a profit target. Each trade commits 10% of equity and pays no commission. 15 settings; defaults include Bar indicating trend maturity 5, Bar limit for trading entry 5 and Bar limit for trading close 30.

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 J2S Backtest- Steven Primo`s Big Trend Strategy repaint?
No
No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
How did J2S Backtest- Steven Primo`s Big Trend Strategy do on BTCUSDT 1D with default settings?
Not measured
It closed no trades there from 26 Jan 2024 to 21 Oct 2026 with the default settings, so there is no result to report. Its code limits trading to a date window, which can leave this period out. It closed no trades on the other markets either. A backtest, not investment advice.
Does J2S Backtest- Steven Primo`s Big Trend Strategy run in Pine Script v6?
Not tested
Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download.
Does J2S Backtest- Steven Primo`s Big Trend Strategy use a stop loss?
Yes
strategy.exit sets a stop on line 87, 109.
Does J2S Backtest- Steven Primo`s Big Trend Strategy run in Zeal Terminal?
Yes
It compiles in 53 ms and runs 1,000 bars in 120 ms, in the browser.

BTCUSDT · 1D · default settings

  • SMA
  • BB High
  • BB Low
  • 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 (13)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$1,000$2,025Equity from $1,000
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. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
Net profit
0.00%
$0.00
Buy and hold
+102.5%
same period
Closed trades
0
0 won · 0 lost
Profitable
0.0%
of closed trades
Profit factor
—
gross profit ÷ gross loss
Max drawdown
0.00%
$0.00

One run with the author's default settings, $1,000 starting capital, commission as the script sets it. 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.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • 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
BACKTEST: STEVEN PRIMO'S BIG TREND STRATEGY
Long entrytrueboolline 76
Short entrytrueboolline 77
BACKTEST: METHOD
Bar indicating trend maturityEntries are made from the bar that indicates the trend maturity.5int · min 1result stopLossInLong stopLossInShort line 63 line 71
Bar limit for trading entryGiven a signal, entry must be reached within how many bars?5int · min 1cancel longEntryID cancel shortEntryID line 94 line 116
Bar limit for trading closeOnce a position is opened, close when it reaches the number of bars in trading.30int · min 1close tradeEntryID line 127
Profit over riskMultiplication factor based on the risk assumed in trading.15float · min 1 · step 0.5takeProfitInLong takeProfitInShort
BACKTEST: BOLLINGER BANDS
Length20int · min 1sma bbWidth
SMA Color Input (no label in the script)color.orangecolorSMA
Sourceclosesourcesma bbWidth
Factor0.382float · min 0.001 · max 50 · step 0.05bbWidth
BB Color Input (no label in the script)color.bluecolorBB High BB Low
Offset1intBB High BB Low SMA
BACKTEST: TIME PERIOD
Filter date range of backtesttrueboolinTradeWindow
Start dateuseStartDatetimeinTradeWindow
End dateuseEndDatetimeinTradeWindow

What it calculates

  • SMASource (close), Length (20)sma · line 47
  • StdevSource (close), Length (20)bbWidth · line 48

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 datasmaLengthInputLengthsetting · 20bbFactorInputFactorsetting · 0.382highhighprice datalowlowprice datamaturityIndexInputBar indicating trend ma…setting · 5profitOverRiskInputProfit over risksetting · 15timetimeprice databacktestStartDateInputStart datesetting · useStartDatebacktestEndDateInputEnd datesetting · useEndDatebarsLimitForEntryInputBar limit for trading e…setting · 5barLimitForCloseInputBar limit for trading c…setting · 30smaSMA→ smabbWidthStdev→ bbWidthbbHigh, bbLowbbHigh · bbLow2 valueslongEntryIDlongEntryIDvaluelongExitID, myLongOrder, shortExitID, myShortOrder, tradeEntryIDlongExitID · myLongOrde…5 valueslongEntryTriggerlongEntryTriggervaluestopLossInLongstopLossInLongvaluetakeProfitInLong, takeProfitInShorttakeProfitInLong · take…2 valuesshortEntryIDshortEntryIDvalueshortEntryTriggershortEntryTriggervaluestopLossInShortstopLossInShortvaluesplitPositionsplitPositionvalueentryBarentryBarvaluecloseIDcloseIDvalueinTradeWindowinTradeWindowconditionresultresultconditionbbBackgroundColor, candleColorDown, candleColorUp, insideBarColorDown, insideBarColorUp, downTrendColor, sidewaysTrendColor, upTrendColor, buySignalColor, sellSignalColorColourbbBackgroundColor · candleCol…order:longEntryIDorder longEntryIDstrategy.orderexit:longExitIDexit longExitIDstrategy.exitcancel:longEntryIDcancel longEntryIDstrategy.cancelorder:shortEntryIDorder shortEntryIDstrategy.orderexit:shortExitIDexit shortExitIDstrategy.exitcancel:shortEntryIDcancel shortEntryIDstrategy.cancelclose:tradeEntryIDClose tradeEntryIDstrategy.closecancel_all:cancel_all strategy.cancel_allclose_all:close_all strategy.close_allbarcolor:45barcolorbarcolorplot:51SMAplotplot:52BB Highplotplot:53BB Lowplotfill:BB BackgroundBB Backgroundfillplotshape:135Primo Buyplotshapeplotshape:136Primo Sellplotshape

Order rules

OrderFires whenBy defaultLine
order longEntryID longlongEntryHasBeenMet()On86
Exit longExitID stop and limitlongEntryHasBeenMet()On87
cancel longEntryIDbar_index - myLongOrder == barsLimitForEntryInputOn96
order shortEntryID shortshortEntryHasBeenMet()On108
Exit shortExitID stop and limitshortEntryHasBeenMet()On109
cancel shortEntryIDbar_index - myShortOrder == barsLimitForEntryInputOn118
Close tradeEntryIDbar_index - entryBar == barLimitForCloseInputOn129
cancel_all isBacktestDateRangeOver()On132
Close isBacktestDateRangeOver()On133

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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 1D0.0%+102.5%00%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%+5.5%00%—0.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%+9.8%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%+8.4%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%+16.7%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%+21.5%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%+148.3%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%+17.1%00%—0.0%8 May 2026 – 21 Oct 2026

Backtests are simulations on historical data and are not investment advice.

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
J2S Backtest- Steven Primo`s Big Trend Strategy this page—v5 strategy0.0%00.0%
Double Bollinger Binary Options by Trade_by_DBsma stdevv5 strategyNo trades on this market
Improved Bollinger Swing Strategy Stock Nasdaq by exlux99sma stdevv4 strategy−20.4%722.3%
I11L Long Put-Call Ratio Inversion by I11Lsma stdevv5 strategyNo trades on this market
P-Signal Strategy by Kharevskystdev smav4 strategy−9.7%2934.6%
P-Signal Strategy & Alert by Kharevskystdev smav4 strategy−9.7%2934.6%

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.

  • No v6-only features. v6 is not needed to run this script.

Clean v5

Verified

Nothing to change.

Does it run in Pine Script v6?

Not tested

Neither version placed a trade on any of the 8 markets, so there was nothing to compare. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © julianossilva-//@version=5+//@version=6strategy(title="J2S Backtest: Steven Primo`s Big Trend Strategy", shorttitle="J2S Backtest: Steven Primo`s Big Trend Strategy", overlay=true, initial_capital=1000, default_qty_value=10, default_qty_type=strategy.percent_of_equity, pyramiding=0)⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 53 msWith a workaround 1,000 bars in 120 msNot measured
PineTSNot testedNot testedNot measured

The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.

“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/// © julianossilva//@version=5strategy(title="J2S Backtest: Steven Primo`s Big Trend Strategy", shorttitle="J2S Backtest: Steven Primo`s Big Trend Strategy", overlay=true, initial_capital=1000, default_qty_value=10, default_qty_type=strategy.percent_of_equity, pyramiding=0)// Variables to control open ordersvar myLongOrders  = array.new_int(0)var myShortOrders = array.new_int(0)// Initial Backtest Date RangeuseStartDate = timestamp("01 Jan 2020 21:00:00")useEndDate   = timestamp("01 Jan 2023 21:00:00")// User InputsSIGNAL_CONFIG          = "BACKTEST: STEVEN PRIMO'S BIG TREND STRATEGY"longEntryInput         = input.bool(defval=true,          group=SIGNAL_CONFIG, title="Long entry")shortEntryInput        = input.bool(defval=true,          group=SIGNAL_CONFIG, title="Short entry")METHOD_CONFIG          = "BACKTEST: METHOD"maturityIndexInput     = input.int(defval=5,              group=METHOD_CONFIG, title="Bar indicating trend maturity", tooltip="Entries are made from the bar that indicates the trend maturity.", minval=1)barsLimitForEntryInput = input.int(defval=5,              group=METHOD_CONFIG, title="Bar limit for trading entry", tooltip="Given a signal, entry must be reached within how many bars?", minval=1)barLimitForCloseInput  = input.int(defval=30,             group=METHOD_CONFIG, title="Bar limit for trading close", tooltip="Once a position is opened, close when it reaches the number of bars in trading.", minval=1)profitOverRiskInput    = input.float(defval=15,           group=METHOD_CONFIG, title="Profit over risk", tooltip="Multiplication factor based on the risk assumed in trading.", minval=1, step=0.5)BB_CONFIG              = "BACKTEST: BOLLINGER BANDS"smaLengthInput         = input.int(defval=20,             group=BB_CONFIG,     inline="01", title="Length", minval=1)smaColorInput          = input.color(defval=color.orange, group=BB_CONFIG,     inline="01", title="")sourceInput            = input.source(defval=close,       group=BB_CONFIG,     inline="02", title="Source")bbFactorInput          = input.float(defval=0.382,        group=BB_CONFIG,     inline="03", title="Factor", minval=0.001, maxval=50, step=0.05)bbColorInput           = input.color(defval=color.blue,   group=BB_CONFIG,     inline="03", title="")offsetInput            = input.int(defval=1,              group=BB_CONFIG,     inline="04", title="Offset")PERIOD_CONFIG          = "BACKTEST: TIME PERIOD"useDateFilterInput     = input.bool(defval=true,          group=PERIOD_CONFIG, title="Filter date range of backtest")backtestStartDateInput = input.time(defval=useStartDate,  group=PERIOD_CONFIG, title="Start date")backtestEndDateInput   = input.time(defval=useEndDate,    group=PERIOD_CONFIG, title="End date")// ColorsbbBackgroundColor  = color.rgb(33, 150, 243, 90)candleColorDown    = color.rgb(239, 83, 80, 80)candleColorUp      = color.rgb(38, 166, 154, 70)insideBarColorDown = color.rgb(239, 83, 80, 40)insideBarColorUp   = color.rgb(38, 166, 154, 20)downTrendColor     = color.rgb(239, 83, 80, 80)sidewaysTrendColor = color.rgb(252, 232, 131, 80)upTrendColor       = color.rgb(38, 166, 154, 80)buySignalColor     = color.limesellSignalColor    = color.orange// CandlesisCandleUp()   => close > openisCandleDown() => close <= openbarcolor(isCandleUp() ? candleColorUp : isCandleDown() ? candleColorDown : na)// Bollinger Bands and Simple Moving Averagesma     = ta.sma(sourceInput, smaLengthInput)bbWidth = ta.stdev(sourceInput, smaLengthInput) * bbFactorInputbbHigh  = sma + bbWidthbbLow   = sma - bbWidthplot(sma, title="SMA", color=smaColorInput, offset=offsetInput)bbUpper = plot(bbHigh, title="BB High", color=bbColorInput, offset=offsetInput)bbLower = plot(bbLow,  title="BB Low",  color=bbColorInput, offset=offsetInput)fill(bbUpper, bbLower, title="BB Background", color=bbBackgroundColor)// Backtest Time PeriodinTradeWindow = not useDateFilterInput or (time >= backtestStartDateInput and time < backtestEndDateInput)isInTradeWindow() => inTradeWindowisBacktestDateRangeOver() => not inTradeWindow and inTradeWindow[1]// Rule that indicates maturity of trend to buyisPrimoBuy() =>    result = true    barIndex = 0    while result and barIndex < maturityIndexInput        result := close[barIndex] >= bbHigh[barIndex]        barIndex += 1    result := result and close[maturityIndexInput] < bbHigh[maturityIndexInput]// Rule that indicates maturity of trend to sellisPrimoSell() =>    result = true    barIndex = 0    while result and barIndex < maturityIndexInput        result := close[barIndex] <= bbLow[barIndex]        barIndex += 1    result := result and close[maturityIndexInput] > bbLow[maturityIndexInput]// Entry signalslongEntryHasBeenMet()  => longEntryInput  and isInTradeWindow() and isPrimoBuy()shortEntryHasBeenMet() => shortEntryInput and isInTradeWindow() and isPrimoSell()// Scheduling LONG entryif longEntryHasBeenMet()    array.push(myLongOrders, bar_index)    longEntryID = "Long Entry:\n" + str.tostring(bar_index)    longExitID  = "Long Exit:\n"  + str.tostring(bar_index)    longEntryTrigger = high + 1 * syminfo.mintick    stopLossInLong   = low[maturityIndexInput - 1]  - 1 * syminfo.mintick    takeProfitInLong = high + (high - low) * profitOverRiskInput    strategy.order(longEntryID, strategy.long, stop=longEntryTrigger)    strategy.exit(longExitID, longEntryID, stop=stopLossInLong, limit=takeProfitInLong)// In pine script, any order scheduled but not yet filled can be canceled.// Once a order is filled, the trade is only finished with use of close or exit functions.// As scheduled orders are not stored in the strategy.opentrades array, manual control is required.int myLongOrderIndex = 0while myLongOrderIndex < array.size(myLongOrders) and array.size(myLongOrders) > 0     myLongOrder = array.get(myLongOrders, myLongOrderIndex)    if bar_index - myLongOrder == barsLimitForEntryInput        longEntryID = "Long Entry:\n" + str.tostring(myLongOrder)        strategy.cancel(longEntryID)        array.remove(myLongOrders, myLongOrderIndex)        continue    myLongOrderIndex += 1// Scheduling SHORT entryif shortEntryHasBeenMet()    array.push(myShortOrders, bar_index)    shortEntryID = "Short Entry:\n" + str.tostring(bar_index)    shortExitID  = "Short Exit:\n"  + str.tostring(bar_index)    shortEntryTrigger = low  - 1 * syminfo.mintick    stopLossInShort   = high[maturityIndexInput - 1] + 1 * syminfo.mintick    takeProfitInShort = low - (high - low) * profitOverRiskInput    strategy.order(shortEntryID, strategy.short, stop=shortEntryTrigger)    strategy.exit(shortExitID, shortEntryID, stop=stopLossInShort, limit=takeProfitInShort)// In pine script, any order scheduled but not yet filled can be canceled.// Once a order is filled, the trade is only finished with use of close or exit functions.// As scheduled orders are not stored in the strategy.opentrades array, manual control is required.int myShortOrderIndex = 0while myShortOrderIndex < array.size(myShortOrders) and array.size(myShortOrders) > 0     myShortOrder = array.get(myShortOrders, myShortOrderIndex)    if bar_index - myShortOrder == barsLimitForEntryInput        shortEntryID = "Short Entry:\n" + str.tostring(myShortOrder)        strategy.cancel(shortEntryID)        array.remove(myShortOrders, myShortOrderIndex)        continue    myShortOrderIndex += 1// Trading must be stopped when candlestick limit reached in a tradingfor tradeNumber = 0 to strategy.opentrades - 1    tradeEntryID  = strategy.opentrades.entry_id(tradeNumber)    splitPosition = str.pos(tradeEntryID, ":")    entryBar      = str.tonumber(str.substring(tradeEntryID, splitPosition + 1))    if bar_index - entryBar == barLimitForCloseInput        closeID = "Close Position:\n" + str.tostring(entryBar)        strategy.close(id=tradeEntryID, comment=closeID, immediately=true)// Close all positions at the end of the backtest periodif isBacktestDateRangeOver()    strategy.cancel_all()    strategy.close_all(comment="Date Range Exit")// Display Signalsplotshape(series=longEntryHasBeenMet(),  title="Primo Buy",  style=shape.triangleup,   location=location.abovebar, color=buySignalColor,  text="Buy",  textcolor=buySignalColor)plotshape(series=shortEntryHasBeenMet(), title="Primo Sell", style=shape.triangledown, location=location.belowbar, color=sellSignalColor, text="Sell", textcolor=sellSignalColor)