Zeal Terminal Open in Zeal Terminal

Pine Script v4 · Strategy

Optimized Trend Tracker STRATEGY & SCREENER

A Pine Script v4 strategy built on Linreg (close, 2), SMA or EMA or WMA (close, 2) and Crossover (MAvg, OTT[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. 41 settings; defaults include Source close, OTT Period 2 and OTT Percent 1.4.

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 & SCREENER repaint?
No
No repainting patterns were found in the source, and a live tick-by-tick replay matched history on 25 of 25 trades.
How did Optimized Trend Tracker STRATEGY & SCREENER do on BTCUSDT 1D with default settings?
+18.05%
From 26 Jan 2024 to 21 Oct 2026, over 77 closed trades, against +102.5% for buy and hold. A backtest, not investment advice.
Can Optimized Trend Tracker STRATEGY & SCREENER 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.
What alerts does Optimized Trend Tracker STRATEGY & SCREENER have?
9
Color ALARM; GREEN ALERT; RED ALERT; Cross Alert; and more.
Does Optimized Trend Tracker STRATEGY & SCREENER use a stop loss?
No
Every exit waits for a signal; nothing limits a losing trade before it fires.

BTCUSDT · 1D · default settings

  • Support Line
  • OTT
  • Buy
  • Sell
  • Winning trade
  • Losing trade
  • Equity
  • Buy and hold
Confirmed Reversal: 0.0050,000100,000AprJulOct2025AprJulOct2026AprJulOct$115,985$202,527Equity from $100,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. Lines, boxes and labels are the script's own drawings, the most recent ones its limits keep. The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market. Data the page supplies at the chart's own timeframe (another symbol, or Heikin-Ashi) reaches the script one bar later in Zeal Terminal's engine than on TradingView. The live re-run is not offered here: the script requests EURUSD D, XAUUSD D, AMZN D, TSLA D, ETHBTC D, XBTUSD D, XRPBTC D, THYAO D, GARAN D, which this page cannot load in your browser.

Needs EURUSD D data, not available: EURUSD is not on Binance Needs XAUUSD D data, not available: XAUUSD is not on Binance Needs AMZN D data, not available: not a Binance spot market Needs TSLA D data, not available: not a Binance spot market Needs XBTUSD D data, not available: XBTUSD is not on Binance Needs THYAO D data, not available: THYAO is not on Binance Needs GARAN D data, not available: GARAN is not on Binance Values that depend on it are empty on this chart.

Net profit
+18.05%
$18,055.00
Buy and hold
+102.5%
same period
Closed trades
77
28 won · 49 lost
Profitable
36.4%
of closed trades
Profit factor
1.10
gross profit ÷ gross loss
Max drawdown
25.57%
−$29,627.70

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

    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 143, 145. The upgraded version below moves each call inside an if block.

  • Note

    Uses transp =, which v5 removed line 87

    transp = on line 87, 98, 100, 102, 104, 111, 113. 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, round → math.round, ema → ta.ema, linreg → ta.linreg, sma → ta.sma, wma → ta.wma, ceil → math.ceil, floor → math.floor, max → math.max, min → math.min, cross → ta.cross, crossover → ta.crossover, crossunder → ta.crossunder, security → request.security.
  • 2 strategy calls use the when = argument (line 143, 145). It is deprecated in v5 and removed in v6, where each call moves inside an if block.

v4 → v5

Verified

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

  • Line 1: //@version=4 → //@version=5
  • Line 10: input(type = input.float) → input.float()
  • Line 11: input(type = input.bool) → input.bool()
  • Line 12: input(type = input.bool) → input.bool()
  • Line 13: input(type = input.bool) → input.bool()
  • Line 14: input(type = input.bool) → input.bool()
84 more edits
  • Line 15: input(type = input.bool) → input.bool()
  • Line 16: input(type = input.bool) → input.bool()
  • Line 22: sum → math.sum
  • Line 23: sum → math.sum
  • Line 26: abs → math.abs
  • Line 26: abs → math.abs
  • Line 34: round → math.round
  • Line 36: ema → ta.ema
  • Line 39: linreg → ta.linreg
  • Line 40: linreg → ta.linreg
  • Line 42: linreg → ta.linreg
  • Line 47: sma → ta.sma
  • Line 50: ema → ta.ema
  • Line 53: wma → ta.wma
  • Line 56: sma → ta.sma
  • Line 56: sma → ta.sma
  • Line 56: ceil → math.ceil
  • Line 56: floor → math.floor
  • Line 76: max → math.max
  • Line 79: min → math.min
  • Line 87: transp = 0 → color.new(OTTC, 0)
  • Line 88: cross → ta.cross
  • Line 89: crossover → ta.crossover
  • Line 90: crossunder → ta.crossunder
  • Line 91: cross → ta.cross
  • Line 92: crossover → ta.crossover
  • Line 93: crossunder → ta.crossunder
  • Line 94: cross → ta.cross
  • Line 95: crossover → ta.crossover
  • Line 96: crossunder → ta.crossunder
  • Line 97: crossover → ta.crossover
  • Line 98: transp = 0 → color.new(color.green, 0)
  • Line 99: crossunder → ta.crossunder
  • Line 100: transp = 0 → color.new(color.red, 0)
  • Line 101: crossover → ta.crossover
  • Line 102: transp = 0 → color.new(color.green, 0)
  • Line 103: crossunder → ta.crossunder
  • Line 104: transp = 0 → color.new(color.red, 0)
  • Line 110: crossover → ta.crossover
  • Line 111: transp = 0 → color.new(color.green, 0)
  • Line 112: crossunder → ta.crossunder
  • Line 113: transp = 0 → color.new(color.red, 0)
  • Line 146: input(type = input.symbol) → input.symbol()
  • Line 147: input(type = input.symbol) → input.symbol()
  • Line 148: input(type = input.symbol) → input.symbol()
  • Line 149: input(type = input.symbol) → input.symbol()
  • Line 150: input(type = input.symbol) → input.symbol()
  • Line 151: input(type = input.symbol) → input.symbol()
  • Line 152: input(type = input.symbol) → input.symbol()
  • Line 153: input(type = input.symbol) → input.symbol()
  • Line 154: input(type = input.symbol) → input.symbol()
  • Line 155: input(type = input.symbol) → input.symbol()
  • Line 156: input(type = input.symbol) → input.symbol()
  • Line 157: input(type = input.symbol) → input.symbol()
  • Line 158: input(type = input.symbol) → input.symbol()
  • Line 159: input(type = input.symbol) → input.symbol()
  • Line 160: input(type = input.symbol) → input.symbol()
  • Line 161: input(type = input.symbol) → input.symbol()
  • Line 162: input(type = input.symbol) → input.symbol()
  • Line 163: input(type = input.symbol) → input.symbol()
  • Line 164: input(type = input.symbol) → input.symbol()
  • Line 165: input(type = input.symbol) → input.symbol()
  • Line 171: max → math.max
  • Line 173: min → math.min
  • Line 184: security → request.security
  • Line 185: security → request.security
  • Line 186: security → request.security
  • Line 187: security → request.security
  • Line 188: security → request.security
  • Line 189: security → request.security
  • Line 190: security → request.security
  • Line 191: security → request.security
  • Line 192: security → request.security
  • Line 193: security → request.security
  • Line 194: security → request.security
  • Line 195: security → request.security
  • Line 196: security → request.security
  • Line 197: security → request.security
  • Line 198: security → request.security
  • Line 199: security → request.security
  • Line 200: security → request.security
  • Line 201: security → request.security
  • Line 202: security → request.security
  • Line 203: security → request.security
-//@version=4+//@version=5// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/⋯length=input(2, "OTT Period", minval=1)-percent=input(1.4, "OTT Percent", type=input.float, step=0.1, minval=0)+percent=input.float(1.4, "OTT Percent", step=0.1, minval=0)-showsupport = input(title="Show Support Line?", type=input.bool, defval=true)+showsupport = input.bool(title="Show Support Line?", defval=true)-showsignalsk = input(title="Show Support Line Crossing Signals?", type=input.bool, defval=true)+showsignalsk = input.bool(title="Show Support Line Crossing Signals?", defval=true)-showsignalsc = input(title="Show Price/OTT Crossing Signals?", type=input.bool, defval=false)+showsignalsc = input.bool(title="Show Price/OTT Crossing Signals?", defval=false)-highlight = input(title="Show OTT Color Changes?", type=input.bool, defval=false)+highlight = input.bool(title="Show OTT Color Changes?", defval=false)-showsignalsr = input(title="Show OTT Color Change Signals?", type=input.bool, defval=false)+showsignalsr = input.bool(title="Show OTT Color Change Signals?", defval=false)-highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)+highlighting = input.bool(title="Highlighter On/Off ?", defval=true)mav = input(title="Moving Average Type", defval="VAR", options=["SMA", "EMA", "WMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF"])⋯    vdd1=src<src[1] ? src[1]-src : 0-    vUD=sum(vud1,9)+    vUD=math.sum(vud1,9)-    vDD=sum(vdd1,9)+    vDD=math.sum(vdd1,9)    vCMO=nz((vUD-vDD)/(vUD+vDD))    VAR=0.0-    VAR:=nz(valpha*abs(vCMO)*src)+(1-valpha*abs(vCMO))*nz(VAR[1])+    VAR:=nz(valpha*math.abs(vCMO)*src)+(1-valpha*math.abs(vCMO))*nz(VAR[1])VAR=Var_Func(src,length)⋯Zlema_Func(src,length)=>-    zxLag = length/2==round(length/2) ? length/2 : (length - 1) / 2+    zxLag = length/2==math.round(length/2) ? length/2 : (length - 1) / 2    zxEMAData = (src + (src - src[zxLag]))-    ZLEMA = ema(zxEMAData, length)+    ZLEMA = ta.ema(zxEMAData, length)ZLEMA=Zlema_Func(src,length)Tsf_Func(src,length)=>-    lrc = linreg(src, length, 0)+    lrc = ta.linreg(src, length, 0)-    lrc1 = linreg(src,length,1)+    lrc1 = ta.linreg(src,length,1)    lrs = (lrc-lrc1)-    TSF = linreg(src, length, 0)+lrs+    TSF = ta.linreg(src, length, 0)+lrsTSF=Tsf_Func(src,length)⋯    if mav == "SMA"-        ma := sma(src, length)+        ma := ta.sma(src, length)        ma    if mav == "EMA"-        ma := ema(src, length)+        ma := ta.ema(src, length)        ma    if mav == "WMA"-        ma := wma(src, length)+        ma := ta.wma(src, length)        ma    if mav == "TMA"-        ma := sma(sma(src, ceil(length / 2)), floor(length / 2) + 1)+        ma := ta.sma(ta.sma(src, math.ceil(length / 2)), math.floor(length / 2) + 1)        ma⋯longStopPrev = nz(longStop[1], longStop)-longStop := MAvg > longStopPrev ? max(longStop, longStopPrev) : longStop+longStop := MAvg > longStopPrev ? math.max(longStop, longStopPrev) : longStopshortStop =  MAvg + farkshortStopPrev = nz(shortStop[1], shortStop)-shortStop := MAvg < shortStopPrev ? min(shortStop, shortStopPrev) : shortStop+shortStop := MAvg < 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")-alertcondition(cross(OTT[2], OTT[3]), title="Color ALARM", message="OTT Has Changed Color!")+alertcondition(ta.cross(OTT[2], OTT[3]), title="Color ALARM", message="OTT Has Changed Color!")-alertcondition(crossover(OTT[2], OTT[3]), title="GREEN ALERT", message="OTT GREEN BUY SIGNAL!")+alertcondition(ta.crossover(OTT[2], OTT[3]), title="GREEN ALERT", message="OTT GREEN BUY SIGNAL!")-alertcondition(crossunder(OTT[2], OTT[3]), title="RED ALERT", message="OTT RED SELL SIGNAL!")+alertcondition(ta.crossunder(OTT[2], OTT[3]), title="RED ALERT", message="OTT RED SELL SIGNAL!")-alertcondition(cross(MAvg, OTT[2]), title="Cross Alert", message="OTT - Support Line Crossing!")+alertcondition(ta.cross(MAvg, OTT[2]), title="Cross Alert", message="OTT - Support Line Crossing!")-alertcondition(crossover(MAvg, OTT[2]), title="Crossover Alarm", message="Support Line BUY SIGNAL!")+alertcondition(ta.crossover(MAvg, OTT[2]), title="Crossover Alarm", message="Support Line BUY SIGNAL!")-alertcondition(crossunder(MAvg, OTT[2]), title="Crossunder Alarm", message="Support Line SELL SIGNAL!")+alertcondition(ta.crossunder(MAvg, OTT[2]), title="Crossunder Alarm", message="Support Line SELL SIGNAL!")-alertcondition(cross(src, OTT[2]), title="Price Cross Alert", message="OTT - Price Crossing!")+alertcondition(ta.cross(src, OTT[2]), title="Price Cross Alert", message="OTT - Price Crossing!")-alertcondition(crossover(src, OTT[2]), title="Price Crossover Alarm", message="PRICE OVER OTT - BUY SIGNAL!")+alertcondition(ta.crossover(src, OTT[2]), title="Price Crossover Alarm", message="PRICE OVER OTT - BUY SIGNAL!")-alertcondition(crossunder(src, OTT[2]), title="Price Crossunder Alarm", message="PRICE UNDER OTT - SELL SIGNAL!")+alertcondition(ta.crossunder(src, OTT[2]), title="Price Crossunder Alarm", message="PRICE UNDER OTT - SELL SIGNAL!")-buySignalk = crossover(MAvg, OTT[2])+buySignalk = ta.crossover(MAvg, OTT[2])-plotshape(buySignalk and showsignalsk ? OTT*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)+plotshape(buySignalk and showsignalsk ? OTT*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 0), textcolor=color.white)-sellSignallk = crossunder(MAvg, OTT[2])+sellSignallk = ta.crossunder(MAvg, OTT[2])-plotshape(sellSignallk and showsignalsk ? OTT*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)+plotshape(sellSignallk and showsignalsk ? OTT*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.white)-buySignalc = crossover(src, OTT[2])+buySignalc = ta.crossover(src, OTT[2])-plotshape(buySignalc and showsignalsc ? OTT*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)+plotshape(buySignalc and showsignalsc ? OTT*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 0), textcolor=color.white)-sellSignallc = crossunder(src, OTT[2])+sellSignallc = ta.crossunder(src, OTT[2])-plotshape(sellSignallc and showsignalsc ? OTT*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)+plotshape(sellSignallc and showsignalsc ? OTT*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.white)mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0,display=display.none)⋯fill(mPlot, pALL, title="DownTrend Highligter", color=shortFillColor)-buySignalr = crossover(OTT[2], OTT[3])+buySignalr = ta.crossover(OTT[2], OTT[3])-plotshape(buySignalr and showsignalsr ? OTT*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)+plotshape(buySignalr and showsignalsr ? OTT*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.new(color.green, 0), textcolor=color.white)-sellSignallr = crossunder(OTT[2], OTT[3])+sellSignallr = ta.crossunder(OTT[2], OTT[3])-plotshape(sellSignallr and showsignalsr ? OTT*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)+plotshape(sellSignallr and showsignalsr ? OTT*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.white)showscr = input(true, title="Show Screener Label")⋯    strategy.entry("Short", strategy.short,when=Timerange())-t1=input('EURUSD',   title='Symbol 01',type=input.symbol)+t1=input.symbol('EURUSD',   title='Symbol 01')-t2=input('XAUUSD',    title='Symbol 02',type=input.symbol)+t2=input.symbol('XAUUSD',    title='Symbol 02')-t3=input('AMZN',    title='Symbol 03',type=input.symbol)+t3=input.symbol('AMZN',    title='Symbol 03')-t4=input('TSLA',    title='Symbol 04',type=input.symbol)+t4=input.symbol('TSLA',    title='Symbol 04')-t5=input('BTCUSDT',    title='Symbol 05',type=input.symbol)+t5=input.symbol('BTCUSDT',    title='Symbol 05')-t6=input('ETHBTC',    title='Symbol 06',type=input.symbol)+t6=input.symbol('ETHBTC',    title='Symbol 06')-t7=input('XBTUSD',    title='Symbol 07',type=input.symbol)+t7=input.symbol('XBTUSD',    title='Symbol 07')-t8=input('XRPBTC',    title='Symbol 08',type=input.symbol)+t8=input.symbol('XRPBTC',    title='Symbol 08')-t9=input('THYAO',   title='Symbol 09',type=input.symbol)+t9=input.symbol('THYAO',   title='Symbol 09')-t10=input('GARAN',    title='Symbol 10',type=input.symbol)+t10=input.symbol('GARAN',    title='Symbol 10')-t11=input('',      title='Symbol 11',type=input.symbol)+t11=input.symbol('',      title='Symbol 11')-t12=input('',      title='Symbol 12',type=input.symbol)+t12=input.symbol('',      title='Symbol 12')-t13=input('',      title='Symbol 13',type=input.symbol)+t13=input.symbol('',      title='Symbol 13')-t14=input('',      title='Symbol 14',type=input.symbol)+t14=input.symbol('',      title='Symbol 14')-t15=input('',      title='Symbol 15',type=input.symbol)+t15=input.symbol('',      title='Symbol 15')-t16=input('',     title='Symbol 16',type=input.symbol)+t16=input.symbol('',     title='Symbol 16')-t17=input('',    title='Symbol 17',type=input.symbol)+t17=input.symbol('',    title='Symbol 17')-t18=input('',    title='Symbol 18',type=input.symbol)+t18=input.symbol('',    title='Symbol 18')-t19=input('',    title='Symbol 19',type=input.symbol)+t19=input.symbol('',    title='Symbol 19')-t20=input('',    title='Symbol 20',type=input.symbol)+t20=input.symbol('',    title='Symbol 20')OTTs(percent, length) =>⋯    TrendUp = 0.0-    TrendUp := MAvg[1]>TrendUp[1] ? max(Up,TrendUp[1]) : Up+    TrendUp := MAvg[1]>TrendUp[1] ? math.max(Up,TrendUp[1]) : Up    TrendDown = 0.0-    TrendDown := MAvg[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn+    TrendDown := MAvg[1]<TrendDown[1]? math.min(Dn,TrendDown[1]) : Dn    Trend = 0.0⋯TrendReversal = Trend != Trend[1]-[t01, s01] = security(t1, timeframe.period, OTTs(percent, length))+[t01, s01] = request.security(t1, timeframe.period, OTTs(percent, length))-[t02, s02] = security(t2, timeframe.period, OTTs(percent, length))+[t02, s02] = request.security(t2, timeframe.period, OTTs(percent, length))-[t03, s03] = security(t3, timeframe.period, OTTs(percent, length))+[t03, s03] = request.security(t3, timeframe.period, OTTs(percent, length))-[t04, s04] = security(t4, timeframe.period, OTTs(percent, length))+[t04, s04] = request.security(t4, timeframe.period, OTTs(percent, length))-[t05, s05] = security(t5, timeframe.period, OTTs(percent, length))+[t05, s05] = request.security(t5, timeframe.period, OTTs(percent, length))-[t06, s06] = security(t6, timeframe.period, OTTs(percent, length))+[t06, s06] = request.security(t6, timeframe.period, OTTs(percent, length))-[t07, s07] = security(t7, timeframe.period, OTTs(percent, length))+[t07, s07] = request.security(t7, timeframe.period, OTTs(percent, length))-[t08, s08] = security(t8, timeframe.period, OTTs(percent, length))+[t08, s08] = request.security(t8, timeframe.period, OTTs(percent, length))-[t09, s09] = security(t9, timeframe.period, OTTs(percent, length))+[t09, s09] = request.security(t9, timeframe.period, OTTs(percent, length))-[t010, s010] = security(t10, timeframe.period, OTTs(percent, length))+[t010, s010] = request.security(t10, timeframe.period, OTTs(percent, length))-[t011, s011] = security(t11, timeframe.period, OTTs(percent, length))+[t011, s011] = request.security(t11, timeframe.period, OTTs(percent, length))-[t012, s012] = security(t12, timeframe.period, OTTs(percent, length))+[t012, s012] = request.security(t12, timeframe.period, OTTs(percent, length))-[t013, s013] = security(t13, timeframe.period, OTTs(percent, length))+[t013, s013] = request.security(t13, timeframe.period, OTTs(percent, length))-[t014, s014] = security(t14, timeframe.period, OTTs(percent, length))+[t014, s014] = request.security(t14, timeframe.period, OTTs(percent, length))-[t015, s015] = security(t15, timeframe.period, OTTs(percent, length))+[t015, s015] = request.security(t15, timeframe.period, OTTs(percent, length))-[t016, s016] = security(t16, timeframe.period, OTTs(percent, length))+[t016, s016] = request.security(t16, timeframe.period, OTTs(percent, length))-[t017, s017] = security(t17, timeframe.period, OTTs(percent, length))+[t017, s017] = request.security(t17, timeframe.period, OTTs(percent, length))-[t018, s018] = security(t18, timeframe.period, OTTs(percent, length))+[t018, s018] = request.security(t18, timeframe.period, OTTs(percent, length))-[t019, s019] = security(t19, timeframe.period, OTTs(percent, length))+[t019, s019] = request.security(t19, timeframe.period, OTTs(percent, length))-[t020, s020] = security(t20, timeframe.period, OTTs(percent, length))+[t020, s020] = request.security(t20, timeframe.period, OTTs(percent, length))tr01 = t01 != t01[1], up01 = t01 == 1, dn01 = t01 == -1⋯

Clean v5

VerifiedDownload the v5 script

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

  • Line 8: input() → input.source()
  • Line 9: input() → input.int()
  • Line 17: input() → input.string()
  • Line 114: input() → input.bool()
  • Line 115: input() → input.int()
  • Line 116: input() → input.int()
10 more edits
  • Line 117: input() → input.string()
  • Line 131: input() → input.bool()
  • Line 132: input() → input.int()
  • Line 133: input() → input.int()
  • Line 134: input() → input.int()
  • Line 135: input() → input.int()
  • Line 136: input() → input.int()
  • Line 137: input() → input.int()
  • Line 143: when = Timerange() → if block
  • Line 145: when = Timerange() → if block
⋯strategy("Optimized Trend Tracker","OTTEx", overlay=true)-src = input(close, title="Source")+src = input.source(close, title="Source")-length=input(2, "OTT Period", minval=1)+length=input.int(2, "OTT Period", minval=1)percent=input.float(1.4, "OTT Percent", step=0.1, minval=0)⋯highlighting = input.bool(title="Highlighter On/Off ?", defval=true)-mav = input(title="Moving Average Type", defval="VAR", options=["SMA", "EMA", "WMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF"])+mav = input.string(title="Moving Average Type", defval="VAR", options=["SMA", "EMA", "WMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF"])Var_Func(src,length)=>⋯plotshape(sellSignallr and showsignalsr ? OTT*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.new(color.red, 0), textcolor=color.white)-showscr = input(true, title="Show Screener Label")+showscr = input.bool(true, title="Show Screener Label")-posX_scr = input(20, title="Pos. Label x-axis")+posX_scr = input.int(20, title="Pos. Label x-axis")-posY_scr = input(1, title="Pos. Size Label y-axis")+posY_scr = input.int(1, title="Pos. Size Label y-axis")-colinput = input(title="Label Color", defval="Blue", options=["White", "Black", "Red", "Green", "Yellow", "Blue"])+colinput = input.string(title="Label Color", defval="Blue", options=["White", "Black", "Red", "Green", "Yellow", "Blue"])col = color.gray⋯    col:=color.blue-dummy0 = input(true, title = "=Backtest Inputs=")+dummy0 = input.bool(true, title = "=Backtest Inputs=")-FromDay    = input(defval = 1, title = "From Day", minval = 1, maxval = 31)+FromDay    = input.int(defval = 1, title = "From Day", minval = 1, maxval = 31)-FromMonth  = input(defval = 1, title = "From Month", minval = 1, maxval = 12)+FromMonth  = input.int(defval = 1, title = "From Month", minval = 1, maxval = 12)-FromYear   = input(defval = 2005, title = "From Year", minval = 2005)+FromYear   = input.int(defval = 2005, title = "From Year", minval = 2005)-ToDay      = input(defval = 1, title = "To Day", minval = 1, maxval = 31)+ToDay      = input.int(defval = 1, title = "To Day", minval = 1, maxval = 31)-ToMonth    = input(defval = 1, title = "To Month", minval = 1, maxval = 12)+ToMonth    = input.int(defval = 1, title = "To Month", minval = 1, maxval = 12)-ToYear     = input(defval = 9999, title = "To Year", minval = 2006)+ToYear     = input.int(defval = 9999, title = "To Year", minval = 2006)Start     = timestamp(FromYear, FromMonth, FromDay, 00, 00)⋯if buySignalk-    strategy.entry("Long", strategy.long,when=Timerange())+    if Timerange()+        strategy.entry("Long", strategy.long)if sellSignallk-    strategy.entry("Short", strategy.short,when=Timerange())+    if Timerange()+        strategy.entry("Short", strategy.short)t1=input.symbol('EURUSD',   title='Symbol 01')⋯

Does it run in Pine Script v6?

No

The v6 version does not run in Zeal Terminal's engine: Pine Script v6 Error at @L105: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/⋯

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 buySignalc sellSignallc Price Cross Alert Price Crossover Alarm Price Crossunder Alarm
OTT Period2int · min 1valpha VAR wwalpha WWMA zxLag ZLEMA lrc lrc1 TSF ma MAvg Trend Tsl t01 s01 t02 s02 t03 s03 t04 s04 t05 s05 t06 s06 t07 s07 t08 s08 t09 s09 t010 s010 t011 s011 t012 s012 t013 s013 t014 s014 t015 s015 t016 s016 t017 s017 t018 s018 t019 s019 t020 s020
OTT Percent1.4float · min 0 · step 0.1fark OTT Up Dn Trend Tsl t01 s01 t02 s02 t03 s03 t04 s04 t05 s05 t06 s06 t07 s07 t08 s08 t09 s09 t010 s010 t011 s011 t012 s012 t013 s013 t014 s014 t015 s015 t016 s016 t017 s017 t018 s018 t019 s019 t020 s020
Show Support Line?trueboolSupport Line
Show Support Line Crossing Signals?trueboolBuy Sell
Show Price/OTT Crossing Signals?falseboolBuy Sell
Show OTT Color Changes?falseboolOTTC
Show OTT Color Change Signals?falseboolBuy Sell
Highlighter On/Off ?trueboollongFillColor shortFillColor
Moving Average TypeVARstring · options ["SMA", "EMA", "WMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF"]line 46 line 49 line 52 line 55 line 58 line 61 line 64 line 67
Show Screener Labeltruebool_lblscr
Pos. Label x-axis20int_lblscr
Pos. Size Label y-axis1int_lblscr
Label ColorBluestring · options ["White", "Black", "Red", "Green", "Yellow", "Blue"]line 119 line 121 line 123 line 125 line 127 line 129
=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
Symbol 01EURUSDsymbolt01 s01 pot_label scr_label up_label dn_label
Symbol 02XAUUSDsymbolt02 s02 pot_label scr_label up_label dn_label
Symbol 03AMZNsymbolt03 s03 pot_label scr_label up_label dn_label
Symbol 04TSLAsymbolt04 s04 pot_label scr_label up_label dn_label
Symbol 05BTCUSDTsymbolt05 s05 pot_label scr_label up_label dn_label
Symbol 06ETHBTCsymbolt06 s06 pot_label scr_label up_label dn_label
Symbol 07XBTUSDsymbolt07 s07 pot_label scr_label up_label dn_label
Symbol 08XRPBTCsymbolt08 s08 pot_label scr_label up_label dn_label
Symbol 09THYAOsymbolt09 s09 pot_label scr_label up_label dn_label
Symbol 10GARANsymbolt010 s010 pot_label scr_label up_label dn_label
Symbol 11symbolt011 s011 pot_label scr_label up_label dn_label
Symbol 12symbolt012 s012 pot_label scr_label up_label dn_label
Symbol 13symbolt013 s013 pot_label scr_label up_label dn_label
Symbol 14symbolt014 s014 pot_label scr_label up_label dn_label
Symbol 15symbolt015 s015 pot_label scr_label up_label dn_label
Symbol 16symbolt016 s016 pot_label scr_label up_label dn_label
Symbol 17symbolt017 s017 pot_label scr_label up_label dn_label
Symbol 18symbolt018 s018 pot_label scr_label up_label dn_label
Symbol 19symbolt019 s019 pot_label scr_label up_label dn_label
Symbol 20symbolt020 s020 pot_label scr_label up_label dn_label

What it calculates

  • Linreg (linreg, ta.linreg in v5)Source (close), OTT Period (2), 0lrc · line 39
  • Linreg (linreg, ta.linreg in v5)Source (close), OTT Period (2), 1lrc1 · line 40
  • SMA / EMA / WMA (sma, ta.sma in v5)Source (close), OTT Period (2)ma · line 47
  • Crossover (crossover, ta.crossover in v5)MAvg, OTT[2]buySignalk · line 97
  • Crossunder (crossunder, ta.crossunder in v5)MAvg, OTT[2]sellSignallk · line 99
  • Crossover (crossover, ta.crossover in v5)Source (close), OTT[2]buySignalc · line 101
  • Crossunder (crossunder, ta.crossunder in v5)Source (close), OTT[2]sellSignallc · line 103
  • Crossover (crossover, ta.crossover in v5)OTT[2], OTT[3]buySignalr · line 110
  • Crossunder (crossunder, ta.crossunder in v5)OTT[2], OTT[3]sellSignallr · line 112

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.

The script has 133 named inputs, calculations, conditions and outputs, too many to draw legibly here; the tables above list them.

Order rules

OrderFires whenBy defaultLine
Open Long longTimerange()On143
Open Short shortTimerange()On145

Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.

Alerts

AlertCallMessageLine
Color ALARMalertconditionOTT Has Changed Color!88
GREEN ALERTalertconditionOTT GREEN BUY SIGNAL!89
RED ALERTalertconditionOTT RED SELL SIGNAL!90
Cross AlertalertconditionOTT - Support Line Crossing!91
Crossover AlarmalertconditionSupport Line BUY SIGNAL!92
Crossunder AlarmalertconditionSupport Line SELL SIGNAL!93
Price Cross AlertalertconditionOTT - Price Crossing!94
Price Crossover AlarmalertconditionPRICE OVER OTT - BUY SIGNAL!95
Price Crossunder AlarmalertconditionPRICE UNDER OTT - SELL SIGNAL!96

Does it repaint?

No

No repainting patterns in the source, and the live replay matched history.

25/25trades 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 data20 security call(s), none with lookahead on.
  • 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

Not run on other markets: the script requests EURUSD D, XAUUSD D, AMZN D, TSLA D, XBTUSD D, THYAO D, GARAN D, and that data is not available here (EURUSD is not on Binance; XAUUSD is not on Binance; not a Binance spot market; not a Binance spot market; XBTUSD is not on Binance; THYAO is not on Binance; GARAN is not on Binance). Its results would rest on empty values.

The trades

By market direction

At entry, last 90 barsTradesWonP&L
Rising market2425%−$27,993.60
Sideways market3647%$38,325.90
Falling market1729%$7,722.64

Rising and falling mean the market moved more than 15% over the 90 bars before entry.

How bad could the drawdown be?

52.3%

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

0%60%
All 77 trades
SideEntryExitBarsP&L
long4 Feb 2024 43,011.1024 Feb 2024 50,744.2020$7,733.05
short24 Feb 2024 50,744.2027 Feb 2024 54,476.503−$3,732.33
long27 Feb 2024 54,476.5017 Mar 2024 65,300.6019$10,824.20
short17 Mar 2024 65,300.6027 Mar 2024 69,988.0010−$4,687.35
long27 Mar 2024 69,988.004 Apr 2024 65,963.308−$4,024.72
short4 Apr 2024 65,963.3012 Apr 2024 70,006.208−$4,042.95
long12 Apr 2024 70,006.2014 Apr 2024 63,924.502−$6,081.70
short14 Apr 2024 63,924.5023 Apr 2024 66,819.309−$2,894.80
long23 Apr 2024 66,819.3029 Apr 2024 63,118.606−$3,700.70
short29 Apr 2024 63,118.607 May 2024 63,165.208−$46.56
long7 May 2024 63,165.202 Jun 2024 67,766.8026$4,601.66
short2 Jun 2024 67,766.805 Jun 2024 70,537.803−$2,770.99
long5 Jun 2024 70,537.8014 Jun 2024 66,773.009−$3,764.82
short14 Jun 2024 66,773.0015 Jul 2024 60,797.9031$5,975.10
long15 Jul 2024 60,797.9025 Jul 2024 65,376.0010$4,578.10
short25 Jul 2024 65,376.0027 Jul 2024 67,908.002−$2,531.99
long27 Jul 2024 67,908.001 Aug 2024 64,628.005−$3,279.99
short1 Aug 2024 64,628.0010 Aug 2024 60,838.009$3,790.02
long10 Aug 2024 60,838.0031 Aug 2024 59,124.0021−$1,714.00
short31 Aug 2024 59,124.0012 Sep 2024 57,338.0012$1,785.99
long12 Sep 2024 57,338.002 Oct 2024 60,804.9020$3,466.92
short2 Oct 2024 60,804.9014 Oct 2024 62,870.0012−$2,065.10
long14 Oct 2024 62,870.0023 Oct 2024 67,426.009$4,555.99
short23 Oct 2024 67,426.0030 Oct 2024 72,736.407−$5,310.40
long30 Oct 2024 72,736.4027 Nov 2024 91,965.2028$19,228.80
short27 Nov 2024 91,965.205 Dec 2024 98,587.308−$6,622.16
long5 Dec 2024 98,587.3021 Dec 2024 97,805.4016−$781.88
short21 Dec 2024 97,805.405 Jan 2025 98,220.5015−$415.07
long5 Jan 2025 98,220.5010 Jan 2025 92,552.505−$5,668.02
short10 Jan 2025 92,552.5017 Jan 2025 99,987.307−$7,434.81
long17 Jan 2025 99,987.302 Feb 2025 100,636.0016$648.36
short2 Feb 2025 100,636.005 Mar 2025 87,282.0031$13,353.70
long5 Mar 2025 87,282.0010 Mar 2025 80,734.505−$6,547.50
short10 Mar 2025 80,734.5020 Mar 2025 86,845.9010−$6,111.45
long20 Mar 2025 86,845.9030 Mar 2025 82,648.5010−$4,197.40
short30 Mar 2025 82,648.5016 Apr 2025 83,644.0017−$995.46
long16 Apr 2025 83,644.0031 May 2025 103,985.0045$20,341.50
short31 May 2025 103,985.0010 Jun 2025 110,263.0010−$6,277.55
long10 Jun 2025 110,263.0019 Jun 2025 104,887.009−$5,376.23
short19 Jun 2025 104,887.0027 Jun 2025 106,947.008−$2,060.27
long27 Jun 2025 106,947.001 Aug 2025 115,764.0035$8,817.01
short1 Aug 2025 115,764.0011 Aug 2025 119,294.0010−$3,530.20
long11 Aug 2025 119,294.0020 Aug 2025 112,873.009−$6,421.32
short20 Aug 2025 112,873.009 Sep 2025 112,065.0020$807.72
long9 Sep 2025 112,065.0023 Sep 2025 112,651.0014$585.76
short23 Sep 2025 112,651.002 Oct 2025 118,595.009−$5,944.00
long2 Oct 2025 118,595.0010 Oct 2025 121,662.008$3,067.42
short10 Oct 2025 121,662.0026 Oct 2025 111,646.0016$10,016.10
long26 Oct 2025 111,646.004 Nov 2025 106,583.009−$5,063.22
short4 Nov 2025 106,583.0025 Nov 2025 88,300.0021$18,283.00
long25 Nov 2025 88,300.0016 Dec 2025 86,432.1021−$1,867.93
short16 Dec 2025 86,432.103 Jan 2026 89,995.1018−$3,563.06
long3 Jan 2026 89,995.1010 Jan 2026 90,641.307$646.13
short10 Jan 2026 90,641.3014 Jan 2026 95,414.004−$4,772.72
long14 Jan 2026 95,414.0021 Jan 2026 88,427.707−$6,986.33
short21 Jan 2026 88,427.708 Feb 2026 69,289.4018$19,138.30
long8 Feb 2026 69,289.4012 Feb 2026 67,082.504−$2,206.85
short12 Feb 2026 67,082.5015 Feb 2026 69,822.903−$2,740.42
long15 Feb 2026 69,822.9018 Feb 2026 67,503.503−$2,319.42
short18 Feb 2026 67,503.505 Mar 2026 72,666.8015−$5,163.25
long5 Mar 2026 72,666.8022 Mar 2026 68,918.1017−$3,748.65
short22 Mar 2026 68,918.107 Apr 2026 68,853.7016$64.46
long7 Apr 2026 68,853.7017 May 2026 78,148.1040$9,294.39
short17 May 2026 78,148.109 Jun 2026 63,086.0023$15,062.10
long9 Jun 2026 63,086.0011 Jun 2026 61,511.002−$1,575.01
short11 Jun 2026 61,511.0013 Jun 2026 63,580.002−$2,069.01
long13 Jun 2026 63,580.0024 Jun 2026 62,734.6011−$845.43
short24 Jun 2026 62,734.604 Jul 2026 62,583.3010$151.31
long4 Jul 2026 62,583.301 Aug 2026 62,887.9028$304.62
short1 Aug 2026 62,887.9010 Aug 2026 64,901.609−$2,013.71
long10 Aug 2026 64,901.6014 Aug 2026 63,490.904−$1,410.73
short14 Aug 2026 63,490.9020 Aug 2026 69,334.806−$5,843.92
long20 Aug 2026 69,334.8030 Aug 2026 78,230.0010$8,895.22
short30 Aug 2026 78,230.006 Sep 2026 79,831.807−$1,601.75
long6 Sep 2026 79,831.8013 Sep 2026 77,278.707−$2,553.02
short13 Sep 2026 77,278.7020 Sep 2026 81,250.007−$3,971.26
long20 Sep 2026 81,250.0010 Oct 2026 82,635.6020$1,385.57

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
Optimized Trend Tracker STRATEGY & SCREENER this page—v4 strategy+18.1%7725.6%
MACD ReLoaded STRATEGY by KivancOzbilgicema linreg wma smav5 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
DRSI DMA Scalping Strategy No Repaint by allenlksma wma emav4 strategy−99.5%44137.7%
Profit Maximizer PMax Strategy - Long-Short by melihtunasma ema linregv4 strategy+16.2%427.8%

Where it runs

EngineCompilesRunsMatches TradingView
Zeal Terminal · OpenPineScript v2Yes 70 msWith a workaround 1,000 bars in 459 msNot measured
PineTSNo v5 and v6 only—Not measured

The engine's host API cannot yet declare a chart's symbol and timeframe, so this page sets them on the engine directly for each market. Data the page supplies at the chart's own timeframe (another symbol, or Heikin-Ashi) reaches the script one bar later in Zeal Terminal's engine than on TradingView.

“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.

//@version=4// 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("Optimized Trend Tracker","OTTEx", overlay=true)src = input(close, title="Source")length=input(2, "OTT Period", minval=1)percent=input(1.4, "OTT Percent", type=input.float, step=0.1, minval=0)showsupport = input(title="Show Support Line?", type=input.bool, defval=true)showsignalsk = input(title="Show Support Line Crossing Signals?", type=input.bool, defval=true)showsignalsc = input(title="Show Price/OTT Crossing Signals?", type=input.bool, defval=false)highlight = input(title="Show OTT Color Changes?", type=input.bool, defval=false)showsignalsr = input(title="Show OTT Color Change Signals?", type=input.bool, defval=false)highlighting = input(title="Highlighter On/Off ?", type=input.bool, defval=true)mav = input(title="Moving Average Type", defval="VAR", options=["SMA", "EMA", "WMA", "TMA", "VAR", "WWMA", "ZLEMA", "TSF"])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=sum(vud1,9)    vDD=sum(vdd1,9)    vCMO=nz((vUD-vDD)/(vUD+vDD))    VAR=0.0    VAR:=nz(valpha*abs(vCMO)*src)+(1-valpha*abs(vCMO))*nz(VAR[1])VAR=Var_Func(src,length)Wwma_Func(src,length)=>    wwalpha = 1/ length    WWMA = 0.0    WWMA := wwalpha*src + (1-wwalpha)*nz(WWMA[1])WWMA=Wwma_Func(src,length)Zlema_Func(src,length)=>    zxLag = length/2==round(length/2) ? length/2 : (length - 1) / 2    zxEMAData = (src + (src - src[zxLag]))    ZLEMA = ema(zxEMAData, length)ZLEMA=Zlema_Func(src,length)Tsf_Func(src,length)=>    lrc = linreg(src, length, 0)    lrc1 = linreg(src,length,1)    lrs = (lrc-lrc1)    TSF = linreg(src, length, 0)+lrsTSF=Tsf_Func(src,length)getMA(src, length) =>    ma = 0.0    if mav == "SMA"        ma := sma(src, length)        ma    if mav == "EMA"        ma := ema(src, length)        ma    if mav == "WMA"        ma := wma(src, length)        ma    if mav == "TMA"        ma := sma(sma(src, ceil(length / 2)), 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    ma    MAvg=getMA(src, length)fark=MAvg*percent*0.01longStop = MAvg - farklongStopPrev = nz(longStop[1], longStop)longStop := MAvg > longStopPrev ? max(longStop, longStopPrev) : longStopshortStop =  MAvg + farkshortStopPrev = nz(shortStop[1], shortStop)shortStop := MAvg < shortStopPrev ? 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)/200 plot(showsupport ? MAvg : 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)alertcondition(cross(OTT[2], OTT[3]), title="Color ALARM", message="OTT Has Changed Color!")alertcondition(crossover(OTT[2], OTT[3]), title="GREEN ALERT", message="OTT GREEN BUY SIGNAL!")alertcondition(crossunder(OTT[2], OTT[3]), title="RED ALERT", message="OTT RED SELL SIGNAL!")alertcondition(cross(MAvg, OTT[2]), title="Cross Alert", message="OTT - Support Line Crossing!")alertcondition(crossover(MAvg, OTT[2]), title="Crossover Alarm", message="Support Line BUY SIGNAL!")alertcondition(crossunder(MAvg, OTT[2]), title="Crossunder Alarm", message="Support Line SELL SIGNAL!")alertcondition(cross(src, OTT[2]), title="Price Cross Alert", message="OTT - Price Crossing!")alertcondition(crossover(src, OTT[2]), title="Price Crossover Alarm", message="PRICE OVER OTT - BUY SIGNAL!")alertcondition(crossunder(src, OTT[2]), title="Price Crossunder Alarm", message="PRICE UNDER OTT - SELL SIGNAL!")buySignalk = crossover(MAvg, OTT[2])plotshape(buySignalk and showsignalsk ? OTT*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)sellSignallk = crossunder(MAvg, OTT[2])plotshape(sellSignallk and showsignalsk ? OTT*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)buySignalc = crossover(src, OTT[2])plotshape(buySignalc and showsignalsc ? OTT*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)sellSignallc = crossunder(src, OTT[2])plotshape(sellSignallc and showsignalsc ? OTT*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)mPlot = plot(ohlc4, title="", style=plot.style_circles, linewidth=0,display=display.none)longFillColor = highlighting ? (MAvg>OTT ? color.green : na) : nashortFillColor = highlighting ? (MAvg<OTT ? color.red : na) : nafill(mPlot, pALL, title="UpTrend Highligter", color=longFillColor)fill(mPlot, pALL, title="DownTrend Highligter", color=shortFillColor)buySignalr = crossover(OTT[2], OTT[3])plotshape(buySignalr and showsignalsr ? OTT*0.995 : na, title="Buy", text="Buy", location=location.absolute, style=shape.labelup, size=size.tiny, color=color.green, textcolor=color.white, transp=0)sellSignallr = crossunder(OTT[2], OTT[3])plotshape(sellSignallr and showsignalsr ? OTT*1.005 : na, title="Sell", text="Sell", location=location.absolute, style=shape.labeldown, size=size.tiny, color=color.red, textcolor=color.white, transp=0)showscr = input(true, title="Show Screener Label")posX_scr = input(20, title="Pos. Label x-axis")posY_scr = input(1, title="Pos. Size Label y-axis")colinput = input(title="Label Color", defval="Blue", options=["White", "Black", "Red", "Green", "Yellow", "Blue"])col = color.grayif colinput=="White"    col:=color.whiteif colinput=="Black"    col:=color.blackif colinput=="Red"    col:=color.redif colinput=="Green"    col:=color.greenif colinput=="Yellow"    col:=color.yellowif colinput=="Blue"    col:=color.bluedummy0 = input(true, title = "=Backtest Inputs=")FromDay    = input(defval = 1, title = "From Day", minval = 1, maxval = 31)FromMonth  = input(defval = 1, title = "From Month", minval = 1, maxval = 12)FromYear   = input(defval = 2005, title = "From Year", minval = 2005)ToDay      = input(defval = 1, title = "To Day", minval = 1, maxval = 31)ToMonth    = input(defval = 1, title = "To Month", minval = 1, maxval = 12)ToYear     = input(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 sellSignallk    strategy.entry("Short", strategy.short,when=Timerange())t1=input('EURUSD',   title='Symbol 01',type=input.symbol)t2=input('XAUUSD',    title='Symbol 02',type=input.symbol)t3=input('AMZN',    title='Symbol 03',type=input.symbol)t4=input('TSLA',    title='Symbol 04',type=input.symbol)t5=input('BTCUSDT',    title='Symbol 05',type=input.symbol)t6=input('ETHBTC',    title='Symbol 06',type=input.symbol)t7=input('XBTUSD',    title='Symbol 07',type=input.symbol)t8=input('XRPBTC',    title='Symbol 08',type=input.symbol)t9=input('THYAO',   title='Symbol 09',type=input.symbol)t10=input('GARAN',    title='Symbol 10',type=input.symbol)t11=input('',      title='Symbol 11',type=input.symbol)t12=input('',      title='Symbol 12',type=input.symbol)t13=input('',      title='Symbol 13',type=input.symbol)t14=input('',      title='Symbol 14',type=input.symbol)t15=input('',      title='Symbol 15',type=input.symbol)t16=input('',     title='Symbol 16',type=input.symbol)t17=input('',    title='Symbol 17',type=input.symbol)t18=input('',    title='Symbol 18',type=input.symbol)t19=input('',    title='Symbol 19',type=input.symbol)t20=input('',    title='Symbol 20',type=input.symbol)OTTs(percent, length) =>    Up=MAvg-MAvg*percent*0.01    Dn=MAvg+MAvg*percent*0.01        TrendUp = 0.0    TrendUp := MAvg[1]>TrendUp[1] ? max(Up,TrendUp[1]) : Up    TrendDown = 0.0    TrendDown := MAvg[1]<TrendDown[1]? min(Dn,TrendDown[1]) : Dn    Trend = 0.0    Trend := MAvg > TrendDown[1] ? 1: MAvg< TrendUp[1]? -1: nz(Trend[1],1)    Tsl = Trend==1? TrendUp: TrendDown        S_Buy = Trend == 1 ? 1 : 0    S_Sell = Trend != 1 ? 1 : 0        [Trend, Tsl][Trend, Tsl] =  OTTs(percent, length)TrendReversal = Trend != Trend[1][t01, s01] = security(t1, timeframe.period, OTTs(percent, length))[t02, s02] = security(t2, timeframe.period, OTTs(percent, length))[t03, s03] = security(t3, timeframe.period, OTTs(percent, length))[t04, s04] = security(t4, timeframe.period, OTTs(percent, length))[t05, s05] = security(t5, timeframe.period, OTTs(percent, length))[t06, s06] = security(t6, timeframe.period, OTTs(percent, length))[t07, s07] = security(t7, timeframe.period, OTTs(percent, length))[t08, s08] = security(t8, timeframe.period, OTTs(percent, length))[t09, s09] = security(t9, timeframe.period, OTTs(percent, length))[t010, s010] = security(t10, timeframe.period, OTTs(percent, length))[t011, s011] = security(t11, timeframe.period, OTTs(percent, length))[t012, s012] = security(t12, timeframe.period, OTTs(percent, length))[t013, s013] = security(t13, timeframe.period, OTTs(percent, length))[t014, s014] = security(t14, timeframe.period, OTTs(percent, length))[t015, s015] = security(t15, timeframe.period, OTTs(percent, length))[t016, s016] = security(t16, timeframe.period, OTTs(percent, length))[t017, s017] = security(t17, timeframe.period, OTTs(percent, length))[t018, s018] = security(t18, timeframe.period, OTTs(percent, length))[t019, s019] = security(t19, timeframe.period, OTTs(percent, length))[t020, s020] = security(t20, timeframe.period, OTTs(percent, length))tr01 = t01 != t01[1], up01 = t01 == 1, dn01 = t01 == -1tr02 = t02 != t02[1], up02 = t02 == 1, dn02 = t02 == -1tr03 = t03 != t03[1], up03 = t03 == 1, dn03 = t03 == -1tr04 = t04 != t04[1], up04 = t04 == 1, dn04 = t04 == -1tr05 = t05 != t05[1], up05 = t05 == 1, dn05 = t05 == -1tr06 = t06 != t06[1], up06 = t06 == 1, dn06 = t06 == -1tr07 = t07 != t07[1], up07 = t07 == 1, dn07 = t07 == -1tr08 = t08 != t08[1], up08 = t08 == 1, dn08 = t08 == -1tr09 = t09 != t09[1], up09 = t09 == 1, dn09 = t09 == -1tr010 = t010 != t010[1], up010 = t010 == 1, dn010 = t010 == -1tr011 = t011 != t011[1], up011 = t011 == 1, dn011 = t011 == -1tr012 = t012 != t012[1], up012 = t012 == 1, dn012 = t012 == -1tr013 = t013 != t013[1], up013 = t013 == 1, dn013 = t013 == -1tr014 = t014 != t014[1], up014 = t014 == 1, dn014 = t014 == -1tr015 = t015 != t015[1], up015 = t015 == 1, dn015 = t015 == -1tr016 = t016 != t016[1], up016 = t016 == 1, dn016 = t016 == -1tr017 = t017 != t017[1], up017 = t017 == 1, dn017 = t017 == -1tr018 = t018 != t018[1], up018 = t018 == 1, dn018 = t018 == -1tr019 = t019 != t019[1], up019 = t019 == 1, dn019 = t019 == -1tr020 = t020 != t020[1], up020 = t020 == 1, dn020 = t020 == -1pot_label = 'Potential Reversal: \n'pot_label := tr01    ? pot_label + t1 + '\n'  : pot_labelpot_label := tr02    ? pot_label + t2 + '\n'  : pot_labelpot_label := tr03    ? pot_label + t3 + '\n'  : pot_labelpot_label := tr04    ? pot_label + t4 + '\n'  : pot_labelpot_label := tr05    ? pot_label + t5 + '\n'  : pot_labelpot_label := tr06    ? pot_label + t6 + '\n'  : pot_labelpot_label := tr07    ? pot_label + t7 + '\n'  : pot_labelpot_label := tr08    ? pot_label + t8 + '\n'  : pot_labelpot_label := tr09    ? pot_label + t9 + '\n'  : pot_labelpot_label := tr010    ? pot_label + t10 + '\n'  : pot_labelpot_label := tr011    ? pot_label + t11 + '\n'  : pot_labelpot_label := tr012    ? pot_label + t12 + '\n'  : pot_labelpot_label := tr013    ? pot_label + t13 + '\n'  : pot_labelpot_label := tr014    ? pot_label + t14 + '\n'  : pot_labelpot_label := tr015    ? pot_label + t15 + '\n'  : pot_labelpot_label := tr016    ? pot_label + t16 + '\n'  : pot_labelpot_label := tr017    ? pot_label + t17 + '\n'  : pot_labelpot_label := tr018    ? pot_label + t18 + '\n'  : pot_labelpot_label := tr019    ? pot_label + t19 + '\n'  : pot_labelpot_label := tr020    ? pot_label + t20 + '\n'  : pot_labelscr_label = 'Confirmed Reversal: \n'scr_label := tr01[1] ? scr_label + t1 + '\n'  : scr_labelscr_label := tr02[1] ? scr_label + t2 + '\n'  : scr_labelscr_label := tr03[1] ? scr_label + t3 + '\n'  : scr_labelscr_label := tr04[1] ? scr_label + t4 + '\n'  : scr_labelscr_label := tr05[1] ? scr_label + t5 + '\n'  : scr_labelscr_label := tr06[1] ? scr_label + t6 + '\n'  : scr_labelscr_label := tr07[1] ? scr_label + t7 + '\n'  : scr_labelscr_label := tr08[1] ? scr_label + t8 + '\n'  : scr_labelscr_label := tr09[1] ? scr_label + t9 + '\n'  : scr_labelscr_label := tr010[1] ? scr_label + t10 + '\n'  : scr_labelscr_label := tr011[1] ? scr_label + t11 + '\n'  : scr_labelscr_label := tr012[1] ? scr_label + t12 + '\n'  : scr_labelscr_label := tr013[1] ? scr_label + t13 + '\n'  : scr_labelscr_label := tr014[1] ? scr_label + t14 + '\n'  : scr_labelscr_label := tr015[1] ? scr_label + t15 + '\n'  : scr_labelscr_label := tr016[1] ? scr_label + t16 + '\n'  : scr_labelscr_label := tr017[1] ? scr_label + t17 + '\n'  : scr_labelscr_label := tr018[1] ? scr_label + t18 + '\n'  : scr_labelscr_label := tr019[1] ? scr_label + t19 + '\n'  : scr_labelscr_label := tr020[1] ? scr_label + t20 + '\n'  : scr_labelup_label = 'Uptrend: \n'up_label := up01[1] ? up_label + t1 + '\n'  : up_labelup_label := up02[1] ? up_label + t2 + '\n'  : up_labelup_label := up03[1] ? up_label + t3 + '\n'  : up_labelup_label := up04[1] ? up_label + t4 + '\n'  : up_labelup_label := up05[1] ? up_label + t5 + '\n'  : up_labelup_label := up06[1] ? up_label + t6 + '\n'  : up_labelup_label := up07[1] ? up_label + t7 + '\n'  : up_labelup_label := up08[1] ? up_label + t8 + '\n'  : up_labelup_label := up09[1] ? up_label + t9 + '\n'  : up_labelup_label := up010[1] ? up_label + t10 + '\n'  : up_labelup_label := up011[1] ? up_label + t11 + '\n'  : up_labelup_label := up012[1] ? up_label + t12 + '\n'  : up_labelup_label := up013[1] ? up_label + t13 + '\n'  : up_labelup_label := up014[1] ? up_label + t14 + '\n'  : up_labelup_label := up015[1] ? up_label + t15 + '\n'  : up_labelup_label := up016[1] ? up_label + t16 + '\n'  : up_labelup_label := up017[1] ? up_label + t17 + '\n'  : up_labelup_label := up018[1] ? up_label + t18 + '\n'  : up_labelup_label := up019[1] ? up_label + t19 + '\n'  : up_labelup_label := up020[1] ? up_label + t20 + '\n'  : up_labeldn_label = 'Downtrend: \n'dn_label := dn01[1] ? dn_label + t1 + '\n'  : dn_labeldn_label := dn02[1] ? dn_label + t2 + '\n'  : dn_labeldn_label := dn03[1] ? dn_label + t3 + '\n'  : dn_labeldn_label := dn04[1] ? dn_label + t4 + '\n'  : dn_labeldn_label := dn05[1] ? dn_label + t5 + '\n'  : dn_labeldn_label := dn06[1] ? dn_label + t6 + '\n'  : dn_labeldn_label := dn07[1] ? dn_label + t7 + '\n'  : dn_labeldn_label := dn08[1] ? dn_label + t8 + '\n'  : dn_labeldn_label := dn09[1] ? dn_label + t9 + '\n'  : dn_labeldn_label := dn010[1] ? dn_label + t10 + '\n'  : dn_labeldn_label := dn011[1] ? dn_label + t11 + '\n'  : dn_labeldn_label := dn012[1] ? dn_label + t12 + '\n'  : dn_labeldn_label := dn013[1] ? dn_label + t13 + '\n'  : dn_labeldn_label := dn014[1] ? dn_label + t14 + '\n'  : dn_labeldn_label := dn015[1] ? dn_label + t15 + '\n'  : dn_labeldn_label := dn016[1] ? dn_label + t16 + '\n'  : dn_labeldn_label := dn017[1] ? dn_label + t17 + '\n'  : dn_labeldn_label := dn018[1] ? dn_label + t18 + '\n'  : dn_labeldn_label := dn019[1] ? dn_label + t19 + '\n'  : dn_labeldn_label := dn020[1] ? dn_label + t20 + '\n'  : dn_labelf_colorscr (_valscr ) =>      _valscr  ? #00000000 : na     f_printscr (_txtscr ) =>      var _lblscr  = label(na),      label.delete(_lblscr ),      _lblscr  := label.new(     time + (time-time[1])*posX_scr ,      ohlc4[posY_scr],      _txtscr ,     xloc.bar_time,      yloc.price,      f_colorscr (  showscr ),     textcolor =  showscr ? col : na,      size = size.normal,      style=label.style_label_center     )f_printscr ( scr_label + '\n' + pot_label +'\n' + up_label + '\n' + dn_label)