Pine Script v4 · Strategy
TTM-SQUEEZE STRATEGY
A Pine Script v4 strategy built on SMA (source, 20), BB (source, 20) and Linreg or Highest or Lowest or SMA (20). It has 17 order rules, 8 entries among them, and trades long only with the default settings. Exits use a stop loss. Each trade commits 100% of equity and pays 0.1 commission. 15 settings; defaults include Start Date 1, Start Month 1 and Start Year 2020.
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 TTM-SQUEEZE STRATEGY repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 2 of 2 trades.
- How did TTM-SQUEEZE STRATEGY do on BTCUSDT 1D with default settings?
- −6.00%
- From 26 Jan 2024 to 21 Oct 2026, over 16 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can TTM-SQUEEZE STRATEGY 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 TTM-SQUEEZE STRATEGY use a stop loss?
- Yes
- strategy.exit sets a stop on line 121.
- Does TTM-SQUEEZE STRATEGY run in Zeal Terminal?
- Yes
- It compiles in 33 ms and runs 1,000 bars in 95 ms, in the browser.
BTCUSDT · 1D · default settings
- Plot
- Plot
- Plot
- Plot
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- −6.00%
- −$6.00
- Buy and hold
- +102.5%
- same period
- Closed trades
- 16
- 8 won · 8 lost
- Profitable
- 50.0%
- of closed trades
- Profit factor
- 0.85
- gross profit ÷ gross loss
- Max drawdown
- 26.33%
- −$27.94
One run with the author's default settings, $100 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, 7) ignores the settings line 45
Line 45 hard-codes 7 where line 29 uses “BB Length”. Changing those settings moves one band but not this one.
sma(close, 7)sma(close, length) -
Check
Every trade uses all the equity
default_qty_value is 100% of equity.
-
Note
No slippage
Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.
-
Note
Uses iff(), which v5 removed line 77
iff() on line 77, 77, 77. v5 writes it as the ternary c ? a : b.
-
Note
Uses transp =, which v5 removed line 79
transp = on line 79, 83, 84. v5 folds the transparency into the colour with color.new(c, transp).
-
Note
Uses long =, which v5 renamed line 87
long = on line 87, 91, 96, 100, 105, 109, 113, 117. v5 writes it as direction = strategy.long or strategy.short.
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, bb → ta.bb, linreg → ta.linreg, avg → math.avg, highest → ta.highest, lowest → ta.lowest, hma → ta.hma, wma → ta.wma, pivothigh → ta.pivothigh, pivotlow → ta.pivotlow, macd → ta.macd, crossunder → ta.crossunder, crossover → ta.crossover.
v4 → v5
VerifiedSame 16 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 4: //@version=4 → //@version=5
- Line 9: input(type = input.integer) → input.int()
- Line 10: input(type = input.integer) → input.int()
- Line 11: input(type = input.integer) → input.int()
- Line 14: input(type = input.bool) → input.bool()
- Line 16: input(type = input.bool) → input.bool()
42 more edits
- Line 17: input(type = input.bool) → input.bool()
- Line 18: input(type = input.bool) → input.bool()
- Line 19: input(type = input.bool) → input.bool()
- Line 20: input(type = input.bool) → input.bool()
- Line 25: input(type = input.integer) → input.int()
- Line 29: sma → ta.sma
- Line 30: bb → ta.bb
- Line 33: sma → ta.sma
- Line 34: range is reserved in v5: renamed range_
- Line 34: tr → ta.tr
- Line 35: sma → ta.sma
- Line 41: linreg → ta.linreg
- Line 41: avg → math.avg
- Line 41: avg → math.avg
- Line 41: highest → ta.highest
- Line 41: lowest → ta.lowest
- Line 41: sma → ta.sma
- Line 44: hma → ta.hma
- Line 45: sma → ta.sma
- Line 46: wma → ta.wma
- Line 50: pivothigh → ta.pivothigh
- Line 51: pivotlow → ta.pivotlow
- Line 52: pivothigh → ta.pivothigh
- Line 53: pivotlow → ta.pivotlow
- Line 56: macd → ta.macd
- Line 58: crossunder → ta.crossunder
- Line 66: crossover → ta.crossover
- Line 67: crossunder → ta.crossunder
- Line 77: iff(c, a, b) → (c ? a : b)
- Line 77: iff(c, a, b) → (c ? a : b)
- Line 77: iff(c, a, b) → (c ? a : b)
- Line 79: transp = 50 → color.new(bcolor, 50)
- Line 83: transp = 80 → color.new((buy[1] and not buy[2]) ? color.green : na, 80)
- Line 84: transp = 80 → color.new((sell[1] and not sell[2]) ? color.red : na, 80)
- Line 87: long = true → direction = strategy.long
- Line 91: long = true → direction = strategy.long
- Line 96: long = true → direction = strategy.long
- Line 100: long = true → direction = strategy.long
- Line 105: long = true → direction = strategy.long
- Line 109: long = true → direction = strategy.long
- Line 113: long = true → direction = strategy.long
- Line 117: long = true → direction = strategy.long
⋯// create base on http://www.dailyfx.com/forex_forum/coding-strategy-advisors-indicators-functions/237563-ttm-squeeze-indicator.html-//@version=4+//@version=5strategy(title="TTM-SQUEEZE STRATEGY", overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=100, commission_value = 0.1)////////////////////// USER INPUTS /////////////////////////⋯// Backtest Start Date //-startDate = input(title="Start Date", type=input.integer, defval=1, minval=1, maxval=31)+startDate = input.int(title="Start Date", defval=1, minval=1, maxval=31)-startMonth = input(title="Start Month", type=input.integer, defval=1, minval=1, maxval=12)+startMonth = input.int(title="Start Month", defval=1, minval=1, maxval=12)-startYear = input(title="Start Year", type=input.integer, defval=2020, minval=1800, maxval=2100)+startYear = input.int(title="Start Year", defval=2020, minval=1800, maxval=2100)afterStartDate = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0))////////////////////// USER INPUTS /////////////////////////-useTrend = input(true, title="Use Trend as Indicator", type=input.bool)+useTrend = input.bool(true, title="Use Trend as Indicator")trendMA = input(100, title="Trend Indicating MA Length")-useTrueRange = input(true, title="Use TrueRange (KC)", type=input.bool)+useTrueRange = input.bool(true, title="Use TrueRange (KC)")-activeTrader = input(false, title="Engage Active Trade Mode", type=input.bool)+activeTrader = input.bool(false, title="Engage Active Trade Mode")-hybridTrader = input(false, title="Engage Hybrid Trade Mode", type=input.bool)+hybridTrader = input.bool(false, title="Engage Hybrid Trade Mode")-safety = input(true, title="Engage Safety Mode", type=input.bool)+safety = input.bool(true, title="Engage Safety Mode")-showMACD = input(true, title="Plot MACD?", type=input.bool)+showMACD = input.bool(true, title="Plot MACD?")length = input(20, title="BB Length")⋯multKC = input(1.5, title="KC MultFactor")-lbp = input(title="Slope Lookback Periods", type=input.integer, defval= 3, minval = 1)+lbp = input.int(title="Slope Lookback Periods", defval= 3, minval = 1)////////////////////// TTM SQUEEZE VARIABLES /////////////////////////⋯source = close-basis = sma(source, length)+basis = ta.sma(source, length)-[middleBB, upperBB, lowerBB] = bb(source, length, mult)+[middleBB, upperBB, lowerBB] = ta.bb(source, length, mult)// Calculate KC //f_kc(src, length, multKC, useTrueRange) =>- float base = sma(src, length)+ float base = ta.sma(src, length)- float range = (useTrueRange) ? tr : (high - low)+ float range_ = (useTrueRange) ? ta.tr : (high - low)- float rangeSma = sma(range, length)+ float rangeSma = ta.sma(range_, length) [base, base + rangeSma * multKC, base - rangeSma * multKC]⋯noSqz = (sqzOn == false) and (sqzOff == false)-val = linreg(source - avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)), lengthKC,0)+val = ta.linreg(source - math.avg(math.avg(ta.highest(high, lengthKC), ta.lowest(low, lengthKC)),ta.sma(close,lengthKC)), lengthKC,0)////////////////////// OTHER VARIABLES /////////////////////////slopeMOM = 10 * ((val - val[lbp])/lbp)-maFast = hma(close, 7)+maFast = ta.hma(close, 7)-maMedium = sma(close, 7)+maMedium = ta.sma(close, 7)-maSlow = wma(close, trendMA)+maSlow = ta.wma(close, trendMA)slopeMA = (maSlow - maSlow[lbp])/lbp⋯lb = 3-mom_PH = pivothigh(val,lb,lb) and val > 0+mom_PH = ta.pivothigh(val,lb,lb) and val > 0-mom_PL = pivotlow(val,lb,lb) and val < 0+mom_PL = ta.pivotlow(val,lb,lb) and val < 0-slope_PH = pivothigh(slopeMOM,lb,lb) and val > 0+slope_PH = ta.pivothigh(slopeMOM,lb,lb) and val > 0-slope_PL = pivotlow(slopeMOM,lb,lb) and val < 0+slope_PL = ta.pivotlow(slopeMOM,lb,lb) and val < 0up = close > opendwn = close < open-[macdLine, signalLine, _] = macd(close, 12, 26, 9)+[macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)macdArea = macdLine - signalLine-macdBear = crossunder(macdLine, signalLine)+macdBear = ta.crossunder(macdLine, signalLine)////////////////////// TRIGGER CONDITIONS /////////////////////////⋯sell_A = maFast < maMedium-crossUp = showMACD and crossover(macdLine, signalLine)+crossUp = showMACD and ta.crossover(macdLine, signalLine)-crossDwn = showMACD and crossunder(macdLine, signalLine)+crossDwn = showMACD and ta.crossunder(macdLine, signalLine)////////////////////// PLOT VARIABLES /////////////////////////⋯ na-bcolor = iff( val > 0, iff( val > nz(val[1]), color.olive, color.gray), iff( val < nz(val[1]), color.maroon, color.gray))+bcolor = ( val > 0 ? ( val > nz(val[1]) ? color.olive : color.gray) : ( val < nz(val[1]) ? color.maroon : color.gray))scolor = sqzOn ? color.red : color.green -plot(val, color=bcolor, style=plot.style_histogram, linewidth=4, transp = 50)+plot(val, color=color.new(bcolor, 50), style=plot.style_histogram, linewidth=4)plot(0, color=scolor, style=plot.style_circles, linewidth=3)⋯plot(signalLine, color=plotSignal, style=plot.style_line, linewidth=2)-bgcolor(color=(buy[1] and not buy[2]) ? color.green : na, transp = 80)+bgcolor(color=color.new((buy[1] and not buy[2]) ? color.green : na, 80))-bgcolor(color=(sell[1] and not sell[2]) ? color.red : na, transp = 80)+bgcolor(color=color.new((sell[1] and not sell[2]) ? color.red : na, 80))////////////////////// PLACE ORDERS /////////////////////////if(not activeTrader and not hybridTrader and not useTrend and buy and afterStartDate)- strategy.entry("Buy - Long Term", long=true)+ strategy.entry("Buy - Long Term", direction = strategy.long)if(not activeTrader and not hybridTrader and not useTrend and sell and afterStartDate)⋯if(not activeTrader and not hybridTrader and useTrend and slopeMA > 0 and buy and afterStartDate)- strategy.entry("Buy - Long Term", long=true)+ strategy.entry("Buy - Long Term", direction = strategy.long)if(not activeTrader and not hybridTrader and useTrend and sell and afterStartDate)⋯if(not useTrend and not hybridTrader and activeTrader and buy_A and afterStartDate)- strategy.entry("Buy - Active Trading", long=true)+ strategy.entry("Buy - Active Trading", direction = strategy.long)if(not useTrend and not hybridTrader and activeTrader and sell_A and afterStartDate)⋯if(not hybridTrader and useTrend and slopeMA > 0 and activeTrader and buy_A and afterStartDate)- strategy.entry("Buy - Active Trading", long=true)+ strategy.entry("Buy - Active Trading", direction = strategy.long)if(not hybridTrader and useTrend and activeTrader and sell_A and afterStartDate)⋯if(hybridTrader and not useTrend and buy and afterStartDate)- strategy.entry("Buy - Long Term", long=true)+ strategy.entry("Buy - Long Term", direction = strategy.long)if(not useTrend and hybridTrader and sell and afterStartDate)⋯if(useTrend and hybridTrader and slopeMA > 0 and buy and afterStartDate)- strategy.entry("Buy - Long Term", long=true)+ strategy.entry("Buy - Long Term", direction = strategy.long)if(useTrend and hybridTrader and sell and afterStartDate)⋯if(not useTrend and hybridTrader and buy_A and afterStartDate)- strategy.entry("Buy - Active Trading", long=true)+ strategy.entry("Buy - Active Trading", direction = strategy.long)if(not useTrend and hybridTrader and sell_A and afterStartDate)⋯if(useTrend and hybridTrader and slopeMA > 0 and activeTrader and buy_A and afterStartDate)- strategy.entry("Buy - Active Trading", long=true)+ strategy.entry("Buy - Active Trading", direction = strategy.long)if(useTrend and hybridTrader and sell_A and afterStartDate)⋯Same 16 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 15: input() → input.int()
- Line 21: input() → input.int()
- Line 22: input() → input.int()
- Line 23: input() → input.int()
- Line 24: input() → input.float()
⋯useTrend = input.bool(true, title="Use Trend as Indicator")-trendMA = input(100, title="Trend Indicating MA Length")+trendMA = input.int(100, title="Trend Indicating MA Length")useTrueRange = input.bool(true, title="Use TrueRange (KC)")⋯showMACD = input.bool(true, title="Plot MACD?")-length = input(20, title="BB Length")+length = input.int(20, title="BB Length")-mult = input(2,title="BB MultFactor")+mult = input.int(2,title="BB MultFactor")-lengthKC=input(20, title="KC Length")+lengthKC=input.int(20, title="KC Length")-multKC = input(1.5, title="KC MultFactor")+multKC = input.float(1.5, title="KC MultFactor")lbp = input.int(title="Slope Lookback Periods", defval= 3, minval = 1)⋯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: 16 before, 19 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.
⋯// create base on http://www.dailyfx.com/forex_forum/coding-strategy-advisors-indicators-functions/237563-ttm-squeeze-indicator.html-//@version=5+//@version=6strategy(title="TTM-SQUEEZE STRATEGY", overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=100, commission_value = 0.1)////////////////////// USER INPUTS /////////////////////////⋯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 |
|---|---|---|---|
| Start Date | 1 | int (written input.integer) · min 1 · max 31 | afterStartDate |
| Start Month | 1 | int (written input.integer) · min 1 · max 12 | afterStartDate |
| Start Year | 2020 | int (written input.integer) · min 1800 · max 2100 | afterStartDate |
| Use Trend as Indicator | true | bool | entry Buy - Long Term close Buy - Long Term entry Buy - Long Term close Buy - Long Term entry Buy - Active Trading close Buy - Active Trading entry Buy - Active Trading close Buy - Active Trading entry Buy - Long Term close Buy - Long Term entry Buy - Long Term close Buy - Long Term entry Buy - Active Trading close Buy - Active Trading entry Buy - Active Trading close Buy - Active Trading line 86 line 88 line 90 line 92 line 95 line 97 line 99 line 101 line 104 line 106 line 108 line 110 line 112 line 114 line 116 line 118 |
| Trend Indicating MA Length | 100 | int | maSlow |
| Use TrueRange (KC) | true | bool | range middleKC upperKC lowerKC |
| Engage Active Trade Mode | false | bool | entry Buy - Long Term close Buy - Long Term entry Buy - Long Term close Buy - Long Term entry Buy - Active Trading close Buy - Active Trading entry Buy - Active Trading close Buy - Active Trading entry Buy - Active Trading line 86 line 88 line 90 line 92 line 95 line 97 line 99 line 101 line 116 |
| Engage Hybrid Trade Mode | false | bool | entry Buy - Long Term close Buy - Long Term entry Buy - Long Term close Buy - Long Term entry Buy - Active Trading close Buy - Active Trading entry Buy - Active Trading close Buy - Active Trading entry Buy - Long Term close Buy - Long Term entry Buy - Long Term close Buy - Long Term entry Buy - Active Trading close Buy - Active Trading entry Buy - Active Trading close Buy - Active Trading line 86 line 88 line 90 line 92 line 95 line 97 line 99 line 101 line 104 line 106 line 108 line 110 line 112 line 114 line 116 line 118 |
| Engage Safety Mode | true | bool | exit Sell Safety line 120 |
| Plot MACD? | true | bool | crossUp crossDwn plotMACD plotSignal |
| BB Length | 20 | int | basis middleBB upperBB lowerBB base rangeSma middleKC upperKC lowerKC |
| BB MultFactor | 2 | int | middleBB upperBB lowerBB |
| KC Length | 20 | int | val |
| KC MultFactor | 1.5 | float | middleKC upperKC lowerKC line 36 |
| Slope Lookback Periods | 3 | int (written input.integer) · min 1 | slopeMOM slopeMA |
What it calculates
- SMA (
sma,ta.smain v5)source, BB Length (20)basis · line 29 - BB (
bb,ta.bbin v5)source, BB Length (20), BB MultFactor (2)middleBB · line 30 - BB (
bb,ta.bbin v5)source, BB Length (20), BB MultFactor (2)upperBB · line 30 - BB (
bb,ta.bbin v5)source, BB Length (20), BB MultFactor (2)lowerBB · line 30 - SMA (
sma,ta.smain v5)src, BB Length (20)base · line 33 - SMA (
sma,ta.smain v5)range, BB Length (20)rangeSma · line 35 - Linreg / Highest / Lowest / SMA (
linreg,ta.linregin v5)source - avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)), KC Length (20), 0val · line 41 - HMA (
hma,ta.hmain v5)close, 7maFast · line 44 - SMA (
sma,ta.smain v5)close, 7maMedium · line 45 - WMA (
wma,ta.wmain v5)close, Trend Indicating MA Length (100)maSlow · line 46 - MACD (
macd,ta.macdin v5)close, 12, 26, 9macdLine · line 56 - MACD (
macd,ta.macdin v5)close, 12, 26, 9signalLine · line 56 - Crossunder (
crossunder,ta.crossunderin v5)macdLine, signalLinemacdBear · line 58
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 Buy - Long Term long | (not activeTrader and not hybridTrader and not useTrend and buy and afterStartDate) | On | 87 |
| Close Buy - Long Term | (not activeTrader and not hybridTrader and not useTrend and sell and afterStartDate) | On | 89 |
| Open Buy - Long Term long | (not activeTrader and not hybridTrader and useTrend and slopeMA > 0 and buy and afterStartDate) | On | 91 |
| Close Buy - Long Term | (not activeTrader and not hybridTrader and useTrend and sell and afterStartDate) | On | 93 |
| Open Buy - Active Trading long | (not useTrend and not hybridTrader and activeTrader and buy_A and afterStartDate) | On | 96 |
| Close Buy - Active Trading | (not useTrend and not hybridTrader and activeTrader and sell_A and afterStartDate) | On | 98 |
| Open Buy - Active Trading long | (not hybridTrader and useTrend and slopeMA > 0 and activeTrader and buy_A and afterStartDate) | On | 100 |
| Close Buy - Active Trading | (not hybridTrader and useTrend and activeTrader and sell_A and afterStartDate) | On | 102 |
| Open Buy - Long Term long | (hybridTrader and not useTrend and buy and afterStartDate) | On | 105 |
| Close Buy - Long Term | (not useTrend and hybridTrader and sell and afterStartDate) | On | 107 |
| Open Buy - Long Term long | (useTrend and hybridTrader and slopeMA > 0 and buy and afterStartDate) | On | 109 |
| Close Buy - Long Term | (useTrend and hybridTrader and sell and afterStartDate) | On | 111 |
| Open Buy - Active Trading long | (not useTrend and hybridTrader and buy_A and afterStartDate) | On | 113 |
| Close Buy - Active Trading | (not useTrend and hybridTrader and sell_A and afterStartDate) | On | 115 |
| Open Buy - Active Trading long | (useTrend and hybridTrader and slopeMA > 0 and activeTrader and buy_A and afterStartDate) | On | 117 |
| Close Buy - Active Trading | (useTrend and hybridTrader and sell_A and afterStartDate) | On | 119 |
| Exit Sell Safety stop | (safety and sqzOff) | On | 121 |
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 | −6.0% | +102.5% | 16 | 50% | 0.85 | 26.3% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −16.0% | +5.5% | 20 | 25% | 0.23 | 16.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +8.5% | +9.8% | 14 | 29% | 1.14 | 47.9% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | +1.5% | +8.4% | 26 | 23% | 1.05 | 16.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −21.3% | +16.7% | 13 | 38% | 0.67 | 51.7% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +8.3% | +21.5% | 18 | 28% | 1.30 | 11.4% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −13.6% | +148.3% | 17 | 41% | 0.74 | 24.9% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +2.7% | +17.1% | 23 | 30% | 1.11 | 12.0% | 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 | 12 | 50% | −$0.08 |
| Sideways market | 4 | 50% | −$5.82 |
| Falling market | 0 | — | $0.00 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
30.6%
The 95th percentile of the worst drawdown when the same 16 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 14.9% to 30.6%; the tick is what actually happened, 24.6%. Order luck alone moves it this much.
All 16 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 8 May 2024 62,312.10 | 12 May 2024 60,826.00 | 4 | −$2.58 |
| long | 14 May 2024 62,940.10 | 31 May 2024 68,352.20 | 17 | $8.17 |
| long | 4 Jun 2024 68,809.90 | 9 Jun 2024 69,310.50 | 5 | $0.56 |
| long | 10 Jun 2024 69,648.10 | 17 Jun 2024 65,509.40 | 7 | −$6.51 |
| long | 6 Dec 2024 96,945.60 | 19 Dec 2024 100,204.00 | 13 | $3.14 |
| long | 20 Dec 2024 97,461.90 | 30 Dec 2024 91,556.50 | 10 | −$6.42 |
| long | 7 Jan 2025 102,236.00 | 10 Jan 2025 92,552.50 | 3 | −$9.30 |
| long | 11 Jan 2025 94,726.10 | 29 Jan 2025 101,336.00 | 18 | $5.89 |
| long | 1 Feb 2025 102,430.00 | 24 Feb 2025 92,958.40 | 23 | −$8.76 |
| long | 7 Jun 2025 104,288.00 | 13 Jun 2025 105,672.00 | 6 | $0.95 |
| long | 17 Jun 2025 106,795.00 | 23 Jun 2025 100,549.00 | 6 | −$5.14 |
| long | 24 Jun 2025 105,334.00 | 22 Jul 2025 117,380.00 | 28 | $8.97 |
| long | 29 Jul 2025 118,062.00 | 18 Aug 2025 117,405.00 | 20 | −$0.67 |
| long | 11 Sep 2025 113,960.00 | 24 Sep 2025 111,999.00 | 13 | −$1.69 |
| long | 3 May 2026 78,686.80 | 13 May 2026 80,504.50 | 10 | $1.82 |
| long | 9 Sep 2026 78,455.80 | 30 Sep 2026 83,663.70 | 21 | $5.68 |
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 |
|---|---|---|---|---|---|
| TTM-SQUEEZE STRATEGY this page | — | v4 strategy | −6.0% | 16 | 26.3% |
| Bollinger -B Candles Strategy by Trendoscope | sma bb lowest highest | v4 strategy | +17.3% | 29 | 5.1% |
| Ultra Moving Average Rating Trend Strategy by exlux99 | wma highest lowest sma linreg hma | v5 strategy | +2.8% | 5 | 2.4% |
| Multi Trend Cross Strategy Template by TradeAutomation | hma linreg sma wma highest lowest | v5 strategy | +33.0% | 3 | 7.3% |
| BTC 15 min by RafaelZioni | sma wma linreg highest lowest | v4 strategy | −25.7% | 119 | 38.9% |
| VixFixLinReg-Strategy by Trendoscope | highest sma lowest linreg | v4 strategy | −49.3% | 12 | 51.1% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 33 ms | With a workaround 1,000 bars in 95 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as long = true as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 87, 91, 96, 100, 105, 109 and more) 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. 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/// © Hodl4dearlife// create base on http://www.dailyfx.com/forex_forum/coding-strategy-advisors-indicators-functions/237563-ttm-squeeze-indicator.html//@version=4strategy(title="TTM-SQUEEZE STRATEGY", overlay=false, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=100, commission_value = 0.1)////////////////////// USER INPUTS /////////////////////////// Only enter long positions //strategy.risk.allow_entry_in(strategy.direction.long)// Backtest Start Date //startDate = input(title="Start Date", type=input.integer, defval=1, minval=1, maxval=31)startMonth = input(title="Start Month", type=input.integer, defval=1, minval=1, maxval=12)startYear = input(title="Start Year", type=input.integer, defval=2020, minval=1800, maxval=2100)afterStartDate = (time >= timestamp(syminfo.timezone, startYear, startMonth, startDate, 0, 0))////////////////////// USER INPUTS /////////////////////////useTrend = input(true, title="Use Trend as Indicator", type=input.bool)trendMA = input(100, title="Trend Indicating MA Length")useTrueRange = input(true, title="Use TrueRange (KC)", type=input.bool)activeTrader = input(false, title="Engage Active Trade Mode", type=input.bool)hybridTrader = input(false, title="Engage Hybrid Trade Mode", type=input.bool)safety = input(true, title="Engage Safety Mode", type=input.bool)showMACD = input(true, title="Plot MACD?", type=input.bool)length = input(20, title="BB Length")mult = input(2,title="BB MultFactor")lengthKC=input(20, title="KC Length")multKC = input(1.5, title="KC MultFactor")lbp = input(title="Slope Lookback Periods", type=input.integer, defval= 3, minval = 1)////////////////////// TTM SQUEEZE VARIABLES /////////////////////////// Calculate BB //source = closebasis = sma(source, length)[middleBB, upperBB, lowerBB] = bb(source, length, mult)// Calculate KC //f_kc(src, length, multKC, useTrueRange) => float base = sma(src, length) float range = (useTrueRange) ? tr : (high - low) float rangeSma = sma(range, length) [base, base + rangeSma * multKC, base - rangeSma * multKC][middleKC, upperKC, lowerKC] = f_kc(source, length, multKC, useTrueRange)sqzOn = (lowerBB > lowerKC) and (upperBB < upperKC)sqzOff = not sqzOnnoSqz = (sqzOn == false) and (sqzOff == false)val = linreg(source - avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)), lengthKC,0)////////////////////// OTHER VARIABLES /////////////////////////slopeMOM = 10 * ((val - val[lbp])/lbp)maFast = hma(close, 7)maMedium = sma(close, 7)maSlow = wma(close, trendMA)slopeMA = (maSlow - maSlow[lbp])/lbpslopeTrend = slopeMA > 0lb = 3mom_PH = pivothigh(val,lb,lb) and val > 0mom_PL = pivotlow(val,lb,lb) and val < 0slope_PH = pivothigh(slopeMOM,lb,lb) and val > 0slope_PL = pivotlow(slopeMOM,lb,lb) and val < 0up = close > opendwn = close < open[macdLine, signalLine, _] = macd(close, 12, 26, 9)macdArea = macdLine - signalLinemacdBear = crossunder(macdLine, signalLine)////////////////////// TRIGGER CONDITIONS ////////////////////////////buy = sqzOff and sqzOn[1] and upbuy = sqzOn and slopeTrend//sell = sqzOff and sqzOn[1] and dwnsell = macdBearbuy_A = sqzOn[1] and maFast > maMediumsell_A = maFast < maMediumcrossUp = showMACD and crossover(macdLine, signalLine)crossDwn = showMACD and crossunder(macdLine, signalLine)////////////////////// PLOT VARIABLES /////////////////////////plotMACD = if showMACD color.tealelse naplotSignal = if showMACD color.redelse nabcolor = iff( val > 0, iff( val > nz(val[1]), color.olive, color.gray), iff( val < nz(val[1]), color.maroon, color.gray))scolor = sqzOn ? color.red : color.green plot(val, color=bcolor, style=plot.style_histogram, linewidth=4, transp = 50)plot(0, color=scolor, style=plot.style_circles, linewidth=3)plot(macdLine, color=plotMACD, style=plot.style_line, linewidth=2)plot(signalLine, color=plotSignal, style=plot.style_line, linewidth=2)bgcolor(color=(buy[1] and not buy[2]) ? color.green : na, transp = 80)bgcolor(color=(sell[1] and not sell[2]) ? color.red : na, transp = 80)////////////////////// PLACE ORDERS /////////////////////////if(not activeTrader and not hybridTrader and not useTrend and buy and afterStartDate) strategy.entry("Buy - Long Term", long=true)if(not activeTrader and not hybridTrader and not useTrend and sell and afterStartDate) strategy.close("Buy - Long Term")if(not activeTrader and not hybridTrader and useTrend and slopeMA > 0 and buy and afterStartDate) strategy.entry("Buy - Long Term", long=true)if(not activeTrader and not hybridTrader and useTrend and sell and afterStartDate) strategy.close("Buy - Long Term")/// Active Trader Mode ///if(not useTrend and not hybridTrader and activeTrader and buy_A and afterStartDate) strategy.entry("Buy - Active Trading", long=true)if(not useTrend and not hybridTrader and activeTrader and sell_A and afterStartDate) strategy.close("Buy - Active Trading")if(not hybridTrader and useTrend and slopeMA > 0 and activeTrader and buy_A and afterStartDate) strategy.entry("Buy - Active Trading", long=true)if(not hybridTrader and useTrend and activeTrader and sell_A and afterStartDate) strategy.close("Buy - Active Trading") /// HYBRID MODE ///if(hybridTrader and not useTrend and buy and afterStartDate) strategy.entry("Buy - Long Term", long=true)if(not useTrend and hybridTrader and sell and afterStartDate) strategy.close("Buy - Long Term")if(useTrend and hybridTrader and slopeMA > 0 and buy and afterStartDate) strategy.entry("Buy - Long Term", long=true)if(useTrend and hybridTrader and sell and afterStartDate) strategy.close("Buy - Long Term")if(not useTrend and hybridTrader and buy_A and afterStartDate) strategy.entry("Buy - Active Trading", long=true)if(not useTrend and hybridTrader and sell_A and afterStartDate) strategy.close("Buy - Active Trading")if(useTrend and hybridTrader and slopeMA > 0 and activeTrader and buy_A and afterStartDate) strategy.entry("Buy - Active Trading", long=true)if(useTrend and hybridTrader and sell_A and afterStartDate) strategy.close("Buy - Active Trading")if(safety and sqzOff) strategy.exit("Sell Safety", "Buy - Long Term", stop = lowerBB)