Pine Script v4 · Strategy
Optimized Trend Tracker - Strategy Version
A Pine Script v4 strategy with no technical-analysis calculation. It has 4 order rules, 4 entries among them, and trades long and short with the default settings. Exits wait for a signal; there is no stop loss. Each trade commits 100% of equity and pays 0.1% commission. 15 settings; defaults include Source close, OTT Period 1 and OTT Percent 0.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 Optimized Trend Tracker - Strategy Version repaint?
- No
- No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 53 of 53 trades.
- How did Optimized Trend Tracker - Strategy Version do on BTCUSDT 1D with default settings?
- +98.64%
- From 26 Jan 2024 to 21 Oct 2026, over 150 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
- Can Optimized Trend Tracker - Strategy Version 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 Optimized Trend Tracker - Strategy Version use a stop loss?
- No
- Every exit waits for a signal; nothing limits a losing trade before it fires.
- Does Optimized Trend Tracker - Strategy Version run in Zeal Terminal?
- Yes
- It compiles in 24 ms and runs 1,000 bars in 66 ms, in the browser.
BTCUSDT · 1D · default settings
- Support Line
- OTT
- Winning trade
- Losing trade
- Equity
- Buy and hold
- Net profit
- +98.64%
- $9,864.04
- Buy and hold
- +102.5%
- same period
- Closed trades
- 150
- 46 won · 104 lost
- Profitable
- 30.7%
- of closed trades
- Profit factor
- 1.04
- gross profit ÷ gross loss
- Max drawdown
- 179.75%
- −$44,343.40
One run with the author's default settings, $10,000 starting capital, commission as the script sets it. A short position was still open at the last bar. A single backtest says little about future results and is not a recommendation. Backtests are simulations on historical data and are not investment advice.
Review
What a careful reader of this script would point out, found by checking the source and the backtest.
-
Check
No stop loss
Every exit waits for a signal. Nothing limits a losing trade before the exit condition fires.
-
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 an argument v6 removed
when = on line 60, 61, 63, 64. The upgraded version below moves each call inside an if block.
-
Note
Uses transp =, which v5 removed line 48
transp = on line 48, 53, 54. v5 folds the transparency into the colour with color.new(c, transp).
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 sum → math.sum, abs → math.abs, max → math.max, min → math.min, crossover → ta.crossover, crossunder → ta.crossunder.
- 4 strategy calls use the when = argument (line 60, 61, 63, 64). It is deprecated in v5 and removed in v6, where each call moves inside an if block.
v4 → v5
VerifiedSame 150 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 3: //@version=4 → //@version=5
- Line 7: input(type = input.float) → input.float()
- Line 9: input(type = input.bool) → input.bool()
- Line 10: input(type = input.bool) → input.bool()
- Line 11: input(type = input.bool) → input.bool()
- Line 12: input(type = input.bool) → input.bool()
17 more edits
- Line 13: input(type = input.bool) → input.bool()
- Line 28: sum → math.sum
- Line 29: sum → math.sum
- Line 31: abs → math.abs
- Line 37: max → math.max
- Line 40: min → math.min
- Line 48: transp = 0 → color.new(OTTC, 0)
- Line 49: crossover → ta.crossover
- Line 50: crossunder → ta.crossunder
- Line 51: crossover → ta.crossover
- Line 52: crossunder → ta.crossunder
- Line 53: transp = 0 → color.new(#0F18BF, 0)
- Line 54: transp = 0 → color.new(#0F18BF, 0)
- Line 60: strategy.entry(…, true) → strategy.entry(…, strategy.long)
- Line 61: strategy.entry(…, false) → strategy.entry(…, strategy.short)
- Line 63: strategy.entry(…, true) → strategy.entry(…, strategy.long)
- Line 64: strategy.entry(…, false) → strategy.entry(…, strategy.short)
⋯// © melihtuna-//@version=4+//@version=5strategy("Optimized Trend Tracker - Strategy Version", shorttitle="OTT-Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=10000, currency=currency.USD, commission_value=0.1, commission_type=strategy.commission.percent)⋯pds=input(1, "OTT Period", minval=1)-percent=input(0.1, "OTT Percent", type=input.float, step=0.1, minval=0)+percent=input.float(0.1, "OTT Percent", step=0.1, minval=0)condition = input(title="Condition", defval="Support Line Crossing Signals", options=["Price/OTT Crossing Signals", "Support Line Crossing Signals"])-showsupport = input(title="Show Support Line?", type=input.bool, defval=true)+showsupport = input.bool(title="Show Support Line?", defval=true)-highlight = input(title="Show OTT Color Changes?", type=input.bool, defval=true)+highlight = input.bool(title="Show OTT Color Changes?", defval=true)-highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)+highlighting = input.bool(title="Highlighter On/Off ?", defval=true)-barcoloing = input(title="Barcolor On/Off ?", type=input.bool, defval=true)+barcoloing = input.bool(title="Barcolor On/Off ?", defval=true)-showlabels = input(title="Show OTT BUY/SELl Labels?", type=input.bool, defval=false)+showlabels = input.bool(title="Show OTT BUY/SELl Labels?", defval=false)// === INPUT BACKTEST RANGE ===⋯dd1=src<src[1] ? src[1]-src : src-UD=sum(ud1,9)+UD=math.sum(ud1,9)-DD=sum(dd1,9)+DD=math.sum(dd1,9)CMO=(UD-DD)/(UD+DD)-k= abs(CMO)+k= math.abs(CMO)Var=0.0⋯longStopPrev = nz(longStop[1], longStop)-longStop := Var > longStopPrev ? max(longStop, longStopPrev) : longStop+longStop := Var > longStopPrev ? math.max(longStop, longStopPrev) : longStopshortStop = Var + farkshortStopPrev = nz(shortStop[1], shortStop)-shortStop := Var < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop+shortStop := Var < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStopdir = 1⋯OTTC = highlight ? OTT[2] > OTT[3] ? color.green : color.red : #B800D9 -pALL=plot(nz(OTT[2]), color=OTTC, linewidth=2, title="OTT", transp=0)+pALL=plot(nz(OTT[2]), color=color.new(OTTC, 0), linewidth=2, title="OTT")-buySignalk = window() and crossover(Var, OTT[2])+buySignalk = window() and ta.crossover(Var, OTT[2])-sellSignallk = window() and crossunder(Var, OTT[2])+sellSignallk = window() and ta.crossunder(Var, OTT[2])-buySignalc = window() and crossover(src, OTT[2])+buySignalc = window() and ta.crossover(src, OTT[2])-sellSignallc = window() and crossunder(src, OTT[2])+sellSignallc = window() and ta.crossunder(src, OTT[2])-plotshape(condition == "Support Line Crossing Signals" ? showlabels and buySignalk ? OTT*0.995 : na : showlabels and buySignalc ? OTT*0.995 : na, title="BUY", text="BUY", location=location.belowbar, style=shape.labelup, size=size.tiny, color=#0F18BF, textcolor=color.white, transp=0)+plotshape(condition == "Support Line Crossing Signals" ? showlabels and buySignalk ? OTT*0.995 : na : showlabels and buySignalc ? OTT*0.995 : na, title="BUY", text="BUY", location=location.belowbar, style=shape.labelup, size=size.tiny, color=color.new(#0F18BF, 0), textcolor=color.white)-plotshape(condition == "Support Line Crossing Signals" ? showlabels and sellSignallk ? OTT*1.005 : na : showlabels and sellSignallc ? OTT*1.005 : na, title="SELL", text="SELL", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=#0F18BF, textcolor=color.white, transp=0)+plotshape(condition == "Support Line Crossing Signals" ? showlabels and sellSignallk ? OTT*1.005 : na : showlabels and sellSignallc ? OTT*1.005 : na, title="SELL", text="SELL", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=color.new(#0F18BF, 0), textcolor=color.white) ⋯if condition == "Support Line Crossing Signals"- strategy.entry("BUY", true, 1, when = buySignalk)+ strategy.entry("BUY", strategy.long, 1, when = buySignalk)- strategy.entry("SELL", false, 1, when = sellSignallk)+ strategy.entry("SELL", strategy.short, 1, when = sellSignallk)else- strategy.entry("BUY", true, 1, when = buySignalc)+ strategy.entry("BUY", strategy.long, 1, when = buySignalc)- strategy.entry("SELL", false, 1, when = sellSignallc)+ strategy.entry("SELL", strategy.short, 1, when = sellSignallc)mPlot = plot(close, title="", style=plot.style_circles, linewidth=0,display=display.none)⋯Same 150 trades and the same P&L on BTCUSDT 1D, 1,000 bars, in Zeal Terminal's engine.
- Line 5: input() → input.source()
- Line 6: input() → input.int()
- Line 8: input() → input.string()
- Line 15: input() → input.int()
- Line 16: input() → input.int()
- Line 17: input() → input.int()
7 more edits
- Line 18: input() → input.int()
- Line 19: input() → input.int()
- Line 20: input() → input.int()
- Line 60: when = buySignalk → if block
- Line 61: when = sellSignallk → if block
- Line 63: when = buySignalc → if block
- Line 64: when = sellSignallc → if block
⋯strategy("Optimized Trend Tracker - Strategy Version", shorttitle="OTT-Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=10000, currency=currency.USD, commission_value=0.1, commission_type=strategy.commission.percent)-src = input(close, title="Source")+src = input.source(close, title="Source")-pds=input(1, "OTT Period", minval=1)+pds=input.int(1, "OTT Period", minval=1)percent=input.float(0.1, "OTT Percent", step=0.1, minval=0)-condition = input(title="Condition", defval="Support Line Crossing Signals", options=["Price/OTT Crossing Signals", "Support Line Crossing Signals"])+condition = input.string(title="Condition", defval="Support Line Crossing Signals", options=["Price/OTT Crossing Signals", "Support Line Crossing Signals"])showsupport = input.bool(title="Show Support Line?", defval=true)⋯// === INPUT BACKTEST RANGE ===-FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)+FromMonth = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)-FromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)+FromDay = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)-FromYear = input(defval = 2020, title = "From Year", minval = 2017)+FromYear = input.int(defval = 2020, title = "From Year", minval = 2017)-ToMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)+ToMonth = input.int(defval = 1, title = "To Month", minval = 1, maxval = 12)-ToDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)+ToDay = input.int(defval = 1, title = "To Day", minval = 1, maxval = 31)-ToYear = input(defval = 9999, title = "To Year", minval = 2017)+ToYear = input.int(defval = 9999, title = "To Year", minval = 2017)// === FUNCTION EXAMPLE ===⋯if condition == "Support Line Crossing Signals"- strategy.entry("BUY", strategy.long, 1, when = buySignalk)+ if buySignalk+ strategy.entry("BUY", strategy.long, 1)- strategy.entry("SELL", strategy.short, 1, when = sellSignallk)+ if sellSignallk+ strategy.entry("SELL", strategy.short, 1)else- strategy.entry("BUY", strategy.long, 1, when = buySignalc)+ if buySignalc+ strategy.entry("BUY", strategy.long, 1)- strategy.entry("SELL", strategy.short, 1, when = sellSignallc)+ if sellSignallc+ strategy.entry("SELL", strategy.short, 1)mPlot = plot(close, title="", style=plot.style_circles, linewidth=0,display=display.none)⋯Does it run in Pine Script v6?
No
The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L69: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.
⋯// © melihtuna-//@version=5+//@version=6strategy("Optimized Trend Tracker - Strategy Version", shorttitle="OTT-Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=10000, currency=currency.USD, commission_value=0.1, commission_type=strategy.commission.percent)⋯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 | ud1 dd1 Var buySignalc sellSignallc |
| OTT Period | 1 | int · min 1 | alpha |
| OTT Percent | 0.1 | float · min 0 · step 0.1 | fark OTT |
| Condition | Support Line Crossing Signals | string · options ["Price/OTT Crossing Signals", "Support Line Crossing Signals"] | entry BUY entry SELL entry BUY entry SELL BUY SELL line 59 |
| Show Support Line? | true | bool | Support Line |
| Show OTT Color Changes? | true | bool | OTTC |
| Highlighter On/Off ? | true | bool | longFillColor shortFillColor |
| Barcolor On/Off ? | true | bool | barcolor |
| Show OTT BUY/SELl Labels? | false | bool | BUY SELL |
| From Month | 1 | int · min 1 · max 12 | start |
| From Day | 1 | int · min 1 · max 31 | start |
| From Year | 2020 | int · min 2017 | start |
| To Month | 1 | int · min 1 · max 12 | finish |
| To Day | 1 | int · min 1 · max 31 | finish |
| To Year | 9999 | int · min 2017 | finish |
What it calculates
No technical-analysis calculation: the script works on prices and settings directly.
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 | buySignalkwindow() and crossover(Var, OTT[2]) | On | 60 |
| Open SELL short | sellSignallkwindow() and crossunder(Var, OTT[2]) | On | 61 |
| Open BUY long | buySignalcwindow() and crossover(src, OTT[2]) | On | 63 |
| Open SELL short | sellSignallcwindow() and crossunder(src, OTT[2]) | On | 64 |
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 | +98.6% | +102.5% | 150 | 31% | 1.04 | 179.7% | 26 Jan 2024 – 21 Oct 2026 |
| BTCUSDT 4h | −181.1% | +5.5% | 133 | 29% | 0.77 | 164.4% | 8 May 2026 – 21 Oct 2026 |
| ETHUSDT 1D | +18.1% | +9.8% | 134 | 31% | 1.16 | 16.8% | 26 Jan 2024 – 21 Oct 2026 |
| ETHUSDT 4h | −6.9% | +8.4% | 139 | 24% | 0.77 | 9.3% | 8 May 2026 – 21 Oct 2026 |
| SOLUSDT 1D | −0.1% | +16.7% | 160 | 32% | 0.99 | 1.2% | 26 Jan 2024 – 21 Oct 2026 |
| SOLUSDT 4h | +0.2% | +21.5% | 135 | 35% | 1.17 | 0.3% | 8 May 2026 – 21 Oct 2026 |
| BNBUSDT 1D | −2.0% | +148.3% | 154 | 36% | 0.92 | 4.9% | 26 Jan 2024 – 21 Oct 2026 |
| BNBUSDT 4h | +2.0% | +17.1% | 113 | 36% | 1.40 | 1.1% | 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 | 43 | 35% | $463.64 |
| Sideways market | 69 | 29% | $12,991.70 |
| Falling market | 38 | 29% | −$3,507.97 |
Rising and falling mean the market moved more than 15% over the 90 bars before entry.
How bad could the drawdown be?
16,604.4%
The 95th percentile of the worst drawdown when the same 150 trades are reshuffled 5,000 times. The bar spans the 5th to 95th percentile, 103.8% to 16,604.4%; the tick is what actually happened, 175.0%. Order luck alone moves it this much.
All 150 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| short | 23 Feb 2024 51,288.40 | 27 Feb 2024 54,476.50 | 4 | −$3,293.82 |
| long | 27 Feb 2024 54,476.50 | 16 Mar 2024 69,499.80 | 18 | $14,899.40 |
| short | 16 Mar 2024 69,499.80 | 26 Mar 2024 69,880.00 | 10 | −$519.54 |
| long | 26 Mar 2024 69,880.00 | 3 Apr 2024 65,464.00 | 8 | −$4,551.35 |
| short | 3 Apr 2024 65,464.00 | 8 Apr 2024 69,360.40 | 5 | −$4,031.21 |
| long | 8 Apr 2024 69,360.40 | 13 Apr 2024 67,116.50 | 5 | −$2,380.34 |
| short | 13 Apr 2024 67,116.50 | 23 Apr 2024 66,819.30 | 10 | $163.26 |
| long | 23 Apr 2024 66,819.30 | 25 Apr 2024 64,289.60 | 2 | −$2,660.85 |
| short | 25 Apr 2024 64,289.60 | 5 May 2024 63,892.00 | 10 | $269.37 |
| long | 5 May 2024 63,892.00 | 12 May 2024 60,826.00 | 7 | −$3,190.76 |
| short | 12 May 2024 60,826.00 | 14 May 2024 62,940.10 | 2 | −$2,237.87 |
| long | 14 May 2024 62,940.10 | 30 May 2024 67,652.40 | 16 | $4,581.73 |
| short | 30 May 2024 67,652.40 | 4 Jun 2024 68,809.90 | 5 | −$1,293.94 |
| long | 4 Jun 2024 68,809.90 | 12 Jun 2024 67,314.20 | 8 | −$1,631.78 |
| short | 12 Jun 2024 67,314.20 | 1 Jul 2024 62,772.00 | 19 | $4,412.13 |
| long | 1 Jul 2024 62,772.00 | 4 Jul 2024 60,208.60 | 3 | −$2,686.42 |
| short | 4 Jul 2024 60,208.60 | 15 Jul 2024 60,797.90 | 11 | −$710.35 |
| long | 15 Jul 2024 60,797.90 | 25 Jul 2024 65,376.00 | 10 | $4,451.93 |
| short | 25 Jul 2024 65,376.00 | 28 Jul 2024 67,896.50 | 3 | −$2,653.75 |
| long | 28 Jul 2024 67,896.50 | 31 Jul 2024 66,188.00 | 3 | −$1,842.57 |
| short | 31 Jul 2024 66,188.00 | 9 Aug 2024 61,686.00 | 9 | $4,374.13 |
| long | 9 Aug 2024 61,686.00 | 13 Aug 2024 59,346.60 | 4 | −$2,460.39 |
| short | 13 Aug 2024 59,346.60 | 14 Aug 2024 60,587.20 | 1 | −$1,360.45 |
| long | 14 Aug 2024 60,587.20 | 16 Aug 2024 57,541.10 | 2 | −$3,164.24 |
| short | 16 Aug 2024 57,541.10 | 21 Aug 2024 59,013.80 | 5 | −$1,589.30 |
| long | 21 Aug 2024 59,013.80 | 28 Aug 2024 59,415.00 | 7 | $282.77 |
| short | 28 Aug 2024 59,415.00 | 10 Sep 2024 57,042.00 | 13 | $2,256.53 |
| long | 10 Sep 2024 57,042.00 | 1 Oct 2024 63,327.60 | 21 | $6,165.22 |
| short | 1 Oct 2024 63,327.60 | 13 Oct 2024 63,206.20 | 12 | −$5.16 |
| long | 13 Oct 2024 63,206.20 | 27 Oct 2024 67,092.80 | 14 | $3,756.23 |
| short | 27 Oct 2024 67,092.80 | 28 Oct 2024 68,021.70 | 1 | −$1,064.04 |
| long | 28 Oct 2024 68,021.70 | 2 Nov 2024 69,496.00 | 5 | $1,336.79 |
| short | 2 Nov 2024 69,496.00 | 7 Nov 2024 75,572.00 | 5 | −$6,221.06 |
| long | 7 Nov 2024 75,572.00 | 26 Nov 2024 93,010.00 | 19 | $17,269.40 |
| short | 26 Nov 2024 93,010.00 | 29 Nov 2024 95,644.00 | 3 | −$2,822.63 |
| long | 29 Nov 2024 95,644.00 | 11 Dec 2024 96,593.00 | 12 | $756.77 |
| short | 11 Dec 2024 96,593.00 | 12 Dec 2024 101,125.00 | 1 | −$4,729.72 |
| long | 12 Dec 2024 101,125.00 | 20 Dec 2024 97,461.90 | 8 | −$3,861.73 |
| short | 20 Dec 2024 97,461.90 | 3 Jan 2025 96,984.80 | 14 | $282.62 |
| long | 3 Jan 2025 96,984.80 | 9 Jan 2025 95,060.60 | 6 | −$2,116.23 |
| short | 9 Jan 2025 95,060.60 | 15 Jan 2025 96,560.90 | 6 | −$1,691.86 |
| long | 15 Jan 2025 96,560.90 | 28 Jan 2025 102,083.00 | 13 | $5,323.34 |
| short | 28 Jan 2025 102,083.00 | 31 Jan 2025 104,723.00 | 3 | −$2,846.92 |
| long | 31 Jan 2025 104,723.00 | 2 Feb 2025 100,636.00 | 2 | −$4,292.64 |
| short | 2 Feb 2025 100,636.00 | 11 Feb 2025 97,430.80 | 9 | $3,006.77 |
| long | 11 Feb 2025 97,430.80 | 12 Feb 2025 95,778.20 | 1 | −$1,845.82 |
| short | 12 Feb 2025 95,778.20 | 13 Feb 2025 97,870.00 | 1 | −$2,285.44 |
| long | 13 Feb 2025 97,870.00 | 17 Feb 2025 96,118.10 | 4 | −$1,945.87 |
| short | 17 Feb 2025 96,118.10 | 21 Feb 2025 98,305.00 | 4 | −$2,381.31 |
| long | 21 Feb 2025 98,305.00 | 23 Feb 2025 96,551.00 | 2 | −$1,948.86 |
| short | 23 Feb 2025 96,551.00 | 6 Mar 2025 90,606.00 | 11 | $5,757.85 |
| long | 6 Mar 2025 90,606.00 | 9 Mar 2025 86,222.50 | 3 | −$4,560.37 |
| short | 9 Mar 2025 86,222.50 | 16 Mar 2025 84,338.40 | 7 | $1,713.46 |
| long | 16 Mar 2025 84,338.40 | 19 Mar 2025 82,715.00 | 3 | −$1,790.46 |
| short | 19 Mar 2025 82,715.00 | 20 Mar 2025 86,845.90 | 1 | −$4,300.46 |
| long | 20 Mar 2025 86,845.90 | 22 Mar 2025 84,088.80 | 2 | −$2,928.07 |
| short | 22 Mar 2025 84,088.80 | 24 Mar 2025 86,082.50 | 2 | −$2,163.88 |
| long | 24 Mar 2025 86,082.50 | 29 Mar 2025 84,424.40 | 5 | −$1,828.63 |
| short | 29 Mar 2025 84,424.40 | 6 Apr 2025 83,538.00 | 8 | $718.43 |
| long | 6 Apr 2025 83,538.00 | 7 Apr 2025 78,430.00 | 1 | −$5,269.96 |
| short | 7 Apr 2025 78,430.00 | 12 Apr 2025 83,423.80 | 5 | −$5,155.68 |
| long | 12 Apr 2025 83,423.80 | 28 Apr 2025 93,749.30 | 16 | $10,148.30 |
| short | 28 Apr 2025 93,749.30 | 29 Apr 2025 95,011.20 | 1 | −$1,450.65 |
| long | 29 Apr 2025 95,011.20 | 1 May 2025 94,172.00 | 2 | −$1,028.36 |
| short | 1 May 2025 94,172.00 | 2 May 2025 96,489.90 | 1 | −$2,508.56 |
| long | 2 May 2025 96,489.90 | 5 May 2025 94,277.60 | 3 | −$2,403.06 |
| short | 5 May 2025 94,277.60 | 7 May 2025 96,834.00 | 2 | −$2,747.52 |
| long | 7 May 2025 96,834.00 | 29 May 2025 107,782.00 | 22 | $10,743.10 |
| short | 29 May 2025 107,782.00 | 8 Jun 2025 105,552.00 | 10 | $2,016.30 |
| long | 8 Jun 2025 105,552.00 | 13 Jun 2025 105,672.00 | 5 | −$91.63 |
| short | 13 Jun 2025 105,672.00 | 25 Jun 2025 106,083.00 | 12 | −$623.01 |
| long | 25 Jun 2025 106,083.00 | 17 Jul 2025 118,630.00 | 22 | $12,322.70 |
| short | 17 Jul 2025 118,630.00 | 18 Jul 2025 119,178.00 | 1 | −$784.93 |
| long | 18 Jul 2025 119,178.00 | 20 Jul 2025 117,840.00 | 2 | −$1,574.57 |
| short | 20 Jul 2025 117,840.00 | 23 Jul 2025 119,954.00 | 3 | −$2,352.21 |
| long | 23 Jul 2025 119,954.00 | 26 Jul 2025 117,614.00 | 3 | −$2,577.69 |
| short | 26 Jul 2025 117,614.00 | 29 Jul 2025 118,062.00 | 3 | −$683.69 |
| long | 29 Jul 2025 118,062.00 | 31 Jul 2025 117,840.00 | 2 | −$457.93 |
| short | 31 Jul 2025 117,840.00 | 5 Aug 2025 115,055.00 | 5 | $2,552.36 |
| long | 5 Aug 2025 115,055.00 | 19 Aug 2025 116,227.00 | 14 | $940.74 |
| short | 19 Aug 2025 116,227.00 | 4 Sep 2025 111,706.00 | 16 | $4,293.40 |
| long | 4 Sep 2025 111,706.00 | 7 Sep 2025 110,188.00 | 3 | −$1,739.63 |
| short | 7 Sep 2025 110,188.00 | 8 Sep 2025 111,137.00 | 1 | −$1,170.70 |
| long | 8 Sep 2025 111,137.00 | 23 Sep 2025 112,651.00 | 15 | $1,289.85 |
| short | 23 Sep 2025 112,651.00 | 30 Sep 2025 114,312.00 | 7 | −$1,887.94 |
| long | 30 Sep 2025 114,312.00 | 9 Oct 2025 123,306.00 | 9 | $8,756.42 |
| short | 9 Oct 2025 123,306.00 | 21 Oct 2025 110,532.00 | 12 | $12,540.10 |
| long | 21 Oct 2025 110,532.00 | 23 Oct 2025 107,567.00 | 2 | −$3,182.74 |
| short | 23 Oct 2025 107,567.00 | 25 Oct 2025 111,005.00 | 2 | −$3,656.02 |
| long | 25 Oct 2025 111,005.00 | 30 Oct 2025 110,021.00 | 5 | −$1,204.63 |
| short | 30 Oct 2025 110,021.00 | 25 Nov 2025 88,300.00 | 26 | $21,523.00 |
| long | 25 Nov 2025 88,300.00 | 7 Dec 2025 89,236.80 | 12 | $759.25 |
| short | 7 Dec 2025 89,236.80 | 8 Dec 2025 90,395.30 | 1 | −$1,338.15 |
| long | 8 Dec 2025 90,395.30 | 14 Dec 2025 90,240.00 | 6 | −$335.95 |
| short | 14 Dec 2025 90,240.00 | 21 Dec 2025 88,360.90 | 7 | $1,700.49 |
| long | 21 Dec 2025 88,360.90 | 25 Dec 2025 87,669.40 | 4 | −$867.50 |
| short | 25 Dec 2025 87,669.40 | 29 Dec 2025 87,952.70 | 4 | −$458.89 |
| long | 29 Dec 2025 87,952.70 | 8 Jan 2026 91,364.20 | 10 | $3,232.13 |
| short | 8 Jan 2026 91,364.20 | 14 Jan 2026 95,414.00 | 6 | −$4,236.61 |
| long | 14 Jan 2026 95,414.00 | 20 Jan 2026 92,631.00 | 6 | −$2,971.04 |
| short | 20 Jan 2026 92,631.00 | 29 Jan 2026 89,300.00 | 9 | $3,149.06 |
| long | 29 Jan 2026 89,300.00 | 30 Jan 2026 84,650.20 | 1 | −$4,823.79 |
| short | 30 Jan 2026 84,650.20 | 15 Feb 2026 69,822.90 | 16 | $14,672.70 |
| long | 15 Feb 2026 69,822.90 | 18 Feb 2026 67,503.50 | 3 | −$2,456.75 |
| short | 18 Feb 2026 67,503.50 | 22 Feb 2026 67,975.90 | 4 | −$607.89 |
| long | 22 Feb 2026 67,975.90 | 24 Feb 2026 64,656.00 | 2 | −$3,452.55 |
| short | 24 Feb 2026 64,656.00 | 27 Feb 2026 67,485.20 | 3 | −$2,961.32 |
| long | 27 Feb 2026 67,485.20 | 1 Mar 2026 66,973.30 | 2 | −$646.39 |
| short | 1 Mar 2026 66,973.30 | 3 Mar 2026 68,830.10 | 2 | −$1,992.60 |
| long | 3 Mar 2026 68,830.10 | 8 Mar 2026 67,262.90 | 5 | −$1,703.24 |
| short | 8 Mar 2026 67,262.90 | 11 Mar 2026 69,948.60 | 3 | −$2,822.94 |
| long | 11 Mar 2026 69,948.60 | 19 Mar 2026 71,246.60 | 8 | $1,156.71 |
| short | 19 Mar 2026 71,246.60 | 26 Mar 2026 71,336.50 | 7 | −$232.56 |
| long | 26 Mar 2026 71,336.50 | 27 Mar 2026 68,820.30 | 1 | −$2,656.38 |
| short | 27 Mar 2026 68,820.30 | 1 Apr 2026 68,284.50 | 5 | $398.71 |
| long | 1 Apr 2026 68,284.50 | 4 Apr 2026 66,964.30 | 3 | −$1,455.45 |
| short | 4 Apr 2026 66,964.30 | 6 Apr 2026 69,034.20 | 2 | −$2,205.89 |
| long | 6 Apr 2026 69,034.20 | 20 Apr 2026 73,801.80 | 14 | $4,624.78 |
| short | 20 Apr 2026 73,801.80 | 22 Apr 2026 76,336.10 | 2 | −$2,684.48 |
| long | 22 Apr 2026 76,336.10 | 29 Apr 2026 76,342.80 | 7 | −$146.04 |
| short | 29 Apr 2026 76,342.80 | 2 May 2026 78,231.10 | 3 | −$2,042.92 |
| long | 2 May 2026 78,231.10 | 13 May 2026 80,504.50 | 11 | $2,114.60 |
| short | 13 May 2026 80,504.50 | 22 May 2026 77,615.50 | 9 | $2,730.83 |
| long | 22 May 2026 77,615.50 | 23 May 2026 75,539.50 | 1 | −$2,229.18 |
| short | 23 May 2026 75,539.50 | 26 May 2026 77,322.00 | 3 | −$1,935.37 |
| long | 26 May 2026 77,322.00 | 27 May 2026 75,930.00 | 1 | −$1,545.25 |
| short | 27 May 2026 75,930.00 | 8 Jun 2026 63,332.00 | 12 | $12,458.70 |
| long | 8 Jun 2026 63,332.00 | 10 Jun 2026 61,730.00 | 2 | −$1,727.07 |
| short | 10 Jun 2026 61,730.00 | 12 Jun 2026 63,626.00 | 2 | −$2,021.36 |
| long | 12 Jun 2026 63,626.00 | 19 Jun 2026 62,958.00 | 7 | −$794.57 |
| short | 19 Jun 2026 62,958.00 | 3 Jul 2026 61,560.00 | 14 | $1,273.49 |
| long | 3 Jul 2026 61,560.00 | 9 Jul 2026 62,290.00 | 6 | $606.16 |
| short | 9 Jul 2026 62,290.00 | 11 Jul 2026 64,161.70 | 2 | −$1,998.16 |
| long | 11 Jul 2026 64,161.70 | 14 Jul 2026 62,334.50 | 3 | −$1,953.70 |
| short | 14 Jul 2026 62,334.50 | 15 Jul 2026 65,044.00 | 1 | −$2,836.85 |
| long | 15 Jul 2026 65,044.00 | 18 Jul 2026 63,931.70 | 3 | −$1,241.30 |
| short | 18 Jul 2026 63,931.70 | 19 Jul 2026 64,834.20 | 1 | −$1,031.31 |
| long | 19 Jul 2026 64,834.20 | 25 Jul 2026 64,140.00 | 6 | −$823.18 |
| short | 25 Jul 2026 64,140.00 | 27 Jul 2026 65,400.00 | 2 | −$1,389.54 |
| long | 27 Jul 2026 65,400.00 | 28 Jul 2026 63,755.90 | 1 | −$1,773.30 |
| short | 28 Jul 2026 63,755.90 | 6 Aug 2026 64,665.20 | 9 | −$1,037.80 |
| long | 6 Aug 2026 64,665.20 | 12 Aug 2026 63,600.00 | 6 | −$1,193.50 |
| short | 12 Aug 2026 63,600.00 | 18 Aug 2026 64,532.10 | 6 | −$1,060.23 |
| long | 18 Aug 2026 64,532.10 | 30 Aug 2026 78,230.00 | 12 | $13,555.10 |
| short | 30 Aug 2026 78,230.00 | 4 Sep 2026 81,270.40 | 5 | −$3,199.87 |
| long | 4 Sep 2026 81,270.40 | 9 Sep 2026 78,455.80 | 5 | −$2,974.30 |
| short | 9 Sep 2026 78,455.80 | 19 Sep 2026 80,883.90 | 10 | −$2,587.40 |
| long | 19 Sep 2026 80,883.90 | 30 Sep 2026 83,663.70 | 11 | $2,615.25 |
| short | 30 Sep 2026 83,663.70 | 2 Oct 2026 84,880.10 | 2 | −$1,384.93 |
| long | 2 Oct 2026 84,880.10 | 8 Oct 2026 83,321.80 | 6 | −$1,726.44 |
Similar scripts
No other indicator or strategy here shares enough of its calculations.
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 24 ms | With a workaround 1,000 bars in 66 ms | Not measured |
| PineTS | No v5 and v6 only | — | Not measured |
Zeal Terminal's engine currently reads an order side written as true, false as a short, whatever it says; this page passes the same side as strategy.long or strategy.short (lines 60, 61, 63, 64) 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/// © melihtuna//@version=4strategy("Optimized Trend Tracker - Strategy Version", shorttitle="OTT-Strategy", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, initial_capital=10000, currency=currency.USD, commission_value=0.1, commission_type=strategy.commission.percent)src = input(close, title="Source")pds=input(1, "OTT Period", minval=1)percent=input(0.1, "OTT Percent", type=input.float, step=0.1, minval=0)condition = input(title="Condition", defval="Support Line Crossing Signals", options=["Price/OTT Crossing Signals", "Support Line Crossing Signals"])showsupport = input(title="Show Support Line?", type=input.bool, defval=true)highlight = input(title="Show OTT Color Changes?", type=input.bool, defval=true)highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)barcoloing = input(title="Barcolor On/Off ?", type=input.bool, defval=true)showlabels = input(title="Show OTT BUY/SELl Labels?", type=input.bool, defval=false)// === INPUT BACKTEST RANGE ===FromMonth = input(defval = 1, title = "From Month", minval = 1, maxval = 12)FromDay = input(defval = 1, title = "From Day", minval = 1, maxval = 31)FromYear = input(defval = 2020, title = "From Year", minval = 2017)ToMonth = input(defval = 1, title = "To Month", minval = 1, maxval = 12)ToDay = input(defval = 1, title = "To Day", minval = 1, maxval = 31)ToYear = input(defval = 9999, title = "To Year", minval = 2017)// === FUNCTION EXAMPLE ===start = timestamp(FromYear, FromMonth, FromDay, 00, 00) // backtest start windowfinish = timestamp(ToYear, ToMonth, ToDay, 23, 59) // backtest finish windowwindow() => time >= start and time <= finish ? true : false // create function "within window of time"alpha=2/(pds+1)ud1=src>src[1] ? src-src[1] : srcdd1=src<src[1] ? src[1]-src : srcUD=sum(ud1,9)DD=sum(dd1,9)CMO=(UD-DD)/(UD+DD)k= abs(CMO)Var=0.0Var:=(alpha*k*src)+(1-alpha*k)*nz(Var[1])fark=Var*percent*0.01longStop = Var - farklongStopPrev = nz(longStop[1], longStop)longStop := Var > longStopPrev ? max(longStop, longStopPrev) : longStopshortStop = Var + farkshortStopPrev = nz(shortStop[1], shortStop)shortStop := Var < shortStopPrev ? min(shortStop, shortStopPrev) : shortStopdir = 1dir := nz(dir[1], dir)dir := dir == -1 and Var > shortStopPrev ? 1 : dir == 1 and Var < longStopPrev ? -1 : dirMT = dir==1 ? longStop: shortStopOTT=Var>MT ? MT*(200+percent)/200 : MT*(200-percent)/200 plot(showsupport ? Var : na, color=#0585E1, linewidth=2, title="Support Line")OTTC = highlight ? OTT[2] > OTT[3] ? color.green : color.red : #B800D9 pALL=plot(nz(OTT[2]), color=OTTC, linewidth=2, title="OTT", transp=0)buySignalk = window() and crossover(Var, OTT[2])sellSignallk = window() and crossunder(Var, OTT[2])buySignalc = window() and crossover(src, OTT[2])sellSignallc = window() and crossunder(src, OTT[2])plotshape(condition == "Support Line Crossing Signals" ? showlabels and buySignalk ? OTT*0.995 : na : showlabels and buySignalc ? OTT*0.995 : na, title="BUY", text="BUY", location=location.belowbar, style=shape.labelup, size=size.tiny, color=#0F18BF, textcolor=color.white, transp=0)plotshape(condition == "Support Line Crossing Signals" ? showlabels and sellSignallk ? OTT*1.005 : na : showlabels and sellSignallc ? OTT*1.005 : na, title="SELL", text="SELL", location=location.abovebar, style=shape.labeldown, size=size.tiny, color=#0F18BF, textcolor=color.white, transp=0) ottBuyColor=#77DD77ottSellColor=#FF0000vColor = strategy.position_size > 0 ? ottBuyColor : ottSellColorif condition == "Support Line Crossing Signals" strategy.entry("BUY", true, 1, when = buySignalk) strategy.entry("SELL", false, 1, when = sellSignallk)else strategy.entry("BUY", true, 1, when = buySignalc) strategy.entry("SELL", false, 1, when = sellSignallc)mPlot = plot(close, title="", style=plot.style_circles, linewidth=0,display=display.none)longFillColor = highlighting ? (Var>OTT ? color.green : na) : nashortFillColor = highlighting ? (Var<OTT ? color.red : na) : nafill(mPlot, pALL, title="UpTrend Highligter", color=longFillColor)fill(mPlot, pALL, title="DownTrend Highligter", color=shortFillColor)barcolor(barcoloing ? vColor : na)