Zeal Terminal Open in Zeal Terminal

Pine Script v5 · Strategy

Twin Optimized Trend Tracker Strategy TOTT

A Pine Script v5 strategy built on Linreg (close, 40), SMA or EMA or WMA (close, 40) and Crossover (MAvg, OTTup[2]). It has 2 order rules, 2 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade is one contract and pays no commission. 15 settings; defaults include Source close, OTT Period 40 and Optimization Constant 1.

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 Twin Optimized Trend Tracker Strategy TOTT 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 Twin Optimized Trend Tracker Strategy TOTT do on BTCUSDT 1D with default settings?
+4.51%
From 26 Jan 2024 to 21 Oct 2026, over 8 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Does Twin Optimized Trend Tracker Strategy TOTT run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L99:C56: 'linewidth' must be at least 1 in Pine Script v6. The v6 version is shown for reference and is not offered as a download.
Does Twin Optimized Trend Tracker Strategy TOTT use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.
Does Twin Optimized Trend Tracker Strategy TOTT run in Zeal Terminal?
Yes
It compiles in 37 ms and runs 1,000 bars in 87 ms, in the browser.

BTCUSDT · 1D · default settings

  • Support Line
  • OTTup
  • OTTdown
  • Buy
  • Sell
  • 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)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$1,051,510$2,025,273Equity from $1,000,000
Binance BTCUSDT 1D candles, 26 Jan 2024 to 21 Oct 2026, 1,000 bars, default settings. Triangles mark entries; circles mark exits. Lines are what the script plots.
Net profit
+4.51%
$45,143.20
Buy and hold
+102.5%
same period
Closed trades
8
4 won · 4 lost
Profitable
50.0%
of closed trades
Profit factor
2.60
gross profit ÷ gross loss
Max drawdown
1.40%
−$14,192.70

One run with the author's default settings, $1,000,000 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.

  • Check

    1 setting does nothing

    “=Backtest Inputs=” is declared but never read.

  • Check

    No stop loss

    Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.

  • Check

    No commission

    The backtest assumes free trading. Results on any real exchange will be lower.

  • Note

    No slippage

    Fills are assumed at the exact open price. Add slippage in the properties for a more realistic test.

  • Note

    Uses an argument v6 removed

    when = on line 117, 119. The upgraded version below moves each call inside an if block.

Settings

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

SettingDefaultType and rangeFeeds
Sourceclosesourcevud1 vdd1 VAR WWMA zxEMAData ZLEMA lrc lrc1 TSF ma MAvg
OTT Period40int · min 1valpha VAR wwalpha WWMA zxLag ZLEMA lrc lrc1 TSF ma MAvg
Optimization Constant1float · min 0 · step 0.1fark OTT
Twin OTT Coefficient0.001float · min 0 · step 0.001OTTup OTTdn
Show Support Line?trueboolSupport Line
Show Signals?trueboolBuy Sell
Moving Average TypeVARstring · options ['SMA', 'EMA', 'WMA', 'TMA', 'VAR', 'WWMA', 'ZLEMA', 'TSF']line 48 line 51 line 54 line 57 line 60 line 63 line 66 line 69
Highlighter On/Off ?trueboollongFillColor shortFillColor
=Backtest Inputs=trueboolunused
From Day1int · min 1 · max 31Start
From Month1int · min 1 · max 12Start
From Year2005int · min 2005Start
To Day1int · min 1 · max 31Finish
To Month1int · min 1 · max 12Finish
To Year9999int · min 2006Finish

What it calculates

  • LinregSource (close), OTT Period (40), 0lrc · line 40
  • LinregSource (close), OTT Period (40), 1lrc1 · line 41
  • SMA / EMA / WMASource (close), OTT Period (40)ma · line 49
  • CrossoverMAvg, OTTup[2]buySignalk · line 91
  • CrossunderMAvg, OTTdn[2]sellSignalk · line 92
  • BarssincebuySignalkK1 · line 93
  • BarssincesellSignalkK2 · line 94
  • BarssincebuySignalk[1]O1 · line 95
  • BarssincesellSignalk[1]O2 · line 96

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.

