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
- 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| BACKTEST: STEVEN PRIMO'S BIG TREND STRATEGY | |||
| Long entry | true | bool | line 76 |
| Short entry | true | bool | line 77 |
| BACKTEST: METHOD | |||
| Bar indicating trend maturityEntries are made from the bar that indicates the trend maturity. | 5 | int · min 1 | result stopLossInLong stopLossInShort line 63 line 71 |
| Bar limit for trading entryGiven a signal, entry must be reached within how many bars? | 5 | int · min 1 | cancel 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. | 30 | int · min 1 | close tradeEntryID line 127 |
| Profit over riskMultiplication factor based on the risk assumed in trading. | 15 | float · min 1 · step 0.5 | takeProfitInLong takeProfitInShort |
| BACKTEST: BOLLINGER BANDS | |||
| Length | 20 | int · min 1 | sma bbWidth |
| SMA Color Input (no label in the script) | color.orange | color | SMA |
| Source | close | source | sma bbWidth |
| Factor | 0.382 | float · min 0.001 · max 50 · step 0.05 | bbWidth |
| BB Color Input (no label in the script) | color.blue | color | BB High BB Low |
| Offset | 1 | int | BB High BB Low SMA |
| BACKTEST: TIME PERIOD | |||
| Filter date range of backtest | true | bool | inTradeWindow |
| Start date | useStartDate | time | inTradeWindow |
| End date | useEndDate | time | inTradeWindow |
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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| order longEntryID long | longEntryHasBeenMet() | On | 86 |
| Exit longExitID stop and limit | longEntryHasBeenMet() | On | 87 |
| cancel longEntryID | bar_index - myLongOrder == barsLimitForEntryInput | On | 96 |
| order shortEntryID short | shortEntryHasBeenMet() | On | 108 |
| Exit shortExitID stop and limit | shortEntryHasBeenMet() | On | 109 |
| cancel shortEntryID | bar_index - myShortOrder == barsLimitForEntryInput | On | 118 |
| Close tradeEntryID | bar_index - entryBar == barLimitForCloseInput | On | 129 |
| cancel_all | isBacktestDateRangeOver() | On | 132 |
| Close | isBacktestDateRangeOver() | On | 133 |
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.
- 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 | 0.0% | +102.5% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | +5.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | +9.8% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | +8.4% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | +16.7% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | +21.5% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | +148.3% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | +17.1% | 0 | 0% | — | 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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| J2S Backtest- Steven Primo`s Big Trend Strategy this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| Double Bollinger Binary Options by Trade_by_DB | sma stdev | v5 strategy | No trades on this market | ||
| Improved Bollinger Swing Strategy Stock Nasdaq by exlux99 | sma stdev | v4 strategy | −20.4% | 7 | 22.3% |
| I11L Long Put-Call Ratio Inversion by I11L | sma stdev | v5 strategy | No trades on this market | ||
| P-Signal Strategy by Kharevsky | stdev sma | v4 strategy | −9.7% | 29 | 34.6% |
| P-Signal Strategy & Alert by Kharevsky | stdev sma | v4 strategy | −9.7% | 29 | 34.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
VerifiedNothing 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
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 53 ms | With a workaround 1,000 bars in 120 ms | Not measured |
| PineTS | Not tested | Not tested | Not 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)