Pine Script v5 · Strategy
J2S Backtest- 123-Stormer Strategy
A Pine Script v5 strategy built on EMA (close, 8), Highest (high, 3) and Lowest (low, 3). 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. 16 settings; defaults include Bar limit for trading entry 3, Bar limit for trading close 8 and Profit over risk 1.
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- 123-Stormer Strategy repaint?
- Yes
- At least one pattern in the source can repaint: higher-timeframe data.
- How did J2S Backtest- 123-Stormer 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- 123-Stormer 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- 123-Stormer Strategy use a stop loss?
- Yes
- strategy.exit sets a stop on line 135, 159.
- Does J2S Backtest- 123-Stormer Strategy run in Zeal Terminal?
- Yes
- It compiles in 48 ms and runs 1,000 bars in 131 ms, in the browser.
BTCUSDT · 1D · default settings
- Fast EMA
- Slow EMA
- 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: STORMER STRATEGY (123) | |||
| Long entry | true | bool | line 107 line 109 |
| Short entry | true | bool | line 113 line 115 |
| BACKTEST: METHOD | |||
| Bar limit for trading entryGiven a signal, entry must be reached within how many bars? | 3 | int · min 1 | cancel longEntryID cancel shortEntryID line 142 line 166 |
| Bar limit for trading closeOnce a position is opened, close when it reaches the number of bars in trading. | 8 | int · min 1 | close tradeEntryID line 177 |
| Profit over riskMultiplication factor based on the risk assumed in trading. The value range from stop-loss to trade entry is used to determine the profit target. This value range is multiplied by the value entered in 'profit over risk' parameter. | 1 | float · min 1 · step 0.5 | takeProfitInLong takeProfitInShort |
| Only third candle inside bar is validAccording to Stomer, it would be the best signal for the strategy | true | bool | line 106 line 112 |
| BACKTEST: EXPONENTIAL MOVING AVERAGES | |||
| Timeframe | 1W | timeframe | fastEMA currentFastEMA previousFastEMA slowEMA currentSlowEMA previousSlowEMA |
| Source | close | source | fastEMA currentFastEMA previousFastEMA slowEMA currentSlowEMA previousSlowEMA |
| Fast EMA length | 8 | int | fastEMA currentFastEMA previousFastEMA |
| Use | true | bool | line 54 line 56 line 61 line 63 Fast EMA line 80 line 82 line 90 line 92 |
| Slow EMA length | 80 | int | slowEMA currentSlowEMA previousSlowEMA |
| Use | true | bool | line 54 line 61 Slow EMA line 80 line 84 line 90 line 94 |
| Offset | 9 | int | Fast EMA Slow EMA |
| BACKTEST: TIME PERIOD | |||
| Filter date range of backtest | true | bool | inTradeWindow |
| Start date | useStartDate | time | inTradeWindow |
| End date | useEndDate | time | inTradeWindow |
What it calculates
- EMASource (close), Fast EMA length (8)
fastEMA · line 44 - EMASource (close), Fast EMA length (8)
currentFastEMA · line 45 - EMAsourceInput[1], Fast EMA length (8)
previousFastEMA · line 46 - EMASource (close), Slow EMA length (80)
slowEMA · line 47 - EMASource (close), Slow EMA length (80)
currentSlowEMA · line 48 - EMAsourceInput[1], Slow EMA length (80)
previousSlowEMA · line 49 - Highesthigh, 3
highestPrice · line 121 - Lowestlow, 3
lowestPrice · line 122
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 longtEntryID long | longEntryHasBeenMet | On | 134 |
| Exit longExitID stop and limit | longEntryHasBeenMet | On | 135 |
| cancel longEntryID | bar_index - myLongOrder == barLimitForEntryInput | On | 144 |
| order shortEntryID short | shortEntryHasBeenMet | On | 158 |
| Exit shortExitID stop and limit | shortEntryHasBeenMet | On | 159 |
| cancel shortEntryID | bar_index - myShortOrder == barLimitForEntryInput | On | 168 |
| Close tradeEntryID | bar_index - entryBar == barLimitForCloseInput | On | 179 |
| cancel_all | isBacktestDateRangeOver() | On | 182 |
| Close | isBacktestDateRangeOver() | On | 183 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Does it repaint?
Yes
At least one pattern in the source can repaint; it is marked Check below.
- CheckHigher-timeframe data6 request.security call(s) use lookahead_on (line 44, 45, 46, 47, 48, 49). Without a [1] offset this reads future bars in history.
- 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 |
Higher-timeframe data for request.security(): BINANCE:BTCUSDT 1W (Binance BTCUSDT 1w), fetched from Binance's public market data for each market.
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- 123-Stormer Strategy this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| CC Trend strategy 2- Downtrend Short by CheatCode1 | ema highest lowest | v5 strategy | No trades on this market | ||
| TrianglePoint strategy by mohanee | highest lowest ema | v4 strategy | +45.4% | 11 | 101.9% |
| Lagged Donchian Channel + EMA by Mysteriown | ema highest lowest | v4 strategy | −12.3% | 4 | 12.3% |
| Backtest Custom HiLo Strategy by luyikaibr | ema highest lowest | v4 strategy | No trades on this market | ||
| CM_SlingShotSystem+_CassicEMA+Willams21EMA13 htc1977 edition by Arivadis | ema highest lowest | v5 strategy | No trades on this market | ||
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: 123-Stormer Strategy", shorttitle="J2S Backtest: 123-Stormer 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 48 ms | With a workaround 1,000 bars in 131 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: 123-Stormer Strategy", shorttitle="J2S Backtest: 123-Stormer Strategy", overlay=true, initial_capital=1000, default_qty_value=10, default_qty_type=strategy.percent_of_equity, pyramiding=0)// Initial Backtest Date RangeuseStartDate = timestamp("01 Jan 2020 21:00:00")useEndDate = timestamp("01 Jan 2023 21:00:00")// User InputsSIGNAL_CONFIG = "BACKTEST: STORMER STRATEGY (123)"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"barLimitForEntryInput = input.int(defval=3, 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=8, 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=1, group=METHOD_CONFIG, title="Profit over risk", tooltip="Multiplication factor based on the risk assumed in trading. The value range from stop-loss to trade entry is used to determine the profit target. This value range is multiplied by the value entered in 'profit over risk' parameter.", minval=1, step=0.5)insideBarStrategyInput = input.bool(defval=true, group=METHOD_CONFIG, title="Only third candle inside bar is valid", tooltip="According to Stomer, it would be the best signal for the strategy")EMA_CONFIG = "BACKTEST: EXPONENTIAL MOVING AVERAGES"emaTimeframeInput = input.timeframe("1W", group=EMA_CONFIG, title="Timeframe")sourceInput = input.source(defval=close, group=EMA_CONFIG, title="Source")fastEMALengthInput = input.int(defval=8, group=EMA_CONFIG, inline="03", title="Fast EMA length ")useFastEMAInput = input.bool(defval=true, group=EMA_CONFIG, inline="03", title="Use")slowEMALengthInput = input.int(defval=80, group=EMA_CONFIG, inline="04", title="Slow EMA length ")useSlowEMAInput = input.bool(defval=true, group=EMA_CONFIG, inline="04", title="Use")emaOffsetInput = input.int(defval=9, group=EMA_CONFIG, 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")// ColorscandleColorDown = 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)// Exponential Moving AveragesfastEMA = request.security(syminfo.tickerid, emaTimeframeInput, ta.ema(sourceInput, fastEMALengthInput), barmerge.gaps_on, barmerge.lookahead_on)currentFastEMA = request.security(syminfo.tickerid, emaTimeframeInput, ta.ema(sourceInput, fastEMALengthInput), barmerge.gaps_off, barmerge.lookahead_on)previousFastEMA = request.security(syminfo.tickerid, emaTimeframeInput, ta.ema(sourceInput[1], fastEMALengthInput), barmerge.gaps_off, barmerge.lookahead_on)slowEMA = request.security(syminfo.tickerid, emaTimeframeInput, ta.ema(sourceInput, slowEMALengthInput), barmerge.gaps_on, barmerge.lookahead_on)currentSlowEMA = request.security(syminfo.tickerid, emaTimeframeInput, ta.ema(sourceInput, slowEMALengthInput), barmerge.gaps_off, barmerge.lookahead_on)previousSlowEMA = request.security(syminfo.tickerid, emaTimeframeInput, ta.ema(sourceInput[1], slowEMALengthInput), barmerge.gaps_off, barmerge.lookahead_on)// Trend Rules for Exponential Moving AveragesisSlowEMAUp() => currentSlowEMA > previousSlowEMAisSlowEMADown() => currentSlowEMA < previousSlowEMAisFastEMAUp() => if useFastEMAInput and useSlowEMAInput currentFastEMA > previousFastEMA and isSlowEMAUp() else if useFastEMAInput currentFastEMA > previousFastEMA else falseisFastEMADown() => if useFastEMAInput and useSlowEMAInput currentFastEMA < previousFastEMA and isSlowEMADown() else if useFastEMAInput currentFastEMA < previousFastEMA else false// Exponential Moving Average ColorsfastEMAColor = isFastEMAUp() ? upTrendColor : isFastEMADown() ? downTrendColor : sidewaysTrendColorslowEMAColor = isSlowEMAUp() ? upTrendColor : isSlowEMADown() ? downTrendColor : sidewaysTrendColor// Display Exponential Moving Averagesplot(useFastEMAInput ? fastEMA : na, offset=emaOffsetInput, color=fastEMAColor, title="Fast EMA", style=plot.style_line, linewidth=4)plot(useSlowEMAInput ? slowEMA : na, offset=emaOffsetInput, color=slowEMAColor, title="Slow EMA", style=plot.style_line, linewidth=7)// Price TrendpricesAboveFastEMA() => low[2] > currentFastEMA and low[1] > currentFastEMA and low > currentFastEMApricesAboveSlowEMA() => low[2] > currentSlowEMA and low[1] > currentSlowEMA and low > currentSlowEMApricesBelowFastEMA() => high[2] < currentFastEMA and high[1] < currentFastEMA and high < currentFastEMApricesBelowSlowEMA() => high[2] < currentSlowEMA and high[1] < currentSlowEMA and high < currentSlowEMA// Market in Bullish TrendisBullishTrend() => if useFastEMAInput and useSlowEMAInput pricesAboveFastEMA() and pricesAboveSlowEMA() else if useFastEMAInput pricesAboveFastEMA() else if useSlowEMAInput pricesAboveSlowEMA() else na// Market in Bearish TrendisBearishTrend() => if useFastEMAInput and useSlowEMAInput pricesBelowFastEMA() and pricesBelowSlowEMA() else if useFastEMAInput pricesBelowFastEMA() else if useSlowEMAInput pricesBelowSlowEMA() else na// Stormer Strategy (123)isFirstCandleUp() => high[2] > high[1] and low[2] > low[1]isFirstCandleDown() => high[2] < high[1] and low[2] < low[1]isThirdCandleUp() => low > low[1]isThirdCandleDown() => high < high[1]isThirdCandleInsideBar() => high < high[1] and low > low[1]// Buy SignalisStormer123Buy() => if insideBarStrategyInput longEntryInput and isFirstCandleUp() and isThirdCandleInsideBar() and isBullishTrend() else longEntryInput and isFirstCandleUp() and isThirdCandleUp() and isBullishTrend()// Sell SignalisStormer123Sell() => if insideBarStrategyInput shortEntryInput and isFirstCandleDown() and isThirdCandleInsideBar() and isBearishTrend() else shortEntryInput and isFirstCandleDown() and isThirdCandleDown() and isBearishTrend()// Backtest Time PeriodinTradeWindow = not useDateFilterInput or (time >= backtestStartDateInput and time < backtestEndDateInput)isInTradeWindow() => inTradeWindowisBacktestDateRangeOver() => not inTradeWindow and inTradeWindow[1]// Backtest Price ParametershighestPrice = ta.highest(high, 3)lowestPrice = ta.lowest(low,3)priceRange = highestPrice - lowestPrice// Stormer Strategy (123): LONGvar myLongOrders = array.new_int(0)longtEntryID = "Long Entry:\n" + str.tostring(bar_index)longExitID = "Long Exit:\n" + str.tostring(bar_index)stopLossInLong = lowestPrice + 1 * syminfo.minticktakeProfitInLong = high + priceRange * profitOverRiskInputlongEntryHasBeenMet = isInTradeWindow() and isBullishTrend() and isStormer123Buy()// Scheduling LONG entryif longEntryHasBeenMet array.push(myLongOrders, bar_index) strategy.order(longtEntryID, strategy.long, stop=high) strategy.exit(longExitID, longtEntryID, 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 == barLimitForEntryInput longEntryID = "Long Entry:\n" + str.tostring(myLongOrder) strategy.cancel(longEntryID) array.remove(myLongOrders, myLongOrderIndex) continue myLongOrderIndex += 1// Stormer Strategy (123): SHORTvar myShortOrders = array.new_int(0)shortEntryID = "Short Entry:\n" + str.tostring(bar_index)shortExitID = "Short Exit:\n" + str.tostring(bar_index)stopLossInShort = highestPrice + 1 * syminfo.minticktakeProfitInShort = low - priceRange * profitOverRiskInputshortEntryHasBeenMet = isInTradeWindow() and isBearishTrend() and isStormer123Sell()// Scheduling SHORT entryif shortEntryHasBeenMet array.push(myShortOrders, bar_index) strategy.order(shortEntryID, strategy.short, stop=low) 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 == barLimitForEntryInput 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="123 Buy", style=shape.triangleup, location=location.abovebar, color=buySignalColor, text="Buy", textcolor=buySignalColor)plotshape(series=shortEntryHasBeenMet, title="123 Sell", style=shape.triangledown, location=location.belowbar, color=sellSignalColor, text="Sell", textcolor=sellSignalColor)