Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Optimized Keltner Channels SL-TP Strategy for BTC

A Pine Script v4 strategy built on SMA (source, 9), EMA (source, 9) and RMA or TR or ATR (true, 9). 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. 8 settings; defaults include Length 9, Multiplier 1.0 and Source close.

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 Optimized Keltner Channels SL-TP Strategy for BTC repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 9 of 9 trades.
How did Optimized Keltner Channels SL-TP Strategy for BTC do on BTCUSDT 1D with default settings?
−19.44%
From 26 Jan 2024 to 21 Oct 2026, over 36 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Optimized Keltner Channels SL-TP Strategy for BTC be converted to Pine Script v5?
No
The automatic step from v4 to v5 gives a script that does not run in v5 (Pine Script v5 Error at @L25:C11: No value assigned to the `transp` parameter in color.new()), so no v5 download is offered; the edits are shown below.
Does Optimized Keltner Channels SL-TP Strategy for BTC use a stop loss?
Yes
strategy.exit sets a stop on line 48, 49.
Does Optimized Keltner Channels SL-TP Strategy for BTC run in Zeal Terminal?
Yes
It compiles in 16 ms and runs 1,000 bars in 57 ms, in the browser.

BTCUSDT · 1D · default settings

  • Upper
  • Basis
  • Lower
  • 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 (8)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$77,615$202,527Equity from $100,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.
Net profit
−19.44%
−$19,440.70
Buy and hold
+102.5%
same period
Closed trades
36
11 won · 25 lost
Profitable
30.6%
of closed trades
Profit factor
0.86
gross profit ÷ gross loss
Max drawdown
69.98%
−$78,946.40

One run with the author's default settings, $100,000 starting capital, commission as the script sets it. A short 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.

  • 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 length (line 5) 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 25

    transp = on line 25. 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, rma → ta.rma, tr → ta.tr, atr → ta.atr, crossover → ta.crossover, crossunder → ta.crossunder.

v4 → v5

Differs

The v5 version does not run in Zeal Terminal's engine: Pine Script v5 Error at @L25:C11: No value assigned to the `transp` parameter in color.new()

  • Line 3: //@version=4 → //@version=5
  • Line 11: input(type = input.float) → input.float()
  • Line 12: input(type = input.float) → input.float()
  • Line 14: sma → ta.sma
  • Line 15: ema → ta.ema
  • Line 18: rma → ta.rma
6 more edits
  • Line 18: tr → ta.tr
  • Line 18: atr → ta.atr
  • Line 18: rma → ta.rma
  • Line 25: transp = 95 → color.new(#0094FF, 95)
  • Line 26: crossover → ta.crossover
  • Line 27: crossunder → ta.crossunder
⋯// © chanu_lev10k-//@version=4+//@version=5strategy(title="Optimized Keltner Channels SL/TP Strategy for BTC", overlay=true)⋯atrlength = input(19, "ATR Length")-sl = input(defval=20, minval=0, type=input.float, step=0.1, title="Stop Loss (%)")+sl = input.float(defval=20, minval=0, step=0.1, title="Stop Loss (%)")-tp = input(defval=20.3, minval=0, type=input.float, step=0.1, title="Take Profit (%)")+tp = input.float(defval=20.3, minval=0, step=0.1, title="Take Profit (%)")esma(source, length)=>-    s = sma(source, length)+    s = ta.sma(source, length)-    e = ema(source, length)+    e = ta.ema(source, length)    exp ? e : sma = esma(src, length)-rangema = BandsStyle == "True Range" ? rma(tr(true), length) : BandsStyle == "Average True Range" ? atr(atrlength) : rma(high - low, length)+rangema = BandsStyle == "True Range" ? ta.rma(ta.tr(true), length) : BandsStyle == "Average True Range" ? ta.atr(atrlength) : ta.rma(high - low, length)upper = ma + rangema * mult⋯l = plot(lower, color=color.red, title="Lower")-fill(u, l, color.new(color=#0094FF, transp=95), title="Background")+fill(u, l, color.new(color=color.new(#0094FF, 95)), title="Background")-crossUpper = crossover(src, upper)+crossUpper = ta.crossover(src, upper)-crossLower = crossunder(src, lower)+crossLower = ta.crossunder(src, lower)bprice = 0.0⋯

Clean v5

Not verified

The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L25:C11: No value assigned to the `transp` parameter in color.new()), so this step could not be checked.

  • Line 5: input() → input.int()
  • Line 6: input() → input.float()
  • Line 7: input() → input.source()
  • Line 8: input() → input.bool()
  • Line 9: input() → input.string()
  • Line 10: input() → input.int()