closecloseprice datalengthOTT Periodsetting · 40percentOptimization Constantsetting · 1coeffTwin OTT Coefficientsetting · 0.001FromYearFrom Yearsetting · 2005FromMonthFrom Monthsetting · 1FromDayFrom Daysetting · 1ToYearTo Yearsetting · 9999ToMonthTo Monthsetting · 1ToDayTo Daysetting · 1lowlowprice datahighhighprice dataohlc4ohlc4price datalrcLinreg→ lrclrc1Linreg→ lrc1maSMA / EMA / WMA→ mabuySignalkCrossover→ buySignalksellSignalkCrossunder→ sellSignalkK1Barssince→ K1K2Barssince→ K2O1Barssince→ O1O2Barssince→ O2valpha, wwalpha, zxLagvalpha · wwalpha +13 valuesvud1, vdd1vud1 · vdd12 valuesvUDvUDvaluevDDvDDvaluevCMOvCMOvalueVAR, WWMA, ZLEMA, TSF, MAvgVAR · WWMA +35 valueszxEMADatazxEMADatavaluelrslrsvaluefarkfarkvaluelongStoplongStopvaluelongStopPrevlongStopPrevvalueshortStopshortStopvalueshortStopPrevshortStopPrevvaluedirdirvalueMTMTvalueOTTOTTvalueOTTup, OTTdnOTTup · OTTdn2 valuesStartStartvalueFinishFinishvaluelongFillColor, shortFillColorColourlongFillColor · shortFillColorentry:LongOpen Longstrategy.entryentry:ShortOpen Shortstrategy.entryplot:88Support Lineplotplot:89OTTupplotplot:90OTTdownplotplotshape:97Buyplotshapeplotshape:98Sellplotshapeplot:99plotfill:UpTrend HighligterUpTrend Highligterfillfill:DownTrend HighligterDownTrend Highligterfillfill:Flat Zone HighligterFlat Zone Highligterfill

Order rules

OrderFires whenBy defaultLine
Open Long longTimerange()On117
Open Short shortTimerange()On119

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+4.5%+102.5%850%2.601.4%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−1.2%+5.5%729%0.552.5%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+0.1%+9.8%850%1.370.3%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−0.0%+8.4%520%0.990.1%8 May 2026 – 21 Oct 2026
SOLUSDT 1D+0.0%+16.7%1242%1.000.0%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h−0.0%+21.5%714%0.720.0%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−0.0%+148.3%1233%0.920.1%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+0.0%+17.1%367%2.900.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 market10%−$6,206.16
Sideways market757%$51,349.30
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?

2.7%

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

0%3%
All 8 trades
SideEntryExitBarsP&L
long4 Feb 2024 43,011.106 Aug 2024 54,018.80184$11,007.70
short6 Aug 2024 54,018.8023 Sep 2024 63,578.8048−$9,559.94
long23 Sep 2024 63,578.801 Mar 2025 84,349.90159$20,771.20
short1 Mar 2025 84,349.9025 Apr 2025 93,980.5055−$9,630.52
long25 Apr 2025 93,980.5020 Oct 2025 108,643.00178$14,662.30
short20 Oct 2025 108,643.0012 May 2026 81,745.70204$26,897.10
long12 May 2026 81,745.7023 May 2026 75,539.5011−$6,206.16
short23 May 2026 75,539.5022 Aug 2026 78,338.0091−$2,798.53

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
Twin Optimized Trend Tracker Strategy TOTT this page—v5 strategy+4.5%81.4%
MACD ReLoaded STRATEGY by KivancOzbilgicema linreg wma sma barssincev5 strategy+7.8%315.1%
Linear Regression MA - Strategy by lazy_capitalistsma linreg emav5 strategy−1,240.4%10318.7%
Forex SWING Trader by SoftKill21wma ema smav4 strategyNo trades on this market
Dazzling Bolts by OrcChieftainsma ema barssincev4 strategy+8.5%1413.0%
High-Low Channel Multi averages Crypto Swing strategy by exlux99sma ema wma linregv4 strategyNo trades on this market

Upgrade and export

Written in Pine Script v5. The clean-v5 step types the settings and moves when = into if blocks, which v6 requires; it is run before and after like any upgrade.

  • 2 strategy calls use the when = argument (line 117, 119). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
  • 5 settings use the untyped input() (line 8, 12, 13, 15, 105). It still compiles in v6; input.int, input.float or input.source state the type.
  • No v6-only features. v6 is not needed to run this script.

