Pine Script v5 · Strategy
ATR trailing Stop Loss tight to slack [Takazudo]
A Pine Script v5 strategy built on ATR (24). It has 4 order rules, 2 entries among them, and trades long and short with the default settings. Exits use a stop loss. Each trade is one contract and pays no commission. 10 settings; defaults include Entry band bar count 100, Trailing stop ATR Length 24 and Trailing stop ATR Multiple on tight 1.5.
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 ATR trailing Stop Loss tight to slack [Takazudo] repaint?
- No
- No repainting patterns were found in the source. The live replay was not measured: it had no trades to compare.
- Does ATR trailing Stop Loss tight to slack [Takazudo] 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 ATR trailing Stop Loss tight to slack [Takazudo] use a stop loss?
- Yes
- strategy.exit sets a stop on line 98, 99.
- Does ATR trailing Stop Loss tight to slack [Takazudo] run in Zeal Terminal?
- Yes
- It compiles in 33 ms and runs 1,000 bars in 296 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Plot
- Plot
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- 0.00%
- $0.00
- Buy and hold
- 0.0%
- 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, $0 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 |
|---|---|---|---|
| Entry strategy | |||
| Entry band bar count | 100 | int · min 1 | line 40 line 45 |
| ATR SL | |||
| Trailing stop ATR Length | 24 | int | sl_atrHeight_tight sl_atrHeight_slack |
| Trailing stop ATR Multiple on tight | 1.5 | float · step 0.1 | sl_atrHeight_tight |
| Trailing stop ATR Multiple on slack | 4 | float · step 0.1 | sl_atrHeight_slack |
| Backtesting range | |||
| From Year | 2016 | int · min 1970 | startDate |
| From Month | 1 | int · min 1 · max 12 | startDate |
| From Day | 1 | int · min 1 · max 31 | startDate |
| To Year | 2021 | int · min 1970 | finishDate |
| To Month | 4 | int · min 1 · max 12 | finishDate |
| To Day | 5 | int · min 1 · max 31 | finishDate |
What it calculates
- ATRTrailing stop ATR Length (24)
sl_atrHeight_tight · line 60 - ATRTrailing stop ATR Length (24)
sl_atrHeight_slack · line 61
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 Long long | shouldMakeEntryLong | On | 95 |
| Open Short short | shouldMakeEntryShort | On | 97 |
| Exit Long-SL/TP stop | every bar | On | 98 |
| Exit Short-SL/TP stop | every bar | On | 99 |
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% | 0.0% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | 0.0% | 0.0% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | 0.0% | 0.0% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | 0.0% | 0.0% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | 0.0% | 0.0% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | 0.0% | 0.0% | 0 | 0% | — | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | 0.0% | 0.0% | 0 | 0% | — | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | 0.0% | 0.0% | 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 |
|---|---|---|---|---|---|
| ATR trailing Stop Loss tight to slack [Takazudo] this page | — | v5 strategy | 0.0% | 0 | 0.0% |
| SOJA PIVOT by ParaBellum68 | atr | v4 strategy | +3.3% | 9 | 18.2% |
| Volatility System by EduardoMattje | atr | v5 strategy | +150.2% | 2 | 21.5% |
| ATR Stop Buy Strategy by phobo3s | atr | v4 strategy | No trades on this market | ||
| VBand Strategy by Saravanan_Ragavan | atr | v4 strategy | No trades on this market | ||
| Volatility Breakout Strategy [Angel Algo] by AngelAlgo | atr | v5 strategy | +3.1% | 18 | 3.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.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/-//@version=5+//@version=6//@author=Takazudo⋯Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 33 ms | With a workaround 1,000 bars in 296 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
Zeal Terminal's engine currently reads an order side written as direction = strategy.long, direction = strategy.short as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 95, 97) 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.
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///@version=5//@author=Takazudostrategy("ATR trailing SL tight to slack [Takazudo]", overlay=true, default_qty_type=strategy.fixed, initial_capital=0, currency=currency.USD)posSize = strategy.position_sizehasNoPos = posSize == 0hasLongPos = posSize > 0hasShortPos = posSize < 0//============================================================================// consts, inputs//============================================================================// colorsvar COLOR_SL_LINE = color.new(#e0f64d, 20)var COLOR_SL_LINE_THIN = color.new(#e0f64d, 90)var COLOR_ENTRY_BAND = color.new(#43A6F5, 30)var COLOR_TRANSPARENT = color.new(#000000, 100)// Entry strategy_g1 = 'Entry strategy'var config_entryBandBars = input.int(defval = 100, title = "Entry band bar count", minval=1, group=_g1)_g2 = 'ATR SL'var config_slAtr_length = input.int(24, title = "Trailing stop ATR Length", group=_g2)var config_slAtr_multi1 = input.float(1.5, title = "Trailing stop ATR Multiple on tight", step=0.1, group=_g2)var config_slAtr_multi2 = input.float(4, title = "Trailing stop ATR Multiple on slack", step=0.1, group=_g2)_g3 = 'Backtesting range'var config_fromYear = input.int(defval = 2016, title = "From Year", minval = 1970, group=_g3)var config_fromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12, group=_g3)var config_fromDay = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31, group=_g3)var config_toYear = input.int(defval = 2021, title = "To Year", minval = 1970, group=_g3)var config_toMonth = input.int(defval = 4, title = "To Month", minval = 1, maxval = 12, group=_g3)var config_toDay = input.int(defval = 5, title = "To Day", minval = 1, maxval = 31, group=_g3)//============================================================================// Range Edge calculation//============================================================================f_calcEntryBand_high() => _highest = math.max(open[3], close[3]) for i = 4 to (config_entryBandBars - 1) _highest := math.max(_highest, open[i], close[i]) _highestf_calcEntryBand_low() => _lowest = math.min(open[3], close[3]) for i = 4 to (config_entryBandBars - 1) _lowest := math.min(_lowest, open[i], close[i]) _lowestentryBand_high = f_calcEntryBand_high()entryBand_low = f_calcEntryBand_low()entryBand_height = entryBand_high - entryBand_lowplot(entryBand_high, color=COLOR_ENTRY_BAND, linewidth=1)plot(entryBand_low, color=COLOR_ENTRY_BAND, linewidth=1)rangeBreakDetected_long = entryBand_high < closerangeBreakDetected_short = entryBand_low > closeshouldMakeEntryLong = (strategy.position_size == 0) and rangeBreakDetected_longshouldMakeEntryShort = (strategy.position_size == 0) and rangeBreakDetected_short//============================================================================// ATR based stuff//============================================================================sl_atrHeight_tight = ta.atr(config_slAtr_length) * config_slAtr_multi1sl_atrHeight_slack = ta.atr(config_slAtr_length) * config_slAtr_multi2sl_tight_bull = math.min(open, close) - sl_atrHeight_tightsl_tight_bear = math.max(open, close) + sl_atrHeight_tightsl_slack_bull = math.min(open, close) - sl_atrHeight_slacksl_slack_bear = math.max(open, close) + sl_atrHeight_slackplot(sl_tight_bull, color=COLOR_SL_LINE_THIN, linewidth=1)plot(sl_tight_bear, color=COLOR_SL_LINE_THIN, linewidth=1)plot(sl_slack_bull, color=COLOR_SL_LINE_THIN, linewidth=1)plot(sl_slack_bear, color=COLOR_SL_LINE_THIN, linewidth=1)//============================================================================// Sl//============================================================================var trailingSl_long = hl2var trailingSl_short = hl2trailingSl_long := if hasLongPos math.max(trailingSl_long, sl_slack_bull)else sl_tight_bulltrailingSl_short := if hasShortPos math.min(trailingSl_short, sl_slack_bear)else sl_tight_bearcolor_sl_long = hasLongPos ? COLOR_SL_LINE : COLOR_TRANSPARENTcolor_sl_short = hasShortPos ? COLOR_SL_LINE : COLOR_TRANSPARENTplot(trailingSl_long, color=color_sl_long, linewidth=2)plot(trailingSl_short, color=color_sl_short, linewidth=2)//============================================================================// make entries//============================================================================// Calculate start/end date and time conditionstartDate = timestamp(config_fromYear, config_fromMonth, config_fromDay, 00, 00)finishDate = timestamp(config_toYear, config_toMonth, config_toDay, 00, 00)if (time >= startDate and time <= finishDate) if shouldMakeEntryLong strategy.entry(id="Long", direction=strategy.long, stop=close, qty=1000) if shouldMakeEntryShort strategy.entry(id="Short", direction=strategy.short, stop=close, qty=1000)strategy.exit('Long-SL/TP', 'Long', stop=trailingSl_long)strategy.exit('Short-SL/TP', 'Short', stop=trailingSl_short)