Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (15)
40,00060,00080,000100,000120,000AprJulOct2025AprJulOct2026AprJulOctPlot$96$203Equity from $100
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 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.
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

Verified

Same 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)⋯

Clean v5

VerifiedDownload the v5 script

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.

SettingDefaultType and rangeFeeds
Start Date1int (written input.integer) · min 1 · max 31afterStartDate
Start Month1int (written input.integer) · min 1 · max 12afterStartDate
Start Year2020int (written input.integer) · min 1800 · max 2100afterStartDate
Use Trend as Indicatortrueboolentry 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 Length100intmaSlow
Use TrueRange (KC)trueboolrange middleKC upperKC lowerKC
Engage Active Trade Modefalseboolentry 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 Modefalseboolentry 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 Modetrueboolexit Sell Safety line 120
Plot MACD?trueboolcrossUp crossDwn plotMACD plotSignal
BB Length20intbasis middleBB upperBB lowerBB base rangeSma middleKC upperKC lowerKC
BB MultFactor2intmiddleBB upperBB lowerBB
KC Length20intval
KC MultFactor1.5floatmiddleKC upperKC lowerKC line 36
Slope Lookback Periods3int (written input.integer) · min 1slopeMOM slopeMA

What it calculates

  • SMA (sma, ta.sma in v5)source, BB Length (20)basis · line 29
  • BB (bb, ta.bb in v5)source, BB Length (20), BB MultFactor (2)middleBB · line 30
  • BB (bb, ta.bb in v5)source, BB Length (20), BB MultFactor (2)upperBB · line 30
  • BB (bb, ta.bb in v5)source, BB Length (20), BB MultFactor (2)lowerBB · line 30
  • SMA (sma, ta.sma in v5)src, BB Length (20)base · line 33
  • SMA (sma, ta.sma in v5)range, BB Length (20)rangeSma · line 35
  • Linreg / Highest / Lowest / SMA (linreg, ta.linreg in v5)source - avg(avg(highest(high, lengthKC), lowest(low, lengthKC)),sma(close,lengthKC)), KC Length (20), 0val · line 41
  • HMA (hma, ta.hma in v5)close, 7maFast · line 44
  • SMA (sma, ta.sma in v5)close, 7maMedium · line 45
  • WMA (wma, ta.wma in v5)close, Trend Indicating MA Length (100)maSlow · line 46
  • MACD (macd, ta.macd in v5)close, 12, 26, 9macdLine · line 56
  • MACD (macd, ta.macd in v5)close, 12, 26, 9signalLine · line 56
  • Crossunder (crossunder, ta.crossunder in 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.

lengthBB Lengthsetting · 20multBB MultFactorsetting · 2lowlowprice datahighhighprice dataclosecloseprice datalengthKCKC Lengthsetting · 20trendMATrend Indicating MA Len…setting · 100multKCKC MultFactorsetting · 1.5lbpSlope Lookback Periodssetting · 3timetimeprice datastartYearStart Yearsetting · 2020startMonthStart Monthsetting · 1startDateStart Datesetting · 1openopenprice databasisSMA→ basismiddleBBBB→ middleBBupperBBBB→ upperBBlowerBBBB→ lowerBBbaseSMA→ baserangeSmaSMA→ rangeSmavalLinreg / Highest / Lowe…→ valmaFastHMA→ maFastmaMediumSMA→ maMediummaSlowWMA→ maSlowmacdLineMACD→ macdLinesignalLineMACD→ signalLinemacdBearCrossunder→ macdBearsourcesourcevaluerangerangevaluemiddleKC, upperKC, lowerKCmiddleKC · upperKC +13 valuesslopeMOMslopeMOMvalueslopeMAslopeMAvaluemacdAreamacdAreavaluesellsellvalueafterStartDateafterStartDateconditionsqzOffsqzOffconditionbuybuyconditionbuy_Abuy_Aconditionsell_Asell_AconditionsqzOnsqzOnconditionnoSqznoSqzconditionslopeTrendslopeTrendconditionmom_PH, mom_PLmom_PH · mom_PL2 conditionsslope_PH, slope_PLslope_PH · slope_PL2 conditionsup, dwnup · dwn2 conditionscrossUp, crossDwncrossUp · crossDwn2 conditionsplotMACD, plotSignal, bcolor, scolorColourplotMACD · plotSignal +2entry:Buy - Long TermOpen Buy - Long Termstrategy.entryclose:Buy - Long TermClose Buy - Long Termstrategy.closeentry:Buy - Active TradingOpen Buy - Active Tradi…strategy.entryclose:Buy - Active TradingClose Buy - Active Trad…strategy.closeexit:Sell Safetyexit Sell Safetystrategy.exitplot:79plotplotplot:80plotplotplot:81plotplotplot:82plotplotbgcolor:83bgcolorbgcolorbgcolor:84bgcolorbgcolor

Order rules

OrderFires whenBy defaultLine
Open Buy - Long Term long(not activeTrader and not hybridTrader and not useTrend and buy and afterStartDate)On87
Close Buy - Long Term(not activeTrader and not hybridTrader and not useTrend and sell and afterStartDate)On89
Open Buy - Long Term long(not activeTrader and not hybridTrader and useTrend and slopeMA > 0 and buy and afterStartDate)On91
Close Buy - Long Term(not activeTrader and not hybridTrader and useTrend and sell and afterStartDate)On93
Open Buy - Active Trading long(not useTrend and not hybridTrader and activeTrader and buy_A and afterStartDate)On96
Close Buy - Active Trading(not useTrend and not hybridTrader and activeTrader and sell_A and afterStartDate)On98
Open Buy - Active Trading long(not hybridTrader and useTrend and slopeMA > 0 and activeTrader and buy_A and afterStartDate)On100
Close Buy - Active Trading(not hybridTrader and useTrend and activeTrader and sell_A and afterStartDate)On102
Open Buy - Long Term long(hybridTrader and not useTrend and buy and afterStartDate)On105
Close Buy - Long Term(not useTrend and hybridTrader and sell and afterStartDate)On107
Open Buy - Long Term long(useTrend and hybridTrader and slopeMA > 0 and buy and afterStartDate)On109
Close Buy - Long Term(useTrend and hybridTrader and sell and afterStartDate)On111
Open Buy - Active Trading long(not useTrend and hybridTrader and buy_A and afterStartDate)On113
Close Buy - Active Trading(not useTrend and hybridTrader and sell_A and afterStartDate)On115
Open Buy - Active Trading long(useTrend and hybridTrader and slopeMA > 0 and activeTrader and buy_A and afterStartDate)On117
Close Buy - Active Trading(useTrend and hybridTrader and sell_A and afterStartDate)On119
Exit Sell Safety stop(safety and sqzOff)On121

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.

2/2trades 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−6.0%+102.5%1650%0.8526.3%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−16.0%+5.5%2025%0.2316.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+8.5%+9.8%1429%1.1447.9%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h+1.5%+8.4%2623%1.0516.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−21.3%+16.7%1338%0.6751.7%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+8.3%+21.5%1828%1.3011.4%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−13.6%+148.3%1741%0.7424.9%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+2.7%+17.1%2330%1.1112.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 barsTradesWonP&L
Rising market1250%−$0.08
Sideways market450%−$5.82
Falling market0—$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.

0%35%
All 16 trades
SideEntryExitBarsP&L
long8 May 2024 62,312.1012 May 2024 60,826.004−$2.58
long14 May 2024 62,940.1031 May 2024 68,352.2017$8.17
long4 Jun 2024 68,809.909 Jun 2024 69,310.505$0.56
long10 Jun 2024 69,648.1017 Jun 2024 65,509.407−$6.51
long6 Dec 2024 96,945.6019 Dec 2024 100,204.0013$3.14
long20 Dec 2024 97,461.9030 Dec 2024 91,556.5010−$6.42
long7 Jan 2025 102,236.0010 Jan 2025 92,552.503−$9.30
long11 Jan 2025 94,726.1029 Jan 2025 101,336.0018$5.89
long1 Feb 2025 102,430.0024 Feb 2025 92,958.4023−$8.76
long7 Jun 2025 104,288.0013 Jun 2025 105,672.006$0.95
long17 Jun 2025 106,795.0023 Jun 2025 100,549.006−$5.14
long24 Jun 2025 105,334.0022 Jul 2025 117,380.0028$8.97
long29 Jul 2025 118,062.0018 Aug 2025 117,405.0020−$0.67
long11 Sep 2025 113,960.0024 Sep 2025 111,999.0013−$1.69
long3 May 2026 78,686.8013 May 2026 80,504.5010$1.82
long9 Sep 2026 78,455.8030 Sep 2026 83,663.7021$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.

ScriptSharesTypeNetTradesMax drawdown
TTM-SQUEEZE STRATEGY this page—v4 strategy−6.0%1626.3%
Bollinger -B Candles Strategy by Trendoscopesma bb lowest highestv4 strategy+17.3%295.1%
Ultra Moving Average Rating Trend Strategy by exlux99wma highest lowest sma linreg hmav5 strategy+2.8%52.4%
Multi Trend Cross Strategy Template by TradeAutomationhma linreg sma wma highest lowestv5 strategy+33.0%37.3%
BTC 15 min by RafaelZionisma wma linreg highest lowestv4 strategy−25.7%11938.9%
VixFixLinReg-Strategy by Trendoscopehighest sma lowest linregv4 strategy−49.3%1251.1%

Where it runs

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