Clean v5

VerifiedDownload the v5 script

Same 8 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.

  • Line 8: input() → input.source()
  • Line 12: input() → input.bool()
  • Line 13: input() → input.bool()
  • Line 15: input() → input.bool()
  • Line 105: input() → input.bool()
  • Line 117: when = Timerange() → if block
  • Line 119: when = Timerange() → if block
⋯strategy('Twin Optimized Trend Tracker', 'TOTT', overlay=true)-src = input(close, title='Source')+src = input.source(close, title='Source')length = input.int(40, 'OTT Period', minval=1)⋯coeff = input.float(0.001, 'Twin OTT Coefficient', step=0.001, minval=0)-showsupport = input(title='Show Support Line?', defval=true)+showsupport = input.bool(title='Show Support Line?', defval=true)-showsignalsk = input(title='Show Signals?', defval=true)+showsignalsk = input.bool(title='Show Signals?', defval=true)mav = input.string(title='Moving Average Type', defval='VAR', options=['SMA', 'EMA', 'WMA', 'TMA', 'VAR', 'WWMA', 'ZLEMA', 'TSF'])-highlighting = input(title='Highlighter On/Off ?', defval=true)+highlighting = input.bool(title='Highlighter On/Off ?', defval=true)Var_Func(src, length) =>⋯fill(pALLup, pALLdn, title='Flat Zone Highligter', color=color.new(color.blue, 90))-dummy0 = input(true, title='=Backtest Inputs=')+dummy0 = input.bool(true, title='=Backtest Inputs=')FromDay = input.int(defval=1, title='From Day', minval=1, maxval=31)⋯if buySignalk-    strategy.entry('Long', strategy.long, when=Timerange())+    if Timerange()+        strategy.entry('Long', strategy.long)if sellSignalk-    strategy.entry('Short', strategy.short, when=Timerange())+    if Timerange()+        strategy.entry('Short', strategy.short)

Does it run in Pine Script v6?

No

The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L99:C56: 'linewidth' must be at least 1 in Pine Script v6. The v6 version is shown for reference and is not offered as a download. It differs from the v5 version by 1 edit.

-//@version=5+//@version=6// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 37 msYes 1,000 bars in 87 msNot measured
PineTSNot testedNot testedNot measured

“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.

Source

Copied verbatim from the author's published script, with its licence header intact. The author may have updated the original since this snapshot.