⋯strategy(title="Optimized Keltner Channels SL/TP Strategy for BTC", overlay=true)-length = input(9, minval=1)+length = input.int(9, minval=1)-mult = input(1.0, "Multiplier")+mult = input.float(1.0, "Multiplier")-src = input(close, title="Source")+src = input.source(close, title="Source")-exp = input(true, "Use Exponential MA")+exp = input.bool(true, "Use Exponential MA")-BandsStyle = input("Average True Range", options = ["Average True Range", "True Range", "Range"], title="Bands Style")+BandsStyle = input.string("Average True Range", options = ["Average True Range", "True Range", "Range"], title="Bands Style")-atrlength = input(19, "ATR Length")+atrlength = input.int(19, "ATR Length")sl = input.float(defval=20, minval=0, step=0.1, title="Stop Loss (%)")⋯

Does it run in Pine Script v6?

Not tested

The v5 script does not run in Zeal Terminal's engine (Pine Script v5 Error at @L25:C11: No value assigned to the `transp` parameter in color.new()), so this step could not be checked. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

⋯// © chanu_lev10k-//@version=5+//@version=6strategy(title="Optimized Keltner Channels SL/TP Strategy for BTC", overlay=true)⋯

Settings

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

SettingDefaultType and rangeFeeds
Length (no label in the script)9int · min 1s e ma rangema
Multiplier1.0floatupper lower
Sourceclosesourcema crossUpper crossLower cancelBcond cancelScond
Use Exponential MAtrueboolline 16
Bands StyleAverage True Rangestring · options ["Average True Range", "True Range", "Range"]rangema
ATR Length19intrangema
Stop Loss (%)20float · min 0 · step 0.1exit Long exit exit Short exit
Take Profit (%)20.3float · min 0 · step 0.1exit Long exit exit Short exit

What it calculates

  • SMA (sma, ta.sma in v5)source, Length (9)s · line 14
  • EMA (ema, ta.ema in v5)source, Length (9)e · line 15
  • RMA / TR / ATR (rma, ta.rma in v5)tr(true), Length (9) · chosen by Bands Stylerangema · line 18
  • Crossover (crossover, ta.crossover in v5)Source (close), uppercrossUpper · line 26
  • Crossunder (crossunder, ta.crossunder in v5)Source (close), lowercrossLower · 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.

lengthLengthsetting · 9lowlowprice datahighhighprice dataBandsStyleBands Stylesetting · Average True RangeatrlengthATR Lengthsetting · 19closecloseprice datamultMultipliersetting · 1.0sSMA→ seEMA→ erangemaRMA / TR / ATR→ rangema · by Bands StylecrossUpperCrossover→ crossUppercrossLowerCrossunder→ crossLowermamavalueupper, lowerupper · lower2 valuesbpricebpricevaluespricespricevaluecrossBcondcrossBcondvaluecrossScondcrossScondvaluecancelBcondcancelBcondconditioncancelScondcancelScondconditioncColourccancel:KltChLEcancel KltChLEstrategy.cancelentry:KltChLEOpen KltChLEstrategy.entrycancel:KltChSEcancel KltChSEstrategy.cancelentry:KltChSEOpen KltChSEstrategy.entryexit:Long exitexit Long exitstrategy.exitexit:Short exitexit Short exitstrategy.exitplot:22Upperplotplot:23Basisplotplot:24Lowerplotfill:BackgroundBackgroundfillplot:50plotplotplot:51plotplot

