Pine Script v4 · Strategy
BTC 15 min
A Pine Script v4 strategy built on SMA (close, 30), EMA (source, 3) and RSI or CUM or Change (leng). It has 4 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 commits 20% of equity and pays 0.075% commission. 23 settings; defaults include Strategy Direction all, length of channel 30 and upper percent 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 BTC 15 min repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 35 of 35 trades.
- How did BTC 15 min do on BTCUSDT 1D with default settings?
- −25.72%
- From 26 Jan 2024 to 21 Oct 2026, over 119 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can BTC 15 min 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 BTC 15 min use a stop loss?
- Yes
- strategy.exit sets a stop on line 213, 214.
- Does BTC 15 min run in Zeal Terminal?
- Yes
- It compiles in 47 ms and runs 1,000 bars in 113 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
Needs BINANCE:BTCUSDT 1 data, not available: a lower timeframe than the chart; the engine does not evaluate intrabar data Values that depend on it are empty on this chart.
- Net profit
- −25.72%
- −$2,571.92
- Buy and hold
- +102.5%
- same period
- Closed trades
- 119
- 82 won · 37 lost
- Profitable
- 68.9%
- of closed trades
- Profit factor
- 0.73
- gross profit ÷ gross loss
- Max drawdown
- 38.87%
- −$4,615.37
One run with the author's default settings, $10,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.
-
Note
6 settings have no label
In the settings dialog HTF (line 29), len (line 54), Min (line 61), filter (line 191), risk (line 193), leverage (line 194) show an empty name. The labels on this page come from the variable names.
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, change → ta.change, rsi → ta.rsi, cum → ta.cum, wma → ta.wma, round → math.round, sqrt → math.sqrt, security → request.security, linreg → ta.linreg, crossover → ta.crossover, crossunder → ta.crossunder, stdev → ta.stdev, highest → ta.highest, lowest → ta.lowest, pow → math.pow.
v4 → v5
VerifiedSame 119 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 10: input(type = input.float) → input.float()
- Line 11: input(type = input.float) → input.float()
- Line 12: sma → ta.sma
- Line 22: ema → ta.ema
- Line 23: ema → ta.ema
41 more edits
- Line 29: input(type = input.resolution) → input.timeframe()
- Line 30: change → ta.change
- Line 32: rsi → ta.rsi
- Line 32: cum → ta.cum
- Line 32: change → ta.change
- Line 33: wma → ta.wma
- Line 36: ema → ta.ema
- Line 41: input(type = input.resolution) → input.timeframe()
- Line 42: input(type = input.integer) → input.int()
- Line 43: input(type = input.integer) → input.int()
- Line 45: wma → ta.wma
- Line 45: wma → ta.wma
- Line 45: wma → ta.wma
- Line 45: round → math.round
- Line 45: sqrt → math.sqrt
- Line 49: wma → ta.wma
- Line 49: wma → ta.wma
- Line 49: wma → ta.wma
- Line 49: wma → ta.wma
- Line 50: security → request.security
- Line 55: linreg → ta.linreg
- Line 56: crossover → ta.crossover
- Line 57: crossunder → ta.crossunder
- Line 57: crossunder → ta.crossunder
- Line 66: wma → ta.wma
- Line 67: wma → ta.wma
- Line 75: ema → ta.ema
- Line 76: stdev → ta.stdev
- Line 81: crossover → ta.crossover
- Line 82: crossunder → ta.crossunder
- Line 91: highest → ta.highest
- Line 92: lowest → ta.lowest
- Line 108: crossover → ta.crossover
- Line 143: input(type = input.float) → input.float()
- Line 144: crossover → ta.crossover
- Line 151: input(type = input.float) → input.float()
- Line 152: crossunder → ta.crossunder
- Line 192: round → math.round
- Line 192: pow → math.pow
- Line 192: pow → math.pow
- Line 206: round → math.round
⋯// © RafaelZioni-//@version=4+//@version=5strategy(title = " BTC 15 min", overlay = true, pyramiding=1,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 20, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.075)⋯length8 = input(30,title = 'length of channel')-upmult = input(title = 'upper percent',type=input.float, step=0.1, defval=5)+upmult = input.float(title = 'upper percent', step=0.1, defval=5)-lowmult = input(title = 'lower percent',type=input.float, step=0.1, defval=5)+lowmult = input.float(title = 'lower percent', step=0.1, defval=5)-basis = sma(close, length8)+basis = ta.sma(close, length8)vup = upmult * price / 100⋯source=close-v1=ema(source,fastLength)+v1=ta.ema(source,fastLength)-v2=ema(source,slowLength)+v2=ta.ema(source,slowLength)//⋯//taken from https://www.tradingview.com/script/Ql1FjjfX-security-free-MTF-example-JD/-HTF = input("1D", type=input.resolution)+HTF = input.timeframe("1D")-ti = change( time(HTF) ) != 0+ti = ta.change( time(HTF) ) != 0T_c = fixnan( ti ? close : na )-vrsi = rsi(cum(change(T_c) * volume), leng)+vrsi = ta.rsi(ta.cum(ta.change(T_c) * volume), leng)-pp=wma(vrsi,len55)+pp=ta.wma(vrsi,len55)d=(vrsi[1]-pp[1])len100 = 10-x=ema(d,len100)+x=ta.ema(d,len100)//⋯//-tf10 = input("1", title = "Timeframe", type = input.resolution, options = ["1", "5", "15", "30", "60","120", "240","360","720", "D", "W"])+tf10 = input.timeframe("1", title = "Timeframe", options = ["1", "5", "15", "30", "60","120", "240","360","720", "D", "W"])-length = input(50, title = "Period", type = input.integer)+length = input.int(50, title = "Period")-shift = input(1, title = "Shift", type = input.integer)+shift = input.int(1, title = "Shift")hma(_src, _length)=>- wma((2 * wma(_src, _length / 2)) - wma(_src, _length), round(sqrt(_length)))+ ta.wma((2 * ta.wma(_src, _length / 2)) - ta.wma(_src, _length), math.round(math.sqrt(_length))) ⋯ p = length/2- wma(wma(close,p/3)*3 - wma(close,p/2) - wma(close,p),p)+ ta.wma(ta.wma(close,p/3)*3 - ta.wma(close,p/2) - ta.wma(close,p),p)-b =security(syminfo.tickerid, tf10, hma3(close[1], length)[shift])+b =request.security(syminfo.tickerid, tf10, hma3(close[1], length)[shift])//plot(a,color=color.gray)⋯len = input(25)-linear_reg = linreg(close_price, len, 0)+linear_reg = ta.linreg(close_price, len, 0)-buy=crossover(linear_reg, b) +buy=ta.crossover(linear_reg, b) -sell=crossunder(linear_reg, b) or crossunder(close[1],upper)+sell=ta.crossunder(linear_reg, b) or ta.crossunder(close[1],upper)//⋯ 60 / timeframe.multiplier * 24 * 7 : 7-l1 = wma(src2,leni)+l1 = ta.wma(src2,leni)-h1 = wma(src3,leni)+h1 = ta.wma(src3,leni)//⋯multi = 2-mean = ema(src5, len5) +mean = ta.ema(src5, len5) -stddev = multi * stdev(src5, len5) +stddev = multi * ta.stdev(src5, len5) b5 = mean + stddev⋯var bool short = na-long :=crossover(src5, s5) +long :=ta.crossover(src5, s5) -short := crossunder(src5, b5)+short := ta.crossunder(src5, b5)var float last_open_long = na⋯//-highb = highest(entry_value1, r) +highb = ta.highest(entry_value1, r) -lowb = lowest(entry_value, r) +lowb = ta.lowest(entry_value, r) d5 = highb - lowb ⋯shortCond = bool(na)-longCond := crossover(zx,0) or buy +longCond := ta.crossover(zx,0) or buy shortCond := sell⋯//isTPs = input(false, "Take Profit Short")-tp = input(2, "Exit Profit %", type=input.float)+tp = input.float(2, "Exit Profit %")-long_tp = isTPl and crossover(high, (1 + tp / 100) * last_open_longCondition) and longCondition == 0 and in_longCondition == 1+long_tp = isTPl and ta.crossover(high, (1 + tp / 100) * last_open_longCondition) and longCondition == 0 and in_longCondition == 1//short_tp = isTPs and crossunder(low, (1 - tp / 100) * last_open_shortCondition) and ⋯sl = 0.0-sl := input(5, " rebuy %", type=input.float)+sl := input.float(5, " rebuy %")-long_sl = isSLl and crossunder(low, (1 - sl / 100) * last_open_longCondition) and +long_sl = isSLl and ta.crossunder(low, (1 - sl / 100) * last_open_longCondition) and longCondition == 0 and in_longCondition == 1⋯filter=input(true)-g(v, p) => round(v * (pow(10, p))) / pow(10, p)+g(v, p) => math.round(v * (math.pow(10, p))) / math.pow(10, p)risk = input(100)⋯per(pcnt) =>- strategy.position_size != 0 ? round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)+ strategy.position_size != 0 ? math.round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)stoploss=input(title=" stop loss", defval=5, minval=0.01)⋯Same 119 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 5: input() → input.string()
- Line 9: input() → input.int()
- Line 19: input() → input.int()
- Line 20: input() → input.int()
- Line 54: input() → input.int()
- Line 61: input() → input.int()
9 more edits
- Line 148: input() → input.bool()
- Line 191: input() → input.bool()
- Line 193: input() → input.int()
- Line 194: input() → input.int()
- Line 207: input() → input.int()
- Line 209: input() → input.int()
- Line 210: input() → input.int()
- Line 211: input() → input.int()
- Line 212: input() → input.int()
⋯strategy(title = " BTC 15 min", overlay = true, pyramiding=1,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 20, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.075)-strat_dir_input = input(title="Strategy Direction", defval="all", options=["long", "short", "all"])+strat_dir_input = input.string(title="Strategy Direction", defval="all", options=["long", "short", "all"])strat_dir_value = strat_dir_input == "long" ? strategy.direction.long : strat_dir_input == "short" ? strategy.direction.short : strategy.direction.all⋯price = close-length8 = input(30,title = 'length of channel')+length8 = input.int(30,title = 'length of channel')upmult = input.float(title = 'upper percent', step=0.1, defval=5)⋯//-fastLength = input(3, title="Fast filter length ", minval=1)+fastLength = input.int(3, title="Fast filter length ", minval=1)-slowLength = input(21,title="Slow filter length", minval=1)+slowLength = input.int(21,title="Slow filter length", minval=1)source=close⋯close_price = close[0]-len = input(25)+len = input.int(25)linear_reg = ta.linreg(close_price, len, 0)⋯src3=high-Min =input(15)+Min =input.int(15)leni = timeframe.isintraday and timeframe.multiplier >= 1 ? ⋯// Stop Loss-isSLl = input(true,"buy Loss Long")+isSLl = input.bool(true,"buy Loss Long")//isSLs = input(false, "buy Loss Short")⋯//-filter=input(true)+filter=input.bool(true)g(v, p) => math.round(v * (math.pow(10, p))) / math.pow(10, p)-risk = input(100)+risk = input.int(100)-leverage = input(1)+leverage = input.int(1)c = g((strategy.equity * leverage / open) * (risk / 100), 4)⋯ strategy.position_size != 0 ? math.round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)-stoploss=input(title=" stop loss", defval=5, minval=0.01)+stoploss=input.int(title=" stop loss", defval=5, minval=0.01)los = per(stoploss)-q1=input(title=" qty_percent1", defval=50, minval=1)+q1=input.int(title=" qty_percent1", defval=50, minval=1)-q2=input(title=" qty_percent2", defval=50, minval=1)+q2=input.int(title=" qty_percent2", defval=50, minval=1)-tp10=input(title=" Take profit1", defval=1, minval=0.01)+tp10=input.int(title=" Take profit1", defval=1, minval=0.01)-tp20=input(title=" Take profit2", defval=2, minval=0.01)+tp20=input.int(title=" Take profit2", defval=2, minval=0.01)strategy.exit("x1", qty_percent = q1, profit = per(tp10), loss = los)⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L79:C0: a 'bool' cannot be 'na' in Pine Script v6 — declare it as true or false. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.
⋯// © RafaelZioni-//@version=5+//@version=6strategy(title = " BTC 15 min", overlay = true, pyramiding=1,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 20, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.075)⋯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 |
|---|---|---|---|
| Strategy Direction | all | string · options ["long", "short", "all"] | strat_dir_value |
| length of channel | 30 | int | basis |
| upper percent | 5 | float · step 0.1 | vup |
| lower percent | 5 | float · step 0.1 | vlow |
| Fast filter length | 3 | int · min 1 | v1 |
| Slow filter length | 21 | int · min 1 | v2 |
| HTF (no label in the script) | 1D | timeframe (written input.resolution) | ti |
| Timeframe | 1 | timeframe (written input.resolution) · options ["1", "5", "15", "30", "60","120", "240","360","720", "D", "W"] | b |
| Period | 50 | int (written input.integer) | p b |
| Shift | 1 | int (written input.integer) | b |
| Len (no label in the script) | 25 | int | linear_reg |
| Min (no label in the script) | 15 | int | leni |
| Exit Profit % | 2 | float | long_tp |
| buy Loss Long | true | bool | long_sl |
| rebuy % | 5 | float | long_sl |
| Filter (no label in the script) | true | bool | l |
| Risk (no label in the script) | 100 | int | c |
| Leverage (no label in the script) | 1 | int | c |
| stop loss | 5 | int · min 0.01 | los |
| qty_percent1 | 50 | int · min 1 | exit x1 |
| qty_percent2 | 50 | int · min 1 | exit x2 |
| Take profit1 | 1 | int · min 0.01 | exit x1 |
| Take profit2 | 2 | int · min 0.01 | exit x2 |
What it calculates
- SMA (
sma,ta.smain v5)close, length of channel (30)basis · line 12 - EMA (
ema,ta.emain v5)source, Fast filter length (3)v1 · line 22 - EMA (
ema,ta.emain v5)source, Slow filter length (21)v2 · line 23 - RSI / CUM / Change (
rsi,ta.rsiin v5)cum(change(T_c) * volume), lengvrsi · line 32 - WMA (
wma,ta.wmain v5)vrsi, len55pp · line 33 - EMA (
ema,ta.emain v5)d, len100x · line 36 - Linreg (
linreg,ta.linregin v5)close_price, Len (25), 0linear_reg · line 55 - Crossover (
crossover,ta.crossoverin v5)linear_reg, bbuy · line 56 - WMA (
wma,ta.wmain v5)src2, lenil1 · line 66 - WMA (
wma,ta.wmain v5)src3, lenih1 · line 67 - EMA (
ema,ta.emain v5)src5, len5mean · line 75 - Stdev (
stdev,ta.stdevin v5)src5, len5stddev · line 76 - Crossover (
crossover,ta.crossoverin v5)src5, s5long · line 81 - Crossunder (
crossunder,ta.crossunderin v5)src5, b5short · line 82 - Highest (
highest,ta.highestin v5)entry_value1, rhighb · line 91 - Lowest (
lowest,ta.lowestin v5)entry_value, rlowb · line 92
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.
The script has 101 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open buy long | l | On | 202 |
| Open sell short | s | On | 204 |
| Exit x1 stop and limit | every bar | On | 213 |
| Exit x2 stop and limit | every bar | On | 214 |
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 data1 security call(s), none with lookahead on.
- 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
Not run on other markets: the script requests BINANCE:BTCUSDT 1, and that data is not available here (a lower timeframe than the chart; the engine does not evaluate intrabar data). Its results would rest on empty values.
The trades
By market direction
| At entry, last 90 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 49 | 71% | −$291.38 |
| Sideways market | 56 | 73% | −$410.38 |
| Falling market | 14 | 43% | −$1,864.51 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
35.4%
The 95th percentile of the worst drawdown when the same 119 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 25.5% to 35.4%; the tick is what actually happened, 36.8%. Order luck alone moves it this much.
All 119 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 19 Feb 2024 52,137.70 | 20 Feb 2024 52,659.10 | 1 | $42.86 |
| long | 19 Feb 2024 52,137.70 | 21 Feb 2024 52,258.80 | 2 | $4.15 |
| short | 21 Feb 2024 52,258.80 | 22 Feb 2024 51,736.20 | 1 | $43.15 |
| short | 21 Feb 2024 52,258.80 | 22 Feb 2024 51,213.60 | 1 | $93.90 |
| long | 31 Mar 2024 69,582.20 | 1 Apr 2024 71,280.00 | 1 | $116.07 |
| long | 31 Mar 2024 69,582.20 | 1 Apr 2024 71,280.00 | 1 | $116.07 |
| long | 7 Apr 2024 68,896.00 | 8 Apr 2024 69,585.00 | 1 | $44.94 |
| long | 7 Apr 2024 68,896.00 | 8 Apr 2024 70,273.90 | 1 | $97.81 |
| long | 14 Apr 2024 63,924.50 | 15 Apr 2024 65,661.90 | 1 | $129.00 |
| long | 14 Apr 2024 63,924.50 | 15 Apr 2024 65,661.90 | 1 | $129.00 |
| long | 25 Apr 2024 64,289.60 | 30 Apr 2024 61,075.10 | 5 | −$269.48 |
| long | 25 Apr 2024 64,289.60 | 30 Apr 2024 61,075.10 | 5 | −$269.48 |
| long | 30 May 2024 67,652.40 | 31 May 2024 68,352.20 | 1 | $44.92 |
| long | 30 May 2024 67,652.40 | 31 May 2024 69,005.50 | 1 | $93.98 |
| long | 2 Jun 2024 67,766.80 | 3 Jun 2024 68,444.50 | 1 | $44.37 |
| long | 2 Jun 2024 67,766.80 | 3 Jun 2024 69,122.20 | 1 | $96.58 |
| short | 4 Jun 2024 68,809.90 | 9 Jun 2024 69,310.50 | 5 | −$94.13 |
| long | 9 Jun 2024 69,310.50 | 10 Jun 2024 70,003.60 | 1 | $44.44 |
| long | 9 Jun 2024 69,310.50 | 14 Jun 2024 65,844.90 | 5 | −$269.30 |
| long | 22 Jun 2024 64,143.60 | 24 Jun 2024 60,936.40 | 2 | −$260.45 |
| long | 22 Jun 2024 64,143.60 | 24 Jun 2024 60,936.40 | 2 | −$260.45 |
| long | 20 Jul 2024 66,660.00 | 21 Jul 2024 67,326.60 | 1 | $43.00 |
| long | 20 Jul 2024 66,660.00 | 21 Jul 2024 67,993.20 | 1 | $93.59 |
| long | 28 Aug 2024 59,415.00 | 29 Aug 2024 60,009.20 | 1 | $39.56 |
| long | 28 Aug 2024 59,415.00 | 29 Aug 2024 60,603.30 | 1 | $86.11 |
| short | 10 Sep 2024 57,042.00 | 11 Sep 2024 56,471.60 | 1 | $44.14 |
| short | 10 Sep 2024 57,042.00 | 11 Sep 2024 55,901.20 | 1 | $96.06 |
| long | 7 Oct 2024 62,819.90 | 8 Oct 2024 62,224.00 | 1 | −$112.49 |
| short | 8 Oct 2024 62,224.00 | 9 Oct 2024 61,601.80 | 1 | $42.19 |
| short | 8 Oct 2024 62,224.00 | 9 Oct 2024 60,979.50 | 1 | $91.82 |
| long | 11 Oct 2024 60,326.40 | 12 Oct 2024 62,540.00 | 1 | $177.46 |
| long | 11 Oct 2024 60,326.40 | 12 Oct 2024 62,540.00 | 1 | $177.46 |
| long | 23 Oct 2024 67,426.00 | 24 Oct 2024 68,100.30 | 1 | $44.61 |
| long | 23 Oct 2024 67,426.00 | 24 Oct 2024 68,774.50 | 1 | $97.09 |
| long | 25 Oct 2024 68,198.30 | 28 Oct 2024 68,880.30 | 3 | $46.22 |
| long | 25 Oct 2024 68,198.30 | 28 Oct 2024 69,562.20 | 3 | $100.60 |
| long | 1 Nov 2024 70,292.00 | 6 Nov 2024 70,994.90 | 5 | $44.50 |
| long | 1 Nov 2024 70,292.00 | 6 Nov 2024 71,697.90 | 5 | $96.87 |
| long | 16 Nov 2024 91,032.10 | 18 Nov 2024 91,942.40 | 2 | $48.36 |
| long | 16 Nov 2024 91,032.10 | 19 Nov 2024 92,852.70 | 3 | $105.25 |
| long | 7 Dec 2024 99,740.80 | 8 Dec 2024 100,738.00 | 1 | $48.41 |
| long | 7 Dec 2024 99,740.80 | 9 Dec 2024 94,753.80 | 2 | −$293.35 |
| long | 11 Dec 2024 96,593.00 | 12 Dec 2024 101,125.00 | 1 | $244.17 |
| long | 11 Dec 2024 96,593.00 | 12 Dec 2024 101,125.00 | 1 | $244.17 |
| long | 20 Dec 2024 97,461.90 | 21 Dec 2024 98,436.50 | 1 | $46.76 |
| long | 20 Dec 2024 97,461.90 | 21 Dec 2024 99,411.10 | 1 | $101.79 |
| short | 3 Jan 2025 96,984.80 | 6 Jan 2025 101,834.00 | 3 | −$303.15 |
| short | 3 Jan 2025 96,984.80 | 6 Jan 2025 101,834.00 | 3 | −$303.15 |
| long | 14 Jan 2025 94,536.10 | 15 Jan 2025 96,560.90 | 1 | $108.09 |
| long | 14 Jan 2025 94,536.10 | 15 Jan 2025 96,560.90 | 1 | $108.09 |
| long | 24 Jan 2025 103,910.00 | 25 Jan 2025 104,949.00 | 1 | $47.17 |
| long | 24 Jan 2025 103,910.00 | 27 Jan 2025 98,714.80 | 3 | −$285.82 |
| long | 2 Feb 2025 100,636.00 | 3 Feb 2025 101,642.00 | 1 | $45.25 |
| long | 2 Feb 2025 100,636.00 | 3 Feb 2025 95,603.90 | 1 | −$274.23 |
| short | 11 May 2025 104,810.00 | 12 May 2025 103,761.00 | 1 | $45.97 |
| short | 11 May 2025 104,810.00 | 12 May 2025 102,713.00 | 1 | $100.03 |
| short | 10 Jun 2025 110,263.00 | 11 Jun 2025 109,160.00 | 1 | $47.75 |
| short | 10 Jun 2025 110,263.00 | 12 Jun 2025 108,058.00 | 2 | $103.91 |
| long | 23 Jun 2025 100,964.00 | 24 Jun 2025 105,334.00 | 1 | $225.31 |
| long | 23 Jun 2025 100,964.00 | 24 Jun 2025 105,334.00 | 1 | $225.31 |
| long | 25 Jul 2025 118,341.00 | 27 Jul 2025 119,524.00 | 2 | $48.09 |
| long | 25 Jul 2025 118,341.00 | 2 Aug 2025 112,424.00 | 8 | −$291.41 |
| long | 3 Aug 2025 112,546.00 | 4 Aug 2025 114,209.00 | 1 | $73.20 |
| long | 3 Aug 2025 112,546.00 | 4 Aug 2025 114,797.00 | 1 | $102.05 |
| short | 12 Aug 2025 118,686.00 | 14 Aug 2025 117,499.00 | 2 | $47.81 |
| short | 12 Aug 2025 118,686.00 | 18 Aug 2025 116,312.00 | 6 | $104.05 |
| long | 22 Aug 2025 112,500.00 | 23 Aug 2025 116,936.00 | 1 | $213.62 |
| long | 22 Aug 2025 112,500.00 | 23 Aug 2025 116,936.00 | 1 | $213.62 |
| long | 25 Aug 2025 113,494.00 | 29 Aug 2025 107,819.00 | 4 | −$300.50 |
| long | 25 Aug 2025 113,494.00 | 29 Aug 2025 107,819.00 | 4 | −$300.50 |
| long | 23 Sep 2025 112,651.00 | 24 Sep 2025 113,778.00 | 1 | $46.78 |
| long | 23 Sep 2025 112,651.00 | 1 Oct 2025 114,904.00 | 8 | $101.83 |
| long | 9 Oct 2025 123,306.00 | 10 Oct 2025 117,141.00 | 1 | −$298.56 |
| long | 9 Oct 2025 123,306.00 | 10 Oct 2025 117,141.00 | 1 | −$298.56 |
| long | 18 Oct 2025 106,432.00 | 19 Oct 2025 107,496.00 | 1 | $45.19 |
| long | 18 Oct 2025 106,432.00 | 19 Oct 2025 108,560.00 | 1 | $98.37 |
| long | 23 Oct 2025 107,567.00 | 24 Oct 2025 110,078.00 | 1 | $118.90 |
| long | 23 Oct 2025 107,567.00 | 24 Oct 2025 110,078.00 | 1 | $118.90 |
| short | 27 Oct 2025 114,559.00 | 28 Oct 2025 113,414.00 | 1 | $48.93 |
| short | 27 Oct 2025 114,559.00 | 28 Oct 2025 112,268.00 | 1 | $106.48 |
| long | 31 Oct 2025 108,323.00 | 1 Nov 2025 109,608.00 | 1 | $57.94 |
| long | 31 Oct 2025 108,323.00 | 1 Nov 2025 110,489.00 | 1 | $103.42 |
| long | 4 Nov 2025 106,583.00 | 5 Nov 2025 101,254.00 | 1 | −$285.77 |
| long | 4 Nov 2025 106,583.00 | 5 Nov 2025 101,254.00 | 1 | −$285.77 |
| long | 18 Jan 2026 95,147.80 | 20 Jan 2026 90,390.40 | 2 | −$280.57 |
| long | 18 Jan 2026 95,147.80 | 20 Jan 2026 90,390.40 | 2 | −$280.57 |
| long | 31 Jan 2026 84,260.50 | 1 Feb 2026 78,741.10 | 1 | −$346.12 |
| long | 31 Jan 2026 84,260.50 | 1 Feb 2026 78,741.10 | 1 | −$346.12 |
| short | 10 Mar 2026 68,432.20 | 13 Mar 2026 71,853.80 | 3 | −$259.22 |
| short | 10 Mar 2026 68,432.20 | 13 Mar 2026 71,853.80 | 3 | −$259.22 |
| long | 30 Mar 2026 66,010.90 | 31 Mar 2026 66,797.40 | 1 | $47.50 |
| long | 30 Mar 2026 66,010.90 | 31 Mar 2026 67,331.10 | 1 | $84.38 |
| short | 7 Apr 2026 68,853.70 | 8 Apr 2026 72,296.30 | 1 | −$239.35 |
| short | 7 Apr 2026 68,853.70 | 8 Apr 2026 72,296.30 | 1 | −$239.35 |
| long | 26 Apr 2026 77,625.00 | 27 Apr 2026 78,657.60 | 1 | $52.22 |
| long | 26 Apr 2026 77,625.00 | 27 Apr 2026 79,177.50 | 1 | $81.86 |
| short | 28 Apr 2026 77,371.30 | 29 Apr 2026 76,342.80 | 1 | $52.06 |
| short | 28 Apr 2026 77,371.30 | 29 Apr 2026 75,823.90 | 1 | $81.65 |
| long | 5 May 2026 79,861.00 | 6 May 2026 80,905.50 | 1 | $53.50 |
| long | 5 May 2026 79,861.00 | 6 May 2026 81,458.20 | 1 | $85.47 |
| long | 9 May 2026 80,193.20 | 10 May 2026 80,995.10 | 1 | $39.33 |
| long | 9 May 2026 80,193.20 | 10 May 2026 81,797.00 | 1 | $85.61 |
| long | 13 May 2026 80,504.50 | 14 May 2026 81,309.50 | 1 | $39.17 |
| long | 13 May 2026 80,504.50 | 18 May 2026 76,479.30 | 5 | −$237.39 |
| long | 2 Jun 2026 71,408.90 | 3 Jun 2026 66,760.80 | 1 | −$295.56 |
| long | 2 Jun 2026 71,408.90 | 3 Jun 2026 66,760.80 | 1 | −$295.56 |
| long | 25 Jul 2026 64,140.00 | 26 Jul 2026 64,781.40 | 1 | $35.87 |
| long | 25 Jul 2026 64,140.00 | 26 Jul 2026 65,422.80 | 1 | $78.07 |
| short | 20 Aug 2026 69,334.80 | 21 Aug 2026 73,027.00 | 1 | −$254.91 |
| short | 20 Aug 2026 69,334.80 | 21 Aug 2026 73,027.00 | 1 | −$254.91 |
| long | 15 Sep 2026 78,189.20 | 18 Sep 2026 78,971.10 | 3 | $35.33 |
| long | 15 Sep 2026 78,189.20 | 18 Sep 2026 79,753.00 | 3 | $76.89 |
| short | 19 Sep 2026 80,883.90 | 21 Sep 2026 84,928.10 | 2 | −$226.14 |
| short | 19 Sep 2026 80,883.90 | 21 Sep 2026 84,928.10 | 2 | −$226.14 |
| long | 30 Sep 2026 83,663.70 | 1 Oct 2026 84,500.30 | 1 | $33.36 |
| long | 30 Sep 2026 83,663.70 | 2 Oct 2026 85,336.90 | 2 | $72.61 |
| short | 3 Oct 2026 84,518.00 | 7 Oct 2026 85,549.90 | 4 | −$108.53 |
| long | 7 Oct 2026 85,549.90 | 8 Oct 2026 81,272.40 | 1 | −$201.20 |
| long | 7 Oct 2026 85,549.90 | 8 Oct 2026 81,272.40 | 1 | −$201.20 |
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 |
|---|---|---|---|---|---|
| BTC 15 min this page | — | v4 strategy | −25.7% | 119 | 38.9% |
| MZ SRSI Strategy V1.0 by MightyZinger | ema sma highest lowest stdev rsi | v4 strategy | No trades on this market | ||
| BBPBΔ(OBV-PVT)BB - Time Series Decomposition & Volume Weighted by tathal | cum ema stdev sma highest lowest | v4 strategy | No trades on this market | ||
| RSI Overbought Oversold Divergence Strategy w- Buy-Sell Signals by imal_max | ema sma lowest highest rsi cum | v5 strategy | does not run in Zeal Terminal | ||
| VixFixLinReg-Strategy by Trendoscope | highest stdev sma lowest linreg | v4 strategy | −49.3% | 12 | 51.1% |
| Crunchster's Turtle and Trend System by Crunchster1 | lowest highest ema stdev sma | v5 strategy | +18.0% | 31 | 16.7% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 47 ms | With a workaround 1,000 bars in 113 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market.
“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/// © RafaelZioni//@version=4strategy(title = " BTC 15 min", overlay = true, pyramiding=1,initial_capital = 10000, default_qty_type= strategy.percent_of_equity, default_qty_value = 20, calc_on_order_fills=false, slippage=0,commission_type=strategy.commission.percent,commission_value=0.075)strat_dir_input = input(title="Strategy Direction", defval="all", options=["long", "short", "all"])strat_dir_value = strat_dir_input == "long" ? strategy.direction.long : strat_dir_input == "short" ? strategy.direction.short : strategy.direction.allstrategy.risk.allow_entry_in(strat_dir_value)price = closelength8 = input(30,title = 'length of channel')upmult = input(title = 'upper percent',type=input.float, step=0.1, defval=5)lowmult = input(title = 'lower percent',type=input.float, step=0.1, defval=5)basis = sma(close, length8)vup = upmult * price / 100vlow = lowmult * price / 100upper = basis + vuplower = basis - vlowplot(basis, color=color.red)//fastLength = input(3, title="Fast filter length ", minval=1)slowLength = input(21,title="Slow filter length", minval=1)source=closev1=ema(source,fastLength)v2=ema(source,slowLength)//leng=1p1=close[1]len55 = 10//taken from https://www.tradingview.com/script/Ql1FjjfX-security-free-MTF-example-JD/HTF = input("1D", type=input.resolution)ti = change( time(HTF) ) != 0T_c = fixnan( ti ? close : na )vrsi = rsi(cum(change(T_c) * volume), leng)pp=wma(vrsi,len55)d=(vrsi[1]-pp[1])len100 = 10x=ema(d,len100)//zx=x/-1col=zx > 0? color.lime : color.orange//tf10 = input("1", title = "Timeframe", type = input.resolution, options = ["1", "5", "15", "30", "60","120", "240","360","720", "D", "W"])length = input(50, title = "Period", type = input.integer)shift = input(1, title = "Shift", type = input.integer)hma(_src, _length)=> wma((2 * wma(_src, _length / 2)) - wma(_src, _length), round(sqrt(_length))) hma3(_src, _length)=> p = length/2 wma(wma(close,p/3)*3 - wma(close,p/2) - wma(close,p),p)b =security(syminfo.tickerid, tf10, hma3(close[1], length)[shift])//plot(a,color=color.gray)//plot(b,color=color.yellow)close_price = close[0]len = input(25)linear_reg = linreg(close_price, len, 0)buy=crossover(linear_reg, b) sell=crossunder(linear_reg, b) or crossunder(close[1],upper)//src2=lowsrc3=highMin =input(15)leni = timeframe.isintraday and timeframe.multiplier >= 1 ? Min / timeframe.multiplier * 7 : timeframe.isintraday and timeframe.multiplier < 60 ? 60 / timeframe.multiplier * 24 * 7 : 7l1 = wma(src2,leni)h1 = wma(src3,leni)//m=(h1+l1)/2//len5 = 100src5=m//multi = 2mean = ema(src5, len5) stddev = multi * stdev(src5, len5) b5 = mean + stddevs5 = mean - stddevvar bool long = navar bool short = nalong :=crossover(src5, s5) short := crossunder(src5, b5)var float last_open_long = navar float last_open_short = nalast_open_long := long ? close : nz(last_open_long[1])last_open_short := short ? close : nz(last_open_short[1])entry_value =last_open_longentry_value1=last_open_shortr=100//highb = highest(entry_value1, r) lowb = lowest(entry_value, r) d5 = highb - lowb me = (highb + lowb) / 2 h4 = highb - d5 * 0.236 c3 = highb - d5 * 0.382 c4 = highb - d5 * 0.618 l4 = highb - d5 * 0.764 //col2 = close >= me ? color.lime : color.red p5 = plot(upper, color=col2)p2 = plot(lower, color=col2)fill(p5, p2,color=col2)// ConditionslongCond = bool(na)shortCond = bool(na)longCond := crossover(zx,0) or buy shortCond := sell// Count your long short conditions for more control with PyramidingsectionLongs = 0sectionLongs := nz(sectionLongs[1])sectionShorts = 0sectionShorts := nz(sectionShorts[1])if longCond sectionLongs := sectionLongs + 1 sectionShorts := 0 sectionShortsif shortCond sectionLongs := 0 sectionShorts := sectionShorts + 1 sectionShorts// Pyramidingpyrl = 1// These check to see your signal and cross references it against the pyramiding settings abovelongCondition = longCond and sectionLongs <= pyrlshortCondition = shortCond and sectionShorts <= pyrl// Get the price of the last opened long or shortlast_open_longCondition = float(na)last_open_shortCondition = float(na)last_open_longCondition := longCondition ? open : nz(last_open_longCondition[1])last_open_shortCondition := shortCondition ? open : nz(last_open_shortCondition[1])// Check if your last postion was a long or a shortlast_longCondition = float(na)last_shortCondition = float(na)last_longCondition := longCondition ? time : nz(last_longCondition[1])last_shortCondition := shortCondition ? time : nz(last_shortCondition[1])in_longCondition = last_longCondition > last_shortConditionin_shortCondition = last_shortCondition > last_longCondition// Take profitisTPl = true//isTPs = input(false, "Take Profit Short")tp = input(2, "Exit Profit %", type=input.float)long_tp = isTPl and crossover(high, (1 + tp / 100) * last_open_longCondition) and longCondition == 0 and in_longCondition == 1//short_tp = isTPs and crossunder(low, (1 - tp / 100) * last_open_shortCondition) and //shortCondition == 0 and in_shortCondition == 1// Stop LossisSLl = input(true,"buy Loss Long")//isSLs = input(false, "buy Loss Short")sl = 0.0sl := input(5, " rebuy %", type=input.float)long_sl = isSLl and crossunder(low, (1 - sl / 100) * last_open_longCondition) and longCondition == 0 and in_longCondition == 1//short_sl = isSLs and crossover(high, (1 + sl / 100) * last_open_shortCondition) and //shortCondition == 0 and in_shortCondition == 1//// ConditionslongCond5 = bool(na)shortCond5 = bool(na)longCond5 := longConditionshortCond5 := long_tp// sectionLongs5 = 0sectionLongs5 := nz(sectionLongs5[1])sectionShorts5 = 0sectionShorts5 := nz(sectionShorts5[1])if longCond5 sectionLongs5 := sectionLongs5 + 1 sectionShorts5 := 0 sectionShorts5if shortCond5 sectionLongs5 := 0 sectionShorts5 := sectionShorts5 + 1 sectionShorts5// pyr5 = 1longCondition5 = longCond5 and sectionLongs5 <= pyr5shortCondition5 = shortCond5 and sectionShorts5 <= pyr5// Get the price of the last opened long or shortlast_open_longCondition5 = float(na)last_open_shortCondition5 = float(na)last_open_longCondition5 := longCondition5 ? open : nz(last_open_longCondition5[1])last_open_shortCondition5 := shortCondition5 ? open : nz(last_open_shortCondition5[1])last_longCondition5 = float(na)last_shortCondition5 = float(na)last_longCondition5 := longCondition5 ? time : nz(last_longCondition5[1])last_shortCondition5 := shortCondition5 ? time : nz(last_shortCondition5[1])in_longCondition5 = last_longCondition5 > last_shortCondition5in_shortCondition5 = last_shortCondition5 > last_longCondition5//filter=input(true)g(v, p) => round(v * (pow(10, p))) / pow(10, p)risk = input(100)leverage = input(1)c = g((strategy.equity * leverage / open) * (risk / 100), 4)//l =(v1 > v2 or filter == false ) and longCondition or long_sl////l = longCondition or long_sls=shortCondition5 if l strategy.entry("buy", strategy.long,c)if s strategy.entry("sell", strategy.short,c)per(pcnt) => strategy.position_size != 0 ? round(pcnt / 100 * strategy.position_avg_price / syminfo.mintick) : float(na)stoploss=input(title=" stop loss", defval=5, minval=0.01)los = per(stoploss)q1=input(title=" qty_percent1", defval=50, minval=1)q2=input(title=" qty_percent2", defval=50, minval=1)tp10=input(title=" Take profit1", defval=1, minval=0.01)tp20=input(title=" Take profit2", defval=2, minval=0.01)strategy.exit("x1", qty_percent = q1, profit = per(tp10), loss = los)strategy.exit("x2", qty_percent = q2, profit = per(tp20), loss = los)