//@version=5// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/// © KivancOzbilgic//created by: @Anil_Ozeksi//developer: ANIL ÖZEKŞİ//author: @kivancozbilgicstrategy('Twin Optimized Trend Tracker', 'TOTT', overlay=true)src = input(close, title='Source')length = input.int(40, 'OTT Period', minval=1)percent = input.float(1, 'Optimization Constant', step=0.1, minval=0)coeff = input.float(0.001, 'Twin OTT Coefficient', step=0.001, minval=0)showsupport = input(title='Show Support Line?', defval=true)showsignalsk = input(title='Show Signals?', defval=true)mav = input.string(title='Moving Average Type', defval='VAR', options=['SMA', 'EMA', 'WMA', 'TMA', 'VAR', 'WWMA', 'ZLEMA', 'TSF'])highlighting = input(title='Highlighter On/Off ?', defval=true)Var_Func(src, length) =>    valpha = 2 / (length + 1)    vud1 = src > src[1] ? src - src[1] : 0    vdd1 = src < src[1] ? src[1] - src : 0    vUD = math.sum(vud1, 9)    vDD = math.sum(vdd1, 9)    vCMO = nz((vUD - vDD) / (vUD + vDD))    VAR = 0.0    VAR := nz(valpha * math.abs(vCMO) * src) + (1 - valpha * math.abs(vCMO)) * nz(VAR[1])    VARVAR = Var_Func(src, length)Wwma_Func(src, length) =>    wwalpha = 1 / length    WWMA = 0.0    WWMA := wwalpha * src + (1 - wwalpha) * nz(WWMA[1])    WWMAWWMA = Wwma_Func(src, length)Zlema_Func(src, length) =>    zxLag = length / 2 == math.round(length / 2) ? length / 2 : (length - 1) / 2    zxEMAData = src + src - src[zxLag]    ZLEMA = ta.ema(zxEMAData, length)    ZLEMAZLEMA = Zlema_Func(src, length)Tsf_Func(src, length) =>    lrc = ta.linreg(src, length, 0)    lrc1 = ta.linreg(src, length, 1)    lrs = lrc - lrc1    TSF = ta.linreg(src, length, 0) + lrs    TSFTSF = Tsf_Func(src, length)getMA(src, length) =>    ma = 0.0    if mav == 'SMA'        ma := ta.sma(src, length)        ma    if mav == 'EMA'        ma := ta.ema(src, length)        ma    if mav == 'WMA'        ma := ta.wma(src, length)        ma    if mav == 'TMA'        ma := ta.sma(ta.sma(src, math.ceil(length / 2)), math.floor(length / 2) + 1)        ma    if mav == 'VAR'        ma := VAR        ma    if mav == 'WWMA'        ma := WWMA        ma    if mav == 'ZLEMA'        ma := ZLEMA        ma    if mav == 'TSF'        ma := TSF        ma    maMAvg = getMA(src, length)fark = MAvg * percent * 0.01longStop = MAvg - farklongStopPrev = nz(longStop[1], longStop)longStop := MAvg > longStopPrev ? math.max(longStop, longStopPrev) : longStopshortStop = MAvg + farkshortStopPrev = nz(shortStop[1], shortStop)shortStop := MAvg < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStopdir = 1dir := nz(dir[1], dir)dir := dir == -1 and MAvg > shortStopPrev ? 1 : dir == 1 and MAvg < longStopPrev ? -1 : dirMT = dir == 1 ? longStop : shortStopOTT = MAvg > MT ? MT * (200 + percent) / 200 : MT * (200 - percent) / 200OTTup = OTT * (1 + coeff)OTTdn = OTT * (1 - coeff)PPLOT = plot(showsupport ? MAvg : na, color=color.new(#0585E1, 0), linewidth=2, title='Support Line')pALLup = plot(nz(OTTup[2]), color=color.new(color.green, 0), linewidth=2, title='OTTup')pALLdn = plot(nz(OTTdn[2]), color=color.new(color.red, 0), linewidth=2, title='OTTdown')buySignalk = ta.crossover(MAvg, OTTup[2])sellSignalk = ta.crossunder(MAvg, OTTdn[2])K1 = ta.barssince(buySignalk)K2 = ta.barssince(sellSignalk)O1 = ta.barssince(buySignalk[1])O2 = ta.barssince(sellSignalk[1])plotshape(buySignalk and showsignalsk and O1 > K2 ? math.min(low, OTTdn) : na, title='Buy', text='Buy', location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 0), textcolor=color.new(color.white, 0))plotshape(sellSignalk and showsignalsk and O2 > K1 ? math.max(high, OTTup) : na, title='Sell', text='Sell', location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.new(color.white, 0))mPlot = plot(ohlc4, title='', style=plot.style_circles, linewidth=0, display=display.none)longFillColor = highlighting ? O2 > K1 ? color.green : na : nashortFillColor = highlighting ? O1 > K2 ? color.red : na : nafill(mPlot, PPLOT, title='UpTrend Highligter', color=longFillColor, transp=90)fill(mPlot, PPLOT, title='DownTrend Highligter', color=shortFillColor, transp=90)fill(pALLup, pALLdn, title='Flat Zone Highligter', color=color.new(color.blue, 90))dummy0 = input(true, title='=Backtest Inputs=')FromDay = input.int(defval=1, title='From Day', minval=1, maxval=31)FromMonth = input.int(defval=1, title='From Month', minval=1, maxval=12)FromYear = input.int(defval=2005, title='From Year', minval=2005)ToDay = input.int(defval=1, title='To Day', minval=1, maxval=31)ToMonth = input.int(defval=1, title='To Month', minval=1, maxval=12)ToYear = input.int(defval=9999, title='To Year', minval=2006)Start = timestamp(FromYear, FromMonth, FromDay, 00, 00)Finish = timestamp(ToYear, ToMonth, ToDay, 23, 59)Timerange() =>    time >= Start and time <= Finish ? true : falseif buySignalk    strategy.entry('Long', strategy.long, when=Timerange())if sellSignalk    strategy.entry('Short', strategy.short, when=Timerange())