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
- 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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Source | close | source | vud1 vdd1 VAR WWMA zxEMAData ZLEMA lrc lrc1 TSF ma MAvg |
| OTT Period | 40 | int · min 1 | valpha VAR wwalpha WWMA zxLag ZLEMA lrc lrc1 TSF ma MAvg |
| Optimization Constant | 1 | float · min 0 · step 0.1 | fark OTT |
| Twin OTT Coefficient | 0.001 | float · min 0 · step 0.001 | OTTup OTTdn |
| Show Support Line? | true | bool | Support Line |
| Show Signals? | true | bool | Buy Sell |
| Moving Average Type | VAR | string · 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 ? | true | bool | longFillColor shortFillColor |
| =Backtest Inputs= | true | bool | unused |
| From Day | 1 | int · min 1 · max 31 | Start |
| From Month | 1 | int · min 1 · max 12 | Start |
| From Year | 2005 | int · min 2005 | Start |
| To Day | 1 | int · min 1 · max 31 | Finish |
| To Month | 1 | int · min 1 · max 12 | Finish |
| To Year | 9999 | int · min 2006 | Finish |
What it calculates
- LinregSource (close), OTT Period (40), 0
lrc · line 40 - LinregSource (close), OTT Period (40), 1
lrc1 · line 41 - SMA / EMA / WMASource (close), OTT Period (40)
ma · line 49 - CrossoverMAvg, OTTup[2]
buySignalk · line 91 - CrossunderMAvg, OTTdn[2]
sellSignalk · line 92 - BarssincebuySignalk
K1 · line 93 - BarssincesellSignalk
K2 · 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.
Order rules
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | Timerange() | On | 117 |
| Open Short short | Timerange() | On | 119 |
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 | +4.5% | +102.5% | 8 | 50% | 2.60 | 1.4% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −1.2% | +5.5% | 7 | 29% | 0.55 | 2.5% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +0.1% | +9.8% | 8 | 50% | 1.37 | 0.3% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −0.0% | +8.4% | 5 | 20% | 0.99 | 0.1% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | +0.0% | +16.7% | 12 | 42% | 1.00 | 0.0% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | −0.0% | +21.5% | 7 | 14% | 0.72 | 0.0% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −0.0% | +148.3% | 12 | 33% | 0.92 | 0.1% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +0.0% | +17.1% | 3 | 67% | 2.90 | 0.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 | 1 | 0% | −$6,206.16 |
| Sideways market | 7 | 57% | $51,349.30 |
| 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?
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.
All 8 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 4 Feb 2024 43,011.10 | 6 Aug 2024 54,018.80 | 184 | $11,007.70 |
| short | 6 Aug 2024 54,018.80 | 23 Sep 2024 63,578.80 | 48 | −$9,559.94 |
| long | 23 Sep 2024 63,578.80 | 1 Mar 2025 84,349.90 | 159 | $20,771.20 |
| short | 1 Mar 2025 84,349.90 | 25 Apr 2025 93,980.50 | 55 | −$9,630.52 |
| long | 25 Apr 2025 93,980.50 | 20 Oct 2025 108,643.00 | 178 | $14,662.30 |
| short | 20 Oct 2025 108,643.00 | 12 May 2026 81,745.70 | 204 | $26,897.10 |
| long | 12 May 2026 81,745.70 | 23 May 2026 75,539.50 | 11 | −$6,206.16 |
| short | 23 May 2026 75,539.50 | 22 Aug 2026 78,338.00 | 91 | −$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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Twin Optimized Trend Tracker Strategy TOTT this page | — | v5 strategy | +4.5% | 8 | 1.4% |
| MACD ReLoaded STRATEGY by KivancOzbilgic | ema linreg wma sma barssince | v5 strategy | +7.8% | 31 | 5.1% |
| Linear Regression MA - Strategy by lazy_capitalist | sma linreg ema | v5 strategy | −1,240.4% | 10 | 318.7% |
| Forex SWING Trader by SoftKill21 | wma ema sma | v4 strategy | No trades on this market | ||
| Dazzling Bolts by OrcChieftain | sma ema barssince | v4 strategy | +8.5% | 14 | 13.0% |
| High-Low Channel Multi averages Crypto Swing strategy by exlux99 | sma ema wma linreg | v4 strategy | No 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.
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
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 37 ms | Yes 1,000 bars in 87 ms | Not measured |
| PineTS | Not tested | Not tested | Not measured |
“Matches TradingView” needs this script's own output exported from TradingView and compared bar by bar, which has not been done for this script. The engine is built on OpenPineScript, whose conformance results are in its conformance report.
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())