Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

ChBrkOutStrategySMA

A Pine Script v4 strategy built on SMA (close, 9), Highest (high, 7) and Lowest (low, 7). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 1 setting; defaults include Length 7.

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 ChBrkOutStrategySMA 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 ChBrkOutStrategySMA do on BTCUSDT 1D with default settings?
−4.53%
From 26 Jan 2024 to 21 Oct 2026, over 42 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can ChBrkOutStrategySMA be converted to Pine Script v5?
Yes
The upgrade takes 1 step, from v4; each was run before and after on the same candles with identical results, and the v5 script can be downloaded below.
Does ChBrkOutStrategySMA use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does ChBrkOutStrategySMA run in Zeal Terminal?
Yes
It compiles in 10 ms and runs 1,000 bars in 32 ms, in the browser.

BTCUSDT · 1D · default settings

  • Upper Bound
  • Lower Bound
  • Fast SMA
  • Slow SMA
  • Avg
  • 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 (1)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOct$190,942$405,055Equity from $200,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. Zeal Terminal's engine currently reads an order side written as long = true, long = false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 21, 24) so the engine trades the way the script says.
Net profit
−4.53%
−$9,059.84
Buy and hold
+102.5%
same period
Closed trades
42
12 won · 30 lost
Profitable
28.6%
of closed trades
Profit factor
0.94
gross profit ÷ gross loss
Max drawdown
20.88%
−$44,562.30

One run with the author's default settings, $200,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 stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • 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.

  • Note

    Uses an argument v6 removed

    when = on line 31, 33. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 17

    transp = on line 17. v5 folds the transparency into the colour with color.new(c, transp).

  • Note

    Uses long =, which v5 renamed line 21

    long = on line 21, 24. v5 writes it as direction = strategy.long or strategy.short.

Upgrade and export

Written in Pine Script v4. The upgrade to v5 takes 1 step, one per version, each applied to the result of the one before. A last clean-v5 pass then types the settings and moves when = into if blocks, which v6 requires. Every step runs before and after on the same candles in Zeal Terminal's engine; a step whose results differ is shown but not offered as a download. Upgrades preserve behaviour: bugs are fixed in the Review, never silently here.

  • Upgrading to v5 renames sma → ta.sma, highest → ta.highest, lowest → ta.lowest, avg → math.avg, crossunder → ta.crossunder, crossover → ta.crossover.
  • 2 strategy calls use the when = argument (line 31, 33). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

Same 42 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 3: //@version=4 → //@version=5
  • Line 5: input(type = input.integer) → input.int()
  • Line 7: sma → ta.sma
  • Line 8: sma → ta.sma
  • Line 9: highest → ta.highest
  • Line 10: lowest → ta.lowest
6 more edits
  • Line 17: transp = 95 removed: the call sets no colour to fold it into, so its default colour loses the transparency
  • Line 18: avg → math.avg
  • Line 21: long = true → direction = strategy.long
  • Line 24: long = false → direction = strategy.short
  • Line 26: crossunder → ta.crossunder
  • Line 27: crossover → ta.crossover
⋯// © anshuanshu333-//@version=4+//@version=5strategy("ChBrkOutStrategySMA", overlay=true, initial_capital = 200000)-length = input(title="Length", type=input.integer, minval=1, maxval=1000, defval=7)+length = input.int(title="Length", minval=1, maxval=1000, defval=7)     -fastSMA = sma(close,9)+fastSMA = ta.sma(close,9)-slowSMA = sma(close,21)+slowSMA = ta.sma(close,21)-upBound = highest(high, length)+upBound = ta.highest(high, length)-downBound = lowest(low, length)+downBound = ta.lowest(low, length)boundLongEntry = ((close >= upBound) or (high >= upBound)) and fastSMA>slowSMA and (close > open)⋯plot(slowSMA,title = "Slow SMA" ,color = color.green, linewidth =1)-fill(u,l, transp=95)+fill(u,l)-plot(avg(upBound,downBound), title = "Avg", color=color.gray,linewidth =1)+plot(math.avg(upBound,downBound), title = "Avg", color=color.gray,linewidth =1)     if (boundLongEntry )-    strategy.entry("LE", long = true)+    strategy.entry("LE", direction = strategy.long)    if (boundShortEntry)-    strategy.entry("SE", long = false)+    strategy.entry("SE", direction = strategy.short)    -SmaLongExit = crossunder(fastSMA,slowSMA)+SmaLongExit = ta.crossunder(fastSMA,slowSMA)-SmaShortExit = crossover(fastSMA,slowSMA)+SmaShortExit = ta.crossover(fastSMA,slowSMA)    ⋯

Clean v5

