Zeal Terminal Open in Zeal Terminal

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
Prerendered with the defaults. Change anything and run it here. The script runs in your browser.
Settings (15)
0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$18,488$20,253Equity from $10,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. 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.
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

Verified

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

Clean v5

VerifiedDownload the v5 script

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.

SettingDefaultType and rangeFeeds
Sourceclosesourceud1 dd1 Var buySignalc sellSignallc
OTT Period1int · min 1alpha
OTT Percent0.1float · min 0 · step 0.1fark OTT
ConditionSupport Line Crossing Signalsstring · options ["Price/OTT Crossing Signals", "Support Line Crossing Signals"]entry BUY entry SELL entry BUY entry SELL BUY SELL line 59
Show Support Line?trueboolSupport Line
Show OTT Color Changes?trueboolOTTC
Highlighter On/Off ?trueboollongFillColor shortFillColor
Barcolor On/Off ?trueboolbarcolor
Show OTT BUY/SELl Labels?falseboolBUY SELL
From Month1int · min 1 · max 12start
From Day1int · min 1 · max 31start
From Year2020int · min 2017start
To Month1int · min 1 · max 12finish
To Day1int · min 1 · max 31finish
To Year9999int · min 2017finish

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.

FromYearFrom Yearsetting · 2020FromMonthFrom Monthsetting · 1FromDayFrom Daysetting · 1ToYearTo Yearsetting · 9999ToMonthTo Monthsetting · 1ToDayTo Daysetting · 1pdsOTT Periodsetting · 1closecloseprice datapercentOTT Percentsetting · 0.1conditionConditionsetting · Support Line Crossi…startstartvaluefinishfinishvaluealphaalphavalueud1, dd1ud1 · dd12 valuesUDUDvalueDDDDvalueCMOCMOvaluekkvalueVarVarvaluefarkfarkvaluelongStoplongStopvaluelongStopPrevlongStopPrevvalueshortStopshortStopvalueshortStopPrevshortStopPrevvaluedirdirvalueMTMTvalueOTTOTTvaluevColorvColorvaluebuySignalkbuySignalkconditionsellSignallksellSignallkconditionbuySignalcbuySignalcconditionsellSignallcsellSignallcconditionOTTC, ottBuyColor, ottSellColor, longFillColor, shortFillColorColourOTTC · ottBuyColor +3entry:BUYOpen BUYstrategy.entryentry:SELLOpen SELLstrategy.entryplot:46Support Lineplotplot:48OTTplotplotshape:53BUYplotshapeplotshape:54SELLplotshapeplot:65plotfill:UpTrend HighligterUpTrend Highligterfillfill:DownTrend HighligterDownTrend Highligterfillbarcolor:70barcolorbarcolor

Order rules

OrderFires whenBy defaultLine
Open BUY longbuySignalkwindow() and crossover(Var, OTT[2])On60
Open SELL shortsellSignallkwindow() and crossunder(Var, OTT[2])On61
Open BUY longbuySignalcwindow() and crossover(src, OTT[2])On63
Open SELL shortsellSignallcwindow() and crossunder(src, OTT[2])On64

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.

53/53trades 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+98.6%+102.5%15031%1.04179.7%26 Jan 2024 – 21 Oct 2026
BTCUSDT 4h−181.1%+5.5%13329%0.77164.4%8 May 2026 – 21 Oct 2026
ETHUSDT 1D+18.1%+9.8%13431%1.1616.8%26 Jan 2024 – 21 Oct 2026
ETHUSDT 4h−6.9%+8.4%13924%0.779.3%8 May 2026 – 21 Oct 2026
SOLUSDT 1D−0.1%+16.7%16032%0.991.2%26 Jan 2024 – 21 Oct 2026
SOLUSDT 4h+0.2%+21.5%13535%1.170.3%8 May 2026 – 21 Oct 2026
BNBUSDT 1D−2.0%+148.3%15436%0.924.9%26 Jan 2024 – 21 Oct 2026
BNBUSDT 4h+2.0%+17.1%11336%1.401.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 barsTradesWonP&L
Rising market4335%$463.64
Sideways market6929%$12,991.70
Falling market3829%−$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.

