Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (10)
50,00075,000100,000125,000AprJulOct2025AprJulOct2026AprJulOct$0$0Equity from $0
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 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.
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.

SettingDefaultType and rangeFeeds
Entry strategy
Entry band bar count100int · min 1line 40 line 45
ATR SL
Trailing stop ATR Length24intsl_atrHeight_tight sl_atrHeight_slack
Trailing stop ATR Multiple on tight1.5float · step 0.1sl_atrHeight_tight
Trailing stop ATR Multiple on slack4float · step 0.1sl_atrHeight_slack
Backtesting range
From Year2016int · min 1970startDate
From Month1int · min 1 · max 12startDate
From Day1int · min 1 · max 31startDate
To Year2021int · min 1970finishDate
To Month4int · min 1 · max 12finishDate
To Day5int · min 1 · max 31finishDate

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.

high · low · closehigh · low · closeprice dataconfig_slAtr_lengthTrailing stop ATR Lengthsetting · 24config_slAtr_multi1Trailing stop ATR Multi…setting · 1.5config_slAtr_multi2Trailing stop ATR Multi…setting · 4closecloseprice dataopenopenprice datahl2hl2price dataconfig_fromYearFrom Yearsetting · 2016config_fromMonthFrom Monthsetting · 1config_fromDayFrom Daysetting · 1config_toYearTo Yearsetting · 2021config_toMonthTo Monthsetting · 4config_toDayTo Daysetting · 5sl_atrHeight_tightATR→ sl_atrHeight_tightsl_atrHeight_slackATR→ sl_atrHeight_slackposSize, entryBand_heightposSize · entryBand_hei…2 values_highest_highestvalue_lowest_lowestvaluesl_tight_bull, sl_tight_bearsl_tight_bull · sl_tigh…2 valuessl_slack_bull, sl_slack_bearsl_slack_bull · sl_slac…2 valuestrailingSl_longtrailingSl_longvaluetrailingSl_shorttrailingSl_shortvaluecolor_sl_longcolor_sl_longvaluecolor_sl_shortcolor_sl_shortvaluestartDatestartDatevaluefinishDatefinishDatevalueshouldMakeEntryLongshouldMakeEntryLongconditionshouldMakeEntryShortshouldMakeEntryShortconditionhasNoPos, hasLongPos, hasShortPoshasNoPos · hasLongPos +13 conditionsrangeBreakDetected_long, rangeBreakDetected_shortrangeBreakDetected_long…2 conditionsCOLOR_SL_LINE, COLOR_SL_LINE_THIN, COLOR_ENTRY_BAND, COLOR_TRANSPARENTColourCOLOR_SL_LINE · COLOR_SL_LINE…entry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryexit:Long-SL/TPexit Long-SL/TPstrategy.exitexit:Short-SL/TPexit Short-SL/TPstrategy.exitplot:51plotplotplot:52plotplotplot:66plotplotplot:67plotplotplot:68plotplotplot:69plotplotplot:85plotplotplot:86plotplot

Order rules

OrderFires whenBy defaultLine
Open Long longshouldMakeEntryLongOn95
Open Short shortshouldMakeEntryShortOn97
Exit Long-SL/TP stopevery barOn98
Exit Short-SL/TP stopevery barOn99

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.

Not measuredNo trades to compareThe last 300 bars, from 26 Dec 2025, were fed to the engine as live ticks, but neither the live nor the historical run produced any trades in them, so the replay says nothing either way.
  • 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 1D0.0%0.0%00%—0.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h0.0%0.0%00%—0.0%8 May 2026 – 21 Oct 2026
ETHUSDT 1D0.0%0.0%00%—0.0%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h0.0%0.0%00%—0.0%8 May 2026 – 21 Oct 2026
SOLUSDT 1D0.0%0.0%00%—0.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h0.0%0.0%00%—0.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D0.0%0.0%00%—0.0%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h0.0%0.0%00%—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.

ScriptSharesTypeNetTradesMax drawdown
ATR trailing Stop Loss tight to slack [Takazudo] this page—v5 strategy0.0%00.0%
SOJA PIVOT by ParaBellum68atrv4 strategy+3.3%918.2%
Volatility System by EduardoMattjeatrv5 strategy+150.2%221.5%
ATR Stop Buy Strategy by phobo3satrv4 strategyNo trades on this market
VBand Strategy by Saravanan_Ragavanatrv4 strategyNo trades on this market
Volatility Breakout Strategy [Angel Algo] by AngelAlgoatrv5 strategy+3.1%183.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

Verified

Nothing 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

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 33 msWith a workaround 1,000 bars in 296 msNot measured
PineTSNot testedNot testedNot 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)