Order rules

OrderFires whenBy defaultLine
cancel KltChLE(cancelBcond)On41
Open KltChLE long(crossUpper)On43
cancel KltChSE(cancelScond)On45
Open KltChSE short(crossLower)On47
Exit Long exit stop and limitevery barOn48
Exit Short exit stop and limitevery barOn49

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.

9/9trades 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−19.4%+102.5%3631%0.8670.0%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−5.3%+5.5%3429%0.8914.6%8 May 2026 – 21 Oct 2026
ETHUSDT 1D−1.0%+9.8%4639%0.904.4%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+0.1%+8.4%2931%1.050.6%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%4842%1.010.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%3429%0.780.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D+0.0%+148.3%3540%1.010.6%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.0%+17.1%2829%1.090.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 market922%−$12,119.70
Sideways market1937%$12,439.40
Falling market825%−$19,760.40

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

How bad could the drawdown be?

68.1%

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

0%78%
All 36 trades
SideEntryExitBarsP&L
long27 Feb 2024 54,476.504 Mar 2024 67,288.606$12,812.10
long7 Mar 2024 66,074.1017 Mar 2024 65,300.6010−$773.43
short17 Mar 2024 65,300.6016 May 2024 66,206.5060−$905.89
long16 May 2024 66,206.5025 Jun 2024 60,293.3040−$5,913.22
short25 Jun 2024 60,293.3016 Jul 2024 64,724.2021−$4,430.86
long16 Jul 2024 64,724.203 Aug 2024 61,498.3018−$3,225.83
short3 Aug 2024 61,498.305 Aug 2024 49,691.602$11,806.70
long24 Aug 2024 64,037.306 Sep 2024 52,801.3013−$11,236.00
short7 Sep 2024 53,963.0014 Sep 2024 60,498.007−$6,535.05
long14 Sep 2024 60,498.002 Oct 2024 60,804.9018$306.91
short2 Oct 2024 60,804.9015 Oct 2024 66,084.0013−$5,279.08
long15 Oct 2024 66,084.0011 Nov 2024 82,399.1027$16,315.10
long20 Nov 2024 92,310.8025 Feb 2025 91,552.9097−$757.93
short25 Feb 2025 91,552.903 Mar 2025 94,270.006−$2,717.14
long3 Mar 2025 94,270.0010 Mar 2025 80,734.407−$13,535.60
short10 Mar 2025 80,734.4023 Apr 2025 93,443.0044−$12,708.60
long23 Apr 2025 93,443.006 Jun 2025 101,509.0044$8,065.67
short6 Jun 2025 101,509.0010 Jun 2025 110,263.004−$8,754.36
long10 Jun 2025 110,263.002 Aug 2025 113,298.0053$3,034.89
short2 Aug 2025 113,298.0011 Aug 2025 119,294.009−$5,996.35
long11 Aug 2025 119,294.0020 Aug 2025 112,873.009−$6,421.34
short20 Aug 2025 112,873.0012 Sep 2025 115,483.0023−$2,609.77
long12 Sep 2025 115,483.0024 Sep 2025 111,999.0012−$3,483.91
short24 Sep 2025 111,999.002 Oct 2025 118,595.008−$6,596.21
long2 Oct 2025 118,595.0011 Oct 2025 112,774.009−$5,820.51
short11 Oct 2025 112,774.0016 Nov 2025 93,368.4036$19,406.00
short20 Nov 2025 91,554.906 Jan 2026 93,859.7047−$2,304.77
long6 Jan 2026 93,859.7021 Jan 2026 88,427.6015−$5,432.07
short21 Jan 2026 88,427.604 Feb 2026 73,046.3014$15,381.40
long5 Mar 2026 72,666.8028 Mar 2026 66,407.3023−$6,259.51
short28 Mar 2026 66,407.308 Apr 2026 71,924.2011−$5,516.96
long8 Apr 2026 71,924.2023 May 2026 75,539.5045$3,615.26
short23 May 2026 75,539.504 Jun 2026 62,518.5012$13,021.00
short10 Jun 2026 61,730.0020 Aug 2026 69,334.8071−$7,604.81
long20 Aug 2026 69,334.8021 Sep 2026 85,813.9032$16,479.10
long22 Sep 2026 86,620.009 Oct 2026 81,754.4017−$4,865.57

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
Optimized Keltner Channels SL-TP Strategy for BTC this page—v4 strategy−19.4%3670.0%
Strategy - Trend Chaser - PSe by ElvinKennedyHernandezLatayantr atr rma ema smav5 strategyNo trades on this market
ATR with EOM and VORTEX by SoftKill21atr ema smav4 strategy+66.2%2229.9%
Scalping Trading System bot Crypto and Stocks by exlux99sma ema trv5 strategy+6.5%51.0%
cATRpillar Strategy by Obi-wanClintobeatr sma emav4 strategy+1.02827e+24%2788,097.2%
Optimized Zhaocaijinbao strategy by fzj20020403sma ema atrv5 strategy+15.6%129.8%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 16 msYes 1,000 bars in 57 msNot measured
PineTSNo 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/// © chanu_lev10k//@version=4strategy(title="Optimized Keltner Channels SL/TP Strategy for BTC", overlay=true)length = input(9, minval=1)mult = input(1.0, "Multiplier")src = input(close, title="Source")exp = input(true, "Use Exponential MA")BandsStyle = input("Average True Range", options = ["Average True Range", "True Range", "Range"], title="Bands Style")atrlength = input(19, "ATR Length")sl = input(defval=20, minval=0, type=input.float, step=0.1, title="Stop Loss (%)")tp = input(defval=20.3, minval=0, type=input.float, step=0.1, title="Take Profit (%)")esma(source, length)=>    s = sma(source, length)    e = ema(source, length)    exp ? e : sma = esma(src, length)rangema = BandsStyle == "True Range" ? rma(tr(true), length) : BandsStyle == "Average True Range" ? atr(atrlength) : rma(high - low, length)upper = ma + rangema * multlower = ma - rangema * multc = color.blueu = plot(upper, color=color.green, title="Upper")plot(ma, color=#0094FF, title="Basis")l = plot(lower, color=color.red, title="Lower")fill(u, l, color.new(color=#0094FF, transp=95), title="Background")crossUpper = crossover(src, upper)crossLower = crossunder(src, lower)bprice = 0.0bprice := crossUpper ? close+syminfo.mintick : nz(bprice[1])sprice = 0.0sprice := crossLower ? close-syminfo.mintick : nz(sprice[1])crossBcond = falsecrossBcond := crossUpper ? true     : na(crossBcond[1]) ? false : crossBcond[1]crossScond = falsecrossScond := crossLower ? true     : na(crossScond[1]) ? false : crossScond[1]cancelBcond = crossBcond and (src < ma or high >= bprice )cancelScond = crossScond and (src > ma or low <= sprice )if (cancelBcond)    strategy.cancel("KltChLE")if (crossUpper)    strategy.entry("KltChLE", strategy.long, stop=bprice, comment="Long")if (cancelScond)    strategy.cancel("KltChSE")if (crossLower)    strategy.entry("KltChSE", strategy.short, stop=sprice, comment="Short")strategy.exit("Long exit", "KltChLE", profit = close * tp * 0.01 / syminfo.mintick, loss = close * sl * 0.01 / syminfo.mintick)strategy.exit("Short exit", "KltChSE", profit = close * tp * 0.01 / syminfo.mintick, loss = close * sl * 0.01 / syminfo.mintick)plot(bprice, color=color.green)plot(sprice, color=color.red)