0%19,095%
All 150 trades
SideEntryExitBarsP&L
short23 Feb 2024 51,288.4027 Feb 2024 54,476.504−$3,293.82
long27 Feb 2024 54,476.5016 Mar 2024 69,499.8018$14,899.40
short16 Mar 2024 69,499.8026 Mar 2024 69,880.0010−$519.54
long26 Mar 2024 69,880.003 Apr 2024 65,464.008−$4,551.35
short3 Apr 2024 65,464.008 Apr 2024 69,360.405−$4,031.21
long8 Apr 2024 69,360.4013 Apr 2024 67,116.505−$2,380.34
short13 Apr 2024 67,116.5023 Apr 2024 66,819.3010$163.26
long23 Apr 2024 66,819.3025 Apr 2024 64,289.602−$2,660.85
short25 Apr 2024 64,289.605 May 2024 63,892.0010$269.37
long5 May 2024 63,892.0012 May 2024 60,826.007−$3,190.76
short12 May 2024 60,826.0014 May 2024 62,940.102−$2,237.87
long14 May 2024 62,940.1030 May 2024 67,652.4016$4,581.73
short30 May 2024 67,652.404 Jun 2024 68,809.905−$1,293.94
long4 Jun 2024 68,809.9012 Jun 2024 67,314.208−$1,631.78
short12 Jun 2024 67,314.201 Jul 2024 62,772.0019$4,412.13
long1 Jul 2024 62,772.004 Jul 2024 60,208.603−$2,686.42
short4 Jul 2024 60,208.6015 Jul 2024 60,797.9011−$710.35
long15 Jul 2024 60,797.9025 Jul 2024 65,376.0010$4,451.93
short25 Jul 2024 65,376.0028 Jul 2024 67,896.503−$2,653.75
long28 Jul 2024 67,896.5031 Jul 2024 66,188.003−$1,842.57
short31 Jul 2024 66,188.009 Aug 2024 61,686.009$4,374.13
long9 Aug 2024 61,686.0013 Aug 2024 59,346.604−$2,460.39
short13 Aug 2024 59,346.6014 Aug 2024 60,587.201−$1,360.45
long14 Aug 2024 60,587.2016 Aug 2024 57,541.102−$3,164.24
short16 Aug 2024 57,541.1021 Aug 2024 59,013.805−$1,589.30
long21 Aug 2024 59,013.8028 Aug 2024 59,415.007$282.77
short28 Aug 2024 59,415.0010 Sep 2024 57,042.0013$2,256.53
long10 Sep 2024 57,042.001 Oct 2024 63,327.6021$6,165.22
short1 Oct 2024 63,327.6013 Oct 2024 63,206.2012−$5.16
long13 Oct 2024 63,206.2027 Oct 2024 67,092.8014$3,756.23
short27 Oct 2024 67,092.8028 Oct 2024 68,021.701−$1,064.04
long28 Oct 2024 68,021.702 Nov 2024 69,496.005$1,336.79
short2 Nov 2024 69,496.007 Nov 2024 75,572.005−$6,221.06
long7 Nov 2024 75,572.0026 Nov 2024 93,010.0019$17,269.40
short26 Nov 2024 93,010.0029 Nov 2024 95,644.003−$2,822.63
long29 Nov 2024 95,644.0011 Dec 2024 96,593.0012$756.77
short11 Dec 2024 96,593.0012 Dec 2024 101,125.001−$4,729.72
long12 Dec 2024 101,125.0020 Dec 2024 97,461.908−$3,861.73
short20 Dec 2024 97,461.903 Jan 2025 96,984.8014$282.62
long3 Jan 2025 96,984.809 Jan 2025 95,060.606−$2,116.23
short9 Jan 2025 95,060.6015 Jan 2025 96,560.906−$1,691.86
long15 Jan 2025 96,560.9028 Jan 2025 102,083.0013$5,323.34
short28 Jan 2025 102,083.0031 Jan 2025 104,723.003−$2,846.92
long31 Jan 2025 104,723.002 Feb 2025 100,636.002−$4,292.64
short2 Feb 2025 100,636.0011 Feb 2025 97,430.809$3,006.77
long11 Feb 2025 97,430.8012 Feb 2025 95,778.201−$1,845.82
short12 Feb 2025 95,778.2013 Feb 2025 97,870.001−$2,285.44
long13 Feb 2025 97,870.0017 Feb 2025 96,118.104−$1,945.87
short17 Feb 2025 96,118.1021 Feb 2025 98,305.004−$2,381.31
long21 Feb 2025 98,305.0023 Feb 2025 96,551.002−$1,948.86
short23 Feb 2025 96,551.006 Mar 2025 90,606.0011$5,757.85
long6 Mar 2025 90,606.009 Mar 2025 86,222.503−$4,560.37
short9 Mar 2025 86,222.5016 Mar 2025 84,338.407$1,713.46
long16 Mar 2025 84,338.4019 Mar 2025 82,715.003−$1,790.46
short19 Mar 2025 82,715.0020 Mar 2025 86,845.901−$4,300.46
long20 Mar 2025 86,845.9022 Mar 2025 84,088.802−$2,928.07
short22 Mar 2025 84,088.8024 Mar 2025 86,082.502−$2,163.88
long24 Mar 2025 86,082.5029 Mar 2025 84,424.405−$1,828.63
short29 Mar 2025 84,424.406 Apr 2025 83,538.008$718.43
long6 Apr 2025 83,538.007 Apr 2025 78,430.001−$5,269.96
short7 Apr 2025 78,430.0012 Apr 2025 83,423.805−$5,155.68
long12 Apr 2025 83,423.8028 Apr 2025 93,749.3016$10,148.30
short28 Apr 2025 93,749.3029 Apr 2025 95,011.201−$1,450.65
long29 Apr 2025 95,011.201 May 2025 94,172.002−$1,028.36
short1 May 2025 94,172.002 May 2025 96,489.901−$2,508.56
long2 May 2025 96,489.905 May 2025 94,277.603−$2,403.06
short5 May 2025 94,277.607 May 2025 96,834.002−$2,747.52
long7 May 2025 96,834.0029 May 2025 107,782.0022$10,743.10
short29 May 2025 107,782.008 Jun 2025 105,552.0010$2,016.30
long8 Jun 2025 105,552.0013 Jun 2025 105,672.005−$91.63
short13 Jun 2025 105,672.0025 Jun 2025 106,083.0012−$623.01
long25 Jun 2025 106,083.0017 Jul 2025 118,630.0022$12,322.70
short17 Jul 2025 118,630.0018 Jul 2025 119,178.001−$784.93
long18 Jul 2025 119,178.0020 Jul 2025 117,840.002−$1,574.57
short20 Jul 2025 117,840.0023 Jul 2025 119,954.003−$2,352.21
long23 Jul 2025 119,954.0026 Jul 2025 117,614.003−$2,577.69
short26 Jul 2025 117,614.0029 Jul 2025 118,062.003−$683.69
long29 Jul 2025 118,062.0031 Jul 2025 117,840.002−$457.93
short31 Jul 2025 117,840.005 Aug 2025 115,055.005$2,552.36
long5 Aug 2025 115,055.0019 Aug 2025 116,227.0014$940.74
short19 Aug 2025 116,227.004 Sep 2025 111,706.0016$4,293.40
long4 Sep 2025 111,706.007 Sep 2025 110,188.003−$1,739.63
short7 Sep 2025 110,188.008 Sep 2025 111,137.001−$1,170.70
long8 Sep 2025 111,137.0023 Sep 2025 112,651.0015$1,289.85
short23 Sep 2025 112,651.0030 Sep 2025 114,312.007−$1,887.94
long30 Sep 2025 114,312.009 Oct 2025 123,306.009$8,756.42
short9 Oct 2025 123,306.0021 Oct 2025 110,532.0012$12,540.10
long21 Oct 2025 110,532.0023 Oct 2025 107,567.002−$3,182.74
short23 Oct 2025 107,567.0025 Oct 2025 111,005.002−$3,656.02
long25 Oct 2025 111,005.0030 Oct 2025 110,021.005−$1,204.63
short30 Oct 2025 110,021.0025 Nov 2025 88,300.0026$21,523.00
long25 Nov 2025 88,300.007 Dec 2025 89,236.8012$759.25
short7 Dec 2025 89,236.808 Dec 2025 90,395.301−$1,338.15
long8 Dec 2025 90,395.3014 Dec 2025 90,240.006−$335.95
short14 Dec 2025 90,240.0021 Dec 2025 88,360.907$1,700.49
long21 Dec 2025 88,360.9025 Dec 2025 87,669.404−$867.50
short25 Dec 2025 87,669.4029 Dec 2025 87,952.704−$458.89
long29 Dec 2025 87,952.708 Jan 2026 91,364.2010$3,232.13
short8 Jan 2026 91,364.2014 Jan 2026 95,414.006−$4,236.61
long14 Jan 2026 95,414.0020 Jan 2026 92,631.006−$2,971.04
short20 Jan 2026 92,631.0029 Jan 2026 89,300.009$3,149.06
long29 Jan 2026 89,300.0030 Jan 2026 84,650.201−$4,823.79
short30 Jan 2026 84,650.2015 Feb 2026 69,822.9016$14,672.70
long15 Feb 2026 69,822.9018 Feb 2026 67,503.503−$2,456.75
short18 Feb 2026 67,503.5022 Feb 2026 67,975.904−$607.89
long22 Feb 2026 67,975.9024 Feb 2026 64,656.002−$3,452.55
short24 Feb 2026 64,656.0027 Feb 2026 67,485.203−$2,961.32
long27 Feb 2026 67,485.201 Mar 2026 66,973.302−$646.39
short1 Mar 2026 66,973.303 Mar 2026 68,830.102−$1,992.60
long3 Mar 2026 68,830.108 Mar 2026 67,262.905−$1,703.24
short8 Mar 2026 67,262.9011 Mar 2026 69,948.603−$2,822.94
long11 Mar 2026 69,948.6019 Mar 2026 71,246.608$1,156.71
short19 Mar 2026 71,246.6026 Mar 2026 71,336.507−$232.56
long26 Mar 2026 71,336.5027 Mar 2026 68,820.301−$2,656.38
short27 Mar 2026 68,820.301 Apr 2026 68,284.505$398.71
long1 Apr 2026 68,284.504 Apr 2026 66,964.303−$1,455.45
short4 Apr 2026 66,964.306 Apr 2026 69,034.202−$2,205.89
long6 Apr 2026 69,034.2020 Apr 2026 73,801.8014$4,624.78
short20 Apr 2026 73,801.8022 Apr 2026 76,336.102−$2,684.48
long22 Apr 2026 76,336.1029 Apr 2026 76,342.807−$146.04
short29 Apr 2026 76,342.802 May 2026 78,231.103−$2,042.92
long2 May 2026 78,231.1013 May 2026 80,504.5011$2,114.60
short13 May 2026 80,504.5022 May 2026 77,615.509$2,730.83
long22 May 2026 77,615.5023 May 2026 75,539.501−$2,229.18
short23 May 2026 75,539.5026 May 2026 77,322.003−$1,935.37
long26 May 2026 77,322.0027 May 2026 75,930.001−$1,545.25
short27 May 2026 75,930.008 Jun 2026 63,332.0012$12,458.70
long8 Jun 2026 63,332.0010 Jun 2026 61,730.002−$1,727.07
short10 Jun 2026 61,730.0012 Jun 2026 63,626.002−$2,021.36
long12 Jun 2026 63,626.0019 Jun 2026 62,958.007−$794.57
short19 Jun 2026 62,958.003 Jul 2026 61,560.0014$1,273.49
long3 Jul 2026 61,560.009 Jul 2026 62,290.006$606.16
short9 Jul 2026 62,290.0011 Jul 2026 64,161.702−$1,998.16
long11 Jul 2026 64,161.7014 Jul 2026 62,334.503−$1,953.70
short14 Jul 2026 62,334.5015 Jul 2026 65,044.001−$2,836.85
long15 Jul 2026 65,044.0018 Jul 2026 63,931.703−$1,241.30
short18 Jul 2026 63,931.7019 Jul 2026 64,834.201−$1,031.31
long19 Jul 2026 64,834.2025 Jul 2026 64,140.006−$823.18
short25 Jul 2026 64,140.0027 Jul 2026 65,400.002−$1,389.54
long27 Jul 2026 65,400.0028 Jul 2026 63,755.901−$1,773.30
short28 Jul 2026 63,755.906 Aug 2026 64,665.209−$1,037.80
long6 Aug 2026 64,665.2012 Aug 2026 63,600.006−$1,193.50
short12 Aug 2026 63,600.0018 Aug 2026 64,532.106−$1,060.23
long18 Aug 2026 64,532.1030 Aug 2026 78,230.0012$13,555.10
short30 Aug 2026 78,230.004 Sep 2026 81,270.405−$3,199.87
long4 Sep 2026 81,270.409 Sep 2026 78,455.805−$2,974.30
short9 Sep 2026 78,455.8019 Sep 2026 80,883.9010−$2,587.40
long19 Sep 2026 80,883.9030 Sep 2026 83,663.7011$2,615.25
short30 Sep 2026 83,663.702 Oct 2026 84,880.102−$1,384.93
long2 Oct 2026 84,880.108 Oct 2026 83,321.806−$1,726.44

Similar scripts

No other indicator or strategy here shares enough of its calculations.

Where it runs

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