Pine Script v4 · Strategy
Dazzling Bolts
A Pine Script v4 strategy built on SMA (close, 10), EMA (close, 55) and ATR (12). It has 6 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss and a profit target. Each trade is one contract and pays no commission. 10 settings; defaults include SMMA Period 10, Source close and EMA Period 55.
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 Dazzling Bolts repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 4 of 4 trades.
- How did Dazzling Bolts do on BTCUSDT 1D with default settings?
- +8.45%
- From 26 Jan 2024 to 21 Oct 2026, over 14 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Dazzling Bolts be converted to Pine Script v5?
- No
- The automatic step from v4 to v5 changes the results, so no v5 download is offered; the edits are shown below.
- Does Dazzling Bolts use a stop loss?
- Yes
- strategy.exit sets a stop on line 38, 43.
- Does Dazzling Bolts run in Zeal Terminal?
- Yes
- It compiles in 24 ms and runs 1,000 bars in 38 ms, in the browser.
BTCUSDT · 1D · default settings
- Purple
- Purple
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +8.45%
- $8,451.72
- Buy and hold
- +102.5%
- same period
- Closed trades
- 14
- 7 won · 7 lost
- Profitable
- 50.0%
- of closed trades
- Profit factor
- 1.22
- gross profit ÷ gross loss
- Max drawdown
- 13.04%
- −$15,983.90
One run with the author's default settings, $100,000 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
sma(close, smalength) ignores the settings line 16
Line 16 hard-codes close where line 10 uses “Source”. Changing those settings moves one band but not this one.
sma(close, smalength)sma(src, smalength) -
Check
No commission
The backtest assumes free trading. Results on any real exchange will be lower.
-
Note
1 setting has no label
In the settings dialog offsetemavalue (line 18) 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.
-
Note
Uses transp =, which v5 removed line 21
transp = on line 21, 22. v5 folds the transparency into the colour with color.new(c, transp).
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, ema → ta.ema, floor → math.floor, atr → ta.atr, barssince → ta.barssince, crossover → ta.crossover, crossunder → ta.crossunder.
v4 → v5
DiffersTrades differ: 14 before, 19 after on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 10: sma → ta.sma
- Line 13: ema → ta.ema
- Line 16: sma → ta.sma
- Line 17: input(type = input.bool) → input.bool()
- Line 21: transp = 0 → color.new(#ff33cc, 0)
10 more edits
- Line 22: transp = 0 → color.new(#ff33cc, 0)
- Line 23: floor → math.floor
- Line 24: input(type = input.bool) → input.bool()
- Line 25: input(type = input.bool) → input.bool()
- Line 27: input(type = input.float) → input.float()
- Line 28: atr → ta.atr
- Line 33: barssince → ta.barssince
- Line 35: barssince → ta.barssince
- Line 39: crossover → ta.crossover
- Line 44: crossunder → ta.crossunder
⋯// © greenmask9-//@version=4+//@version=5strategy("Dazzling Bolts", overlay=true)⋯smma = 0.0-smma := na(smma[1]) ? sma(src, len) : (smma[1] * (len - 1) + src) / len+smma := na(smma[1]) ? ta.sma(src, len) : (smma[1] * (len - 1) + src) / len// 55 EMAemalength = input(55, title="EMA Period")-ema = ema(close, emalength)+ema = ta.ema(close, emalength)// 100 SMAsmalength = input(110, title="SMA Period")-sma = sma(close, smalength)+sma = ta.sma(close, smalength)-emaforce = input(title="Force trend with medium EMA", type=input.bool, defval=true)+emaforce = input.bool(title="Force trend with medium EMA", defval=true)offsetemavalue = input(defval = 6)⋯bearbounce = smma<ema and ema<sma and high[5]<ema and high[2]>ema and close[1]<ema and (ema[offsetemavalue]<sma or (not emaforce))-plotshape(bullbounce, title= "Purple", location=location.belowbar, color=#ff33cc, transp=0, style=shape.triangleup, size=size.tiny, text="Bolts")+plotshape(bullbounce, title= "Purple", location=location.belowbar, color=color.new(#ff33cc, 0), style=shape.triangleup, size=size.tiny, text="Bolts")-plotshape(bearbounce, title= "Purple", location=location.abovebar, color=#ff33cc, transp=0, style=shape.triangledown, size=size.tiny, text="Bolts")+plotshape(bearbounce, title= "Purple", location=location.abovebar, color=color.new(#ff33cc, 0), style=shape.triangledown, size=size.tiny, text="Bolts")-ordersize=floor(strategy.initial_capital/close)+ordersize=math.floor(strategy.initial_capital/close)-longs = input(title="Test longs", type=input.bool, defval=true)+longs = input.bool(title="Test longs", defval=true)-shorts = input(title="Test shorts", type=input.bool, defval=true)+shorts = input.bool(title="Test shorts", defval=true)atrlength = input(title="ATR length", defval=12)-atrm = input(title="ATR muliplier",type=input.float, defval=2)+atrm = input.float(title="ATR muliplier", defval=2)-atr = atr(atrlength)+atr = ta.atr(atrlength)target = close + atr*atrm⋯bullbuy = bullbounce and longs and strategy.opentrades==0-bb = barssince(bullbuy)+bb = ta.barssince(bullbuy)bearsell = bearbounce and shorts and strategy.opentrades==0-bs = barssince(bearsell)+bs = ta.barssince(bearsell)if (bullbuy)⋯ strategy.exit ("Bolts.close", from_entry="Boltsup", limit=target, stop=antitarget)-if (crossover(smma, sma))+if (ta.crossover(smma, sma)) strategy.close("Boltsup", qty_percent = 100, comment = "Bolts.crossover")⋯ strategy.exit("Bolts.close", from_entry="Boltsdown", limit=antitarget, stop=target)-if (crossunder(smma, sma))+if (ta.crossunder(smma, sma)) strategy.close("Boltsdown", qty_percent = 100, comment = "Bolts.crossover")⋯Clean v5
VerifiedSame 19 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 7: input() → input.int()
- Line 8: input() → input.source()
- Line 12: input() → input.int()
- Line 15: input() → input.int()
- Line 18: input() → input.int()
- Line 26: input() → input.int()
⋯// 13 SMMA-len = input(10, minval=1, title="SMMA Period")+len = input.int(10, minval=1, title="SMMA Period")-src = input(close, title="Source")+src = input.source(close, title="Source")smma = 0.0⋯// 55 EMA-emalength = input(55, title="EMA Period")+emalength = input.int(55, title="EMA Period")ema = ta.ema(close, emalength)// 100 SMA-smalength = input(110, title="SMA Period")+smalength = input.int(110, title="SMA Period")sma = ta.sma(close, smalength)emaforce = input.bool(title="Force trend with medium EMA", defval=true)-offsetemavalue = input(defval = 6)+offsetemavalue = input.int(defval = 6)bullbounce = smma>ema and ema>sma and low[5]>ema and low[2]<ema and close[1]>ema and (ema[offsetemavalue]>sma or (not emaforce))⋯shorts = input.bool(title="Test shorts", defval=true)-atrlength = input(title="ATR length", defval=12)+atrlength = input.int(title="ATR length", defval=12)atrm = input.float(title="ATR muliplier", defval=2)⋯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: 19 before, 14 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.
⋯// © greenmask9-//@version=5+//@version=6strategy("Dazzling Bolts", overlay=true)⋯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 |
|---|---|---|---|
| SMMA Period | 10 | int · min 1 | smma |
| Source | close | source | smma |
| EMA Period | 55 | int | ema |
| SMA Period | 110 | int | sma |
| Force trend with medium EMA | true | bool | bullbounce bearbounce |
| Offsetemavalue (no label in the script) | 6 | int | bullbounce bearbounce |
| Test longs | true | bool | bullbuy |
| Test shorts | true | bool | bearsell |
| ATR length | 12 | int | atr |
| ATR muliplier | 2 | float | target antitarget |
What it calculates
- SMA (
sma,ta.smain v5)Source (close), SMMA Period (10)smma · line 10 - EMA (
ema,ta.emain v5)close, EMA Period (55)ema · line 13 - SMA (
sma,ta.smain v5)close, SMA Period (110)sma · line 16 - ATR (
atr,ta.atrin v5)ATR length (12)atr · line 28 - Barssince (
barssince,ta.barssincein v5)bullbuybb · line 33 - Barssince (
barssince,ta.barssincein v5)bearsellbs · line 35
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 |
|---|---|---|---|
| Open Boltsup long | (bullbuy) | On | 37 |
| Exit Bolts.close stop and limit | (bullbuy) | On | 38 |
| Close Boltsup | (crossover(smma, sma)) | On | 40 |
| Open Boltsdown short | (bearsell) | On | 42 |
| Exit Bolts.close stop and limit | (bearsell) | On | 43 |
| Close Boltsdown | (crossunder(smma, sma)) | On | 45 |
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.
- 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 | +8.5% | +102.5% | 14 | 50% | 1.22 | 13.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −2.8% | +5.5% | 16 | 44% | 0.80 | 9.7% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | −41.2% | +9.8% | 13 | 31% | 0.50 | 50.3% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −7.1% | +8.4% | 20 | 45% | 0.78 | 14.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −27.9% | +16.7% | 12 | 42% | 0.67 | 33.8% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −4.9% | +21.5% | 14 | 43% | 0.81 | 10.8% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −11.8% | +148.3% | 24 | 50% | 0.89 | 37.7% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | −10.6% | +17.1% | 17 | 41% | 0.58 | 15.2% | 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 3 | 67% | $5,060.97 |
| Sideways market | 8 | 50% | $9,527.19 |
| Falling market | 3 | 33% | −$6,136.44 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
23.4%
The 95th percentile of the worst drawdown when the same 14 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 10.4% to 23.4%; the tick is what actually happened, 11.8%. Order luck alone moves it this much.
All 14 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 14 Jun 2024 66,773.00 | 24 Jun 2024 62,518.90 | 10 | −$4,254.14 |
| short | 24 Aug 2024 64,037.20 | 27 Aug 2024 58,113.40 | 3 | $5,923.85 |
| short | 17 Sep 2024 58,214.00 | 19 Sep 2024 62,670.30 | 2 | −$4,456.33 |
| long | 6 Oct 2024 62,058.00 | 14 Oct 2024 66,076.10 | 8 | $4,018.12 |
| long | 2 Jan 2025 94,591.80 | 6 Jan 2025 102,099.00 | 4 | $7,507.42 |
| long | 12 Jan 2025 94,600.00 | 17 Jan 2025 101,732.00 | 5 | $7,132.16 |
| long | 5 Feb 2025 97,763.10 | 25 Feb 2025 88,184.50 | 20 | −$9,578.61 |
| short | 5 Mar 2025 87,282.00 | 11 Mar 2025 77,215.90 | 6 | $10,066.10 |
| short | 5 Apr 2025 83,889.90 | 6 Apr 2025 77,227.10 | 1 | $6,662.74 |
| short | 16 Apr 2025 83,644.00 | 22 Apr 2025 91,433.30 | 6 | −$7,789.31 |
| short | 9 Jan 2026 91,100.00 | 13 Jan 2026 96,109.90 | 4 | −$5,009.87 |
| short | 16 Mar 2026 72,815.30 | 27 Mar 2026 66,878.70 | 11 | $5,936.56 |
| long | 21 May 2026 77,552.20 | 28 May 2026 73,622.30 | 7 | −$3,929.94 |
| short | 18 Jul 2026 63,931.70 | 19 Aug 2026 67,708.70 | 32 | −$3,777.04 |
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 |
|---|---|---|---|---|---|
| Dazzling Bolts this page | — | v4 strategy | +8.5% | 14 | 13.0% |
| Oath by OrcChieftain | ema sma atr barssince | v4 strategy | +0.2% | 45 | 0.0% |
| ATR with EOM and VORTEX by SoftKill21 | atr ema sma | v4 strategy | +66.2% | 22 | 29.9% |
| cATRpillar Strategy by Obi-wanClintobe | atr sma ema | v4 strategy | +1.02827e+24% | 27 | 88,097.2% |
| Optimized Zhaocaijinbao strategy by fzj20020403 | sma ema atr | v5 strategy | +15.6% | 12 | 9.8% |
| pomila by cryptostartegy | sma atr barssince | v4 strategy | −54.6% | 25 | 86.6% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 24 ms | Yes 1,000 bars in 38 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not 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. 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/// © greenmask9//@version=4strategy("Dazzling Bolts", overlay=true)//max_bars_back=3000// 13 SMMAlen = input(10, minval=1, title="SMMA Period")src = input(close, title="Source")smma = 0.0smma := na(smma[1]) ? sma(src, len) : (smma[1] * (len - 1) + src) / len// 55 EMAemalength = input(55, title="EMA Period")ema = ema(close, emalength)// 100 SMAsmalength = input(110, title="SMA Period")sma = sma(close, smalength)emaforce = input(title="Force trend with medium EMA", type=input.bool, defval=true)offsetemavalue = input(defval = 6)bullbounce = smma>ema and ema>sma and low[5]>ema and low[2]<ema and close[1]>ema and (ema[offsetemavalue]>sma or (not emaforce))bearbounce = smma<ema and ema<sma and high[5]<ema and high[2]>ema and close[1]<ema and (ema[offsetemavalue]<sma or (not emaforce))plotshape(bullbounce, title= "Purple", location=location.belowbar, color=#ff33cc, transp=0, style=shape.triangleup, size=size.tiny, text="Bolts")plotshape(bearbounce, title= "Purple", location=location.abovebar, color=#ff33cc, transp=0, style=shape.triangledown, size=size.tiny, text="Bolts")ordersize=floor(strategy.initial_capital/close)longs = input(title="Test longs", type=input.bool, defval=true)shorts = input(title="Test shorts", type=input.bool, defval=true)atrlength = input(title="ATR length", defval=12)atrm = input(title="ATR muliplier",type=input.float, defval=2)atr = atr(atrlength)target = close + atr*atrmantitarget = close - (atr*atrm)//limits and stop do not move, no need to count bars from sincebullbuy = bullbounce and longs and strategy.opentrades==0bb = barssince(bullbuy)bearsell = bearbounce and shorts and strategy.opentrades==0bs = barssince(bearsell)if (bullbuy) strategy.entry("Boltsup", strategy.long, ordersize) strategy.exit ("Bolts.close", from_entry="Boltsup", limit=target, stop=antitarget)if (crossover(smma, sma)) strategy.close("Boltsup", qty_percent = 100, comment = "Bolts.crossover")if (bearsell) strategy.entry("Boltsdown", strategy.short, ordersize) strategy.exit("Bolts.close", from_entry="Boltsdown", limit=antitarget, stop=target)if (crossunder(smma, sma)) strategy.close("Boltsdown", qty_percent = 100, comment = "Bolts.crossover")if (bb<5) bulltarget = line.new(bar_index[bb], target[bb], bar_index[0], target[bb], color=color.blue, width=2) bullclose = line.new(bar_index[bb], close[bb], bar_index[0], close[bb], color=color.blue, width=2) bullstop = line.new(bar_index[bb], antitarget[bb], bar_index[0], antitarget[bb], color=color.blue, width=2)if (bs<5) bulltarget = line.new(bar_index[bs], antitarget[bs], bar_index[0], antitarget[bs], color=color.purple, width=2) bullclose = line.new(bar_index[bs], close[bs], bar_index[0], close[bs], color=color.purple, width=2) bullstop = line.new(bar_index[bs], target[bs], bar_index[0], target[bs], color=color.purple, width=2)