VerifiedDownload the v5 script

Same 42 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 31: when = SmaLongExit → if block
  • Line 33: when = SmaShortExit → if block
⋯if (strategy.position_size > 0)-    strategy.close(id="LE",when= SmaLongExit)+    if SmaLongExit+        strategy.close(id="LE")if (strategy.position_size < 0)-    strategy.close(id="SE",when= SmaShortExit)+    if SmaShortExit+        strategy.close(id="SE")

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: 42 before, 52 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.

⋯// © anshuanshu333-//@version=5+//@version=6strategy("ChBrkOutStrategySMA", overlay=true, initial_capital = 200000)⋯

Settings

Every input the script declares, with its default and what it feeds. Bounds are the ones the script enforces.

SettingDefaultType and rangeFeeds
Length7int (written input.integer) · min 1 · max 1000upBound downBound

What it calculates

  • SMA (sma, ta.sma in v5)close, 9fastSMA · line 7
  • SMA (sma, ta.sma in v5)close, 21slowSMA · line 8
  • Highest (highest, ta.highest in v5)high, Length (7)upBound · line 9
  • Lowest (lowest, ta.lowest in v5)low, Length (7)downBound · line 10
  • Crossunder (crossunder, ta.crossunder in v5)fastSMA, slowSMASmaLongExit · line 26
  • Crossover (crossover, ta.crossover in v5)fastSMA, slowSMASmaShortExit · line 27

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 datahighhighprice datalengthLengthsetting · 7lowlowprice dataopenopenprice datafastSMASMA→ fastSMAslowSMASMA→ slowSMAupBoundHighest→ upBounddownBoundLowest→ downBoundSmaLongExitCrossunder→ SmaLongExitSmaShortExitCrossover→ SmaShortExitboundLongEntryboundLongEntryconditionboundShortEntryboundShortEntryconditionentry:LEOpen LEstrategy.entryentry:SEOpen SEstrategy.entryclose:LEClose LEstrategy.closeclose:SEClose SEstrategy.closeplot:13Upper Boundplotplot:14Lower Boundplotplot:15Fast SMAplotplot:16Slow SMAplotfill:17Fillfillplot:18Avgplot

Order rules

OrderFires whenBy defaultLine
Open LE long(boundLongEntry )On21
Open SE short(boundShortEntry)On24
Close LESmaLongExitOn31
Close SESmaShortExitOn33

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−4.5%+102.5%4229%0.9420.9%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h+0.1%+5.5%3842%1.017.1%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−0.1%+9.8%3743%0.961.5%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.1%+8.4%4425%1.210.2%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.0%+16.7%3845%0.820.1%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.0%+21.5%4028%1.040.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.3%+148.3%3636%1.930.2%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.0%+17.1%4134%1.140.1%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 market1315%−$36,805.80
Sideways market1942%$34,862.60
Falling market1020%−$7,116.69

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

34.3%

The 95th percentile of the worst drawdown when the same 42 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 17.0% to 34.3%; the tick is what actually happened, 17.2%. Order luck alone moves it this much.

0%39%
All 42 trades
SideEntryExitBarsP&L
long16 Feb 2024 51,880.0023 Mar 2024 63,796.6036$11,916.60
long9 Apr 2024 71,620.0014 Apr 2024 63,924.505−$7,695.48
short14 Apr 2024 63,924.5017 May 2024 65,235.2033−$1,310.69
long18 May 2024 67,024.0015 Jun 2024 66,044.0028−$980.01
short15 Jun 2024 66,044.0018 Jul 2024 64,088.0033$1,956.00
long20 Jul 2024 66,660.005 Aug 2024 58,161.0016−$8,499.01
short5 Aug 2024 58,161.0023 Aug 2024 60,375.8018−$2,214.83
long24 Aug 2024 64,037.203 Sep 2024 59,132.1010−$4,905.12
short7 Sep 2024 53,963.0017 Sep 2024 58,214.0010−$4,251.02
long18 Sep 2024 60,314.007 Oct 2024 62,819.9019$2,505.92
short11 Oct 2024 60,326.4017 Oct 2024 67,620.006−$7,293.60
long17 Oct 2024 67,620.0025 Dec 2024 98,663.6069$31,043.60
short31 Dec 2024 92,792.108 Jan 2025 96,954.608−$4,162.55
short14 Jan 2025 94,536.1018 Jan 2025 104,077.004−$9,541.36
long18 Jan 2025 104,077.004 Feb 2025 101,329.0017−$2,748.96
short19 Feb 2025 95,671.7026 Mar 2025 87,392.9035$8,278.86
short7 Apr 2025 78,430.0018 Apr 2025 84,947.9011−$6,517.92
long22 Apr 2025 87,516.204 Jun 2025 105,377.0043$17,860.70
short6 Jun 2025 101,509.0015 Jun 2025 105,415.009−$3,905.94
short21 Jun 2025 103,298.001 Jul 2025 107,147.0010−$3,848.53
long3 Jul 2025 108,850.001 Aug 2025 115,764.0029$6,914.48
short2 Aug 2025 113,298.0013 Aug 2025 120,134.0011−$6,836.17
long14 Aug 2025 123,306.0023 Aug 2025 116,936.009−$6,370.44
short25 Aug 2025 113,494.0012 Sep 2025 115,483.0018−$1,989.10
long12 Sep 2025 115,483.0027 Sep 2025 109,643.0015−$5,839.23
long6 Oct 2025 123,482.0016 Oct 2025 110,763.0010−$12,719.00
short18 Oct 2025 106,432.0031 Oct 2025 108,323.0013−$1,891.19
short5 Nov 2025 101,497.005 Dec 2025 92,078.1030$9,419.17
long10 Dec 2025 92,678.8017 Dec 2025 87,863.407−$4,815.38
short19 Dec 2025 85,516.403 Jan 2026 89,995.1015−$4,478.73
long3 Jan 2026 89,995.1024 Jan 2026 89,600.3021−$394.88
short26 Jan 2026 86,670.406 Mar 2026 70,891.0039$15,779.30
long14 Mar 2026 70,930.0027 Mar 2026 68,820.3013−$2,109.70
short28 Mar 2026 66,407.309 Apr 2026 71,069.9012−$4,662.65
long10 Apr 2026 71,788.0020 May 2026 76,834.4040$5,046.38
short23 May 2026 75,539.5022 Jun 2026 63,312.0030$12,227.50
short26 Jun 2026 59,794.609 Jul 2026 62,290.0013−$2,495.37
long15 Jul 2026 65,044.001 Aug 2026 62,887.9017−$2,156.11
short1 Aug 2026 62,887.9012 Aug 2026 63,600.0011−$712.13
long20 Aug 2026 69,334.8013 Sep 2026 77,278.7024$7,943.95
short16 Sep 2026 75,644.5022 Sep 2026 86,620.006−$10,975.50
long22 Sep 2026 86,620.0011 Oct 2026 82,988.4019−$3,631.66

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
ChBrkOutStrategySMA this page—v4 strategy−4.5%4220.9%
KDJ Strategy @ionvolution by ionvolutionsma highest lowestv5 strategyNo trades on this market
Trading range display with Box by potatoshopsma highest lowestv5 strategy+0.7%273.9%
Open Drive by Marcns_highest lowest smav5 strategyNo trades on this market
Trend Bounce [racer8] by racer8highest lowest smav4 strategy+2.4%2232.2%
Lawyers Trend Pro Strategy by ErdemDemirsma lowest highestv4 strategy+12.1%10241.7%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 10 msWith a workaround 1,000 bars in 32 msNot measured
PineTSNo v5 and v6 only—Not measured

Zeal Terminal's engine currently reads an order side written as long = true, long = false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 21, 24) so the engine trades the way the script says.

“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. PineTS runs Pine Script v5 and v6 only.

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/// © anshuanshu333//@version=4strategy("ChBrkOutStrategySMA", overlay=true, initial_capital = 200000)length = input(title="Length", type=input.integer, minval=1, maxval=1000, defval=7)     fastSMA = sma(close,9)slowSMA = sma(close,21)upBound = highest(high, length)downBound = lowest(low, length)boundLongEntry = ((close >= upBound) or (high >= upBound)) and fastSMA>slowSMA and (close > open)boundShortEntry =((close <= downBound) or (low <= downBound)) and fastSMA<slowSMA and (close <open)u=plot(upBound, title = "Upper Bound",color=color.blue, linewidth=1)l=plot(downBound, title = "Lower Bound",color=color.red, linewidth=1)plot(fastSMA,title = "Fast SMA", color = color.red, linewidth =2)plot(slowSMA,title = "Slow SMA" ,color = color.green, linewidth =1)fill(u,l, transp=95)plot(avg(upBound,downBound), title = "Avg", color=color.gray,linewidth =1)     if (boundLongEntry )    strategy.entry("LE", long = true)    if (boundShortEntry)    strategy.entry("SE", long = false)    SmaLongExit = crossunder(fastSMA,slowSMA)SmaShortExit = crossover(fastSMA,slowSMA)    //Close TRades   if (strategy.position_size > 0)    strategy.close(id="LE",when= SmaLongExit)if (strategy.position_size < 0)    strategy.close(id="SE",when= SmaShortExit)