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
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
VerifiedSame 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⋯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.
| Setting | Default | Type and range | Feeds |
|---|---|---|---|
| Source | close | source | vud1 vdd1 VAR WWMA zxEMAData ZLEMA lrc lrc1 TSF ma MAvg buySignalc sellSignallc Price Cross Alert Price Crossover Alarm Price Crossunder Alarm |
| OTT Period | 2 | int · min 1 | valpha 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 Percent | 1.4 | float · min 0 · step 0.1 | fark 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? | true | bool | Support Line |
| Show Support Line Crossing Signals? | true | bool | Buy Sell |
| Show Price/OTT Crossing Signals? | false | bool | Buy Sell |
| Show OTT Color Changes? | false | bool | OTTC |
| Show OTT Color Change Signals? | false | bool | Buy Sell |
| Highlighter On/Off ? | true | bool | longFillColor shortFillColor |
| Moving Average Type | VAR | string · 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 Label | true | bool | _lblscr |
| Pos. Label x-axis | 20 | int | _lblscr |
| Pos. Size Label y-axis | 1 | int | _lblscr |
| Label Color | Blue | string · options ["White", "Black", "Red", "Green", "Yellow", "Blue"] | line 119 line 121 line 123 line 125 line 127 line 129 |
| =Backtest Inputs= | true | bool | unused |
| From Day | 1 | int · min 1 · max 31 | Start |
| From Month | 1 | int · min 1 · max 12 | Start |
| From Year | 2005 | int · min 2005 | Start |
| To Day | 1 | int · min 1 · max 31 | Finish |
| To Month | 1 | int · min 1 · max 12 | Finish |
| To Year | 9999 | int · min 2006 | Finish |
| Symbol 01 | EURUSD | symbol | t01 s01 pot_label scr_label up_label dn_label |
| Symbol 02 | XAUUSD | symbol | t02 s02 pot_label scr_label up_label dn_label |
| Symbol 03 | AMZN | symbol | t03 s03 pot_label scr_label up_label dn_label |
| Symbol 04 | TSLA | symbol | t04 s04 pot_label scr_label up_label dn_label |
| Symbol 05 | BTCUSDT | symbol | t05 s05 pot_label scr_label up_label dn_label |
| Symbol 06 | ETHBTC | symbol | t06 s06 pot_label scr_label up_label dn_label |
| Symbol 07 | XBTUSD | symbol | t07 s07 pot_label scr_label up_label dn_label |
| Symbol 08 | XRPBTC | symbol | t08 s08 pot_label scr_label up_label dn_label |
| Symbol 09 | THYAO | symbol | t09 s09 pot_label scr_label up_label dn_label |
| Symbol 10 | GARAN | symbol | t010 s010 pot_label scr_label up_label dn_label |
| Symbol 11 | | symbol | t011 s011 pot_label scr_label up_label dn_label |
| Symbol 12 | | symbol | t012 s012 pot_label scr_label up_label dn_label |
| Symbol 13 | | symbol | t013 s013 pot_label scr_label up_label dn_label |
| Symbol 14 | | symbol | t014 s014 pot_label scr_label up_label dn_label |
| Symbol 15 | | symbol | t015 s015 pot_label scr_label up_label dn_label |
| Symbol 16 | | symbol | t016 s016 pot_label scr_label up_label dn_label |
| Symbol 17 | | symbol | t017 s017 pot_label scr_label up_label dn_label |
| Symbol 18 | | symbol | t018 s018 pot_label scr_label up_label dn_label |
| Symbol 19 | | symbol | t019 s019 pot_label scr_label up_label dn_label |
| Symbol 20 | | symbol | t020 s020 pot_label scr_label up_label dn_label |
What it calculates
- Linreg (
linreg,ta.linregin v5)Source (close), OTT Period (2), 0lrc · line 39 - Linreg (
linreg,ta.linregin v5)Source (close), OTT Period (2), 1lrc1 · line 40 - SMA / EMA / WMA (
sma,ta.smain v5)Source (close), OTT Period (2)ma · line 47 - Crossover (
crossover,ta.crossoverin v5)MAvg, OTT[2]buySignalk · line 97 - Crossunder (
crossunder,ta.crossunderin v5)MAvg, OTT[2]sellSignallk · line 99 - Crossover (
crossover,ta.crossoverin v5)Source (close), OTT[2]buySignalc · line 101 - Crossunder (
crossunder,ta.crossunderin v5)Source (close), OTT[2]sellSignallc · line 103 - Crossover (
crossover,ta.crossoverin v5)OTT[2], OTT[3]buySignalr · line 110 - Crossunder (
crossunder,ta.crossunderin 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
| Order | Fires when | By default | Line |
|---|---|---|---|
| Open Long long | Timerange() | On | 143 |
| Open Short short | Timerange() | On | 145 |
Each order is guarded by the setting shown. “Off” orders never fire unless that setting is switched on.
Alerts
| Alert | Call | Message | Line |
|---|---|---|---|
| Color ALARM | alertcondition | OTT Has Changed Color! | 88 |
| GREEN ALERT | alertcondition | OTT GREEN BUY SIGNAL! | 89 |
| RED ALERT | alertcondition | OTT RED SELL SIGNAL! | 90 |
| Cross Alert | alertcondition | OTT - Support Line Crossing! | 91 |
| Crossover Alarm | alertcondition | Support Line BUY SIGNAL! | 92 |
| Crossunder Alarm | alertcondition | Support Line SELL SIGNAL! | 93 |
| Price Cross Alert | alertcondition | OTT - Price Crossing! | 94 |
| Price Crossover Alarm | alertcondition | PRICE OVER OTT - BUY SIGNAL! | 95 |
| Price Crossunder Alarm | alertcondition | PRICE UNDER OTT - SELL SIGNAL! | 96 |
Does it repaint?
No
No repainting patterns in the source, and the live replay matched history.
- 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 bars | Trades | Won | P&L |
|---|---|---|---|
| Rising market | 24 | 25% | −$27,993.60 |
| Sideways market | 36 | 47% | $38,325.90 |
| Falling market | 17 | 29% | $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.
All 77 trades
| Side | Entry | Exit | Bars | P&L |
|---|---|---|---|---|
| long | 4 Feb 2024 43,011.10 | 24 Feb 2024 50,744.20 | 20 | $7,733.05 |
| short | 24 Feb 2024 50,744.20 | 27 Feb 2024 54,476.50 | 3 | −$3,732.33 |
| long | 27 Feb 2024 54,476.50 | 17 Mar 2024 65,300.60 | 19 | $10,824.20 |
| short | 17 Mar 2024 65,300.60 | 27 Mar 2024 69,988.00 | 10 | −$4,687.35 |
| long | 27 Mar 2024 69,988.00 | 4 Apr 2024 65,963.30 | 8 | −$4,024.72 |
| short | 4 Apr 2024 65,963.30 | 12 Apr 2024 70,006.20 | 8 | −$4,042.95 |
| long | 12 Apr 2024 70,006.20 | 14 Apr 2024 63,924.50 | 2 | −$6,081.70 |
| short | 14 Apr 2024 63,924.50 | 23 Apr 2024 66,819.30 | 9 | −$2,894.80 |
| long | 23 Apr 2024 66,819.30 | 29 Apr 2024 63,118.60 | 6 | −$3,700.70 |
| short | 29 Apr 2024 63,118.60 | 7 May 2024 63,165.20 | 8 | −$46.56 |
| long | 7 May 2024 63,165.20 | 2 Jun 2024 67,766.80 | 26 | $4,601.66 |
| short | 2 Jun 2024 67,766.80 | 5 Jun 2024 70,537.80 | 3 | −$2,770.99 |
| long | 5 Jun 2024 70,537.80 | 14 Jun 2024 66,773.00 | 9 | −$3,764.82 |
| short | 14 Jun 2024 66,773.00 | 15 Jul 2024 60,797.90 | 31 | $5,975.10 |
| long | 15 Jul 2024 60,797.90 | 25 Jul 2024 65,376.00 | 10 | $4,578.10 |
| short | 25 Jul 2024 65,376.00 | 27 Jul 2024 67,908.00 | 2 | −$2,531.99 |
| long | 27 Jul 2024 67,908.00 | 1 Aug 2024 64,628.00 | 5 | −$3,279.99 |
| short | 1 Aug 2024 64,628.00 | 10 Aug 2024 60,838.00 | 9 | $3,790.02 |
| long | 10 Aug 2024 60,838.00 | 31 Aug 2024 59,124.00 | 21 | −$1,714.00 |
| short | 31 Aug 2024 59,124.00 | 12 Sep 2024 57,338.00 | 12 | $1,785.99 |
| long | 12 Sep 2024 57,338.00 | 2 Oct 2024 60,804.90 | 20 | $3,466.92 |
| short | 2 Oct 2024 60,804.90 | 14 Oct 2024 62,870.00 | 12 | −$2,065.10 |
| long | 14 Oct 2024 62,870.00 | 23 Oct 2024 67,426.00 | 9 | $4,555.99 |
| short | 23 Oct 2024 67,426.00 | 30 Oct 2024 72,736.40 | 7 | −$5,310.40 |
| long | 30 Oct 2024 72,736.40 | 27 Nov 2024 91,965.20 | 28 | $19,228.80 |
| short | 27 Nov 2024 91,965.20 | 5 Dec 2024 98,587.30 | 8 | −$6,622.16 |
| long | 5 Dec 2024 98,587.30 | 21 Dec 2024 97,805.40 | 16 | −$781.88 |
| short | 21 Dec 2024 97,805.40 | 5 Jan 2025 98,220.50 | 15 | −$415.07 |
| long | 5 Jan 2025 98,220.50 | 10 Jan 2025 92,552.50 | 5 | −$5,668.02 |
| short | 10 Jan 2025 92,552.50 | 17 Jan 2025 99,987.30 | 7 | −$7,434.81 |
| long | 17 Jan 2025 99,987.30 | 2 Feb 2025 100,636.00 | 16 | $648.36 |
| short | 2 Feb 2025 100,636.00 | 5 Mar 2025 87,282.00 | 31 | $13,353.70 |
| long | 5 Mar 2025 87,282.00 | 10 Mar 2025 80,734.50 | 5 | −$6,547.50 |
| short | 10 Mar 2025 80,734.50 | 20 Mar 2025 86,845.90 | 10 | −$6,111.45 |
| long | 20 Mar 2025 86,845.90 | 30 Mar 2025 82,648.50 | 10 | −$4,197.40 |
| short | 30 Mar 2025 82,648.50 | 16 Apr 2025 83,644.00 | 17 | −$995.46 |
| long | 16 Apr 2025 83,644.00 | 31 May 2025 103,985.00 | 45 | $20,341.50 |
| short | 31 May 2025 103,985.00 | 10 Jun 2025 110,263.00 | 10 | −$6,277.55 |
| long | 10 Jun 2025 110,263.00 | 19 Jun 2025 104,887.00 | 9 | −$5,376.23 |
| short | 19 Jun 2025 104,887.00 | 27 Jun 2025 106,947.00 | 8 | −$2,060.27 |
| long | 27 Jun 2025 106,947.00 | 1 Aug 2025 115,764.00 | 35 | $8,817.01 |
| short | 1 Aug 2025 115,764.00 | 11 Aug 2025 119,294.00 | 10 | −$3,530.20 |
| long | 11 Aug 2025 119,294.00 | 20 Aug 2025 112,873.00 | 9 | −$6,421.32 |
| short | 20 Aug 2025 112,873.00 | 9 Sep 2025 112,065.00 | 20 | $807.72 |
| long | 9 Sep 2025 112,065.00 | 23 Sep 2025 112,651.00 | 14 | $585.76 |
| short | 23 Sep 2025 112,651.00 | 2 Oct 2025 118,595.00 | 9 | −$5,944.00 |
| long | 2 Oct 2025 118,595.00 | 10 Oct 2025 121,662.00 | 8 | $3,067.42 |
| short | 10 Oct 2025 121,662.00 | 26 Oct 2025 111,646.00 | 16 | $10,016.10 |
| long | 26 Oct 2025 111,646.00 | 4 Nov 2025 106,583.00 | 9 | −$5,063.22 |
| short | 4 Nov 2025 106,583.00 | 25 Nov 2025 88,300.00 | 21 | $18,283.00 |
| long | 25 Nov 2025 88,300.00 | 16 Dec 2025 86,432.10 | 21 | −$1,867.93 |
| short | 16 Dec 2025 86,432.10 | 3 Jan 2026 89,995.10 | 18 | −$3,563.06 |
| long | 3 Jan 2026 89,995.10 | 10 Jan 2026 90,641.30 | 7 | $646.13 |
| short | 10 Jan 2026 90,641.30 | 14 Jan 2026 95,414.00 | 4 | −$4,772.72 |
| long | 14 Jan 2026 95,414.00 | 21 Jan 2026 88,427.70 | 7 | −$6,986.33 |
| short | 21 Jan 2026 88,427.70 | 8 Feb 2026 69,289.40 | 18 | $19,138.30 |
| long | 8 Feb 2026 69,289.40 | 12 Feb 2026 67,082.50 | 4 | −$2,206.85 |
| short | 12 Feb 2026 67,082.50 | 15 Feb 2026 69,822.90 | 3 | −$2,740.42 |
| long | 15 Feb 2026 69,822.90 | 18 Feb 2026 67,503.50 | 3 | −$2,319.42 |
| short | 18 Feb 2026 67,503.50 | 5 Mar 2026 72,666.80 | 15 | −$5,163.25 |
| long | 5 Mar 2026 72,666.80 | 22 Mar 2026 68,918.10 | 17 | −$3,748.65 |
| short | 22 Mar 2026 68,918.10 | 7 Apr 2026 68,853.70 | 16 | $64.46 |
| long | 7 Apr 2026 68,853.70 | 17 May 2026 78,148.10 | 40 | $9,294.39 |
| short | 17 May 2026 78,148.10 | 9 Jun 2026 63,086.00 | 23 | $15,062.10 |
| long | 9 Jun 2026 63,086.00 | 11 Jun 2026 61,511.00 | 2 | −$1,575.01 |
| short | 11 Jun 2026 61,511.00 | 13 Jun 2026 63,580.00 | 2 | −$2,069.01 |
| long | 13 Jun 2026 63,580.00 | 24 Jun 2026 62,734.60 | 11 | −$845.43 |
| short | 24 Jun 2026 62,734.60 | 4 Jul 2026 62,583.30 | 10 | $151.31 |
| long | 4 Jul 2026 62,583.30 | 1 Aug 2026 62,887.90 | 28 | $304.62 |
| short | 1 Aug 2026 62,887.90 | 10 Aug 2026 64,901.60 | 9 | −$2,013.71 |
| long | 10 Aug 2026 64,901.60 | 14 Aug 2026 63,490.90 | 4 | −$1,410.73 |
| short | 14 Aug 2026 63,490.90 | 20 Aug 2026 69,334.80 | 6 | −$5,843.92 |
| long | 20 Aug 2026 69,334.80 | 30 Aug 2026 78,230.00 | 10 | $8,895.22 |
| short | 30 Aug 2026 78,230.00 | 6 Sep 2026 79,831.80 | 7 | −$1,601.75 |
| long | 6 Sep 2026 79,831.80 | 13 Sep 2026 77,278.70 | 7 | −$2,553.02 |
| short | 13 Sep 2026 77,278.70 | 20 Sep 2026 81,250.00 | 7 | −$3,971.26 |
| long | 20 Sep 2026 81,250.00 | 10 Oct 2026 82,635.60 | 20 | $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.
| Script | Shares | Type | Net | Trades | Max drawdown |
|---|---|---|---|---|---|
| Optimized Trend Tracker STRATEGY & SCREENER this page | — | v4 strategy | +18.1% | 77 | 25.6% |
| MACD ReLoaded STRATEGY by KivancOzbilgic | ema linreg wma sma | v5 strategy | +7.8% | 31 | 5.1% |
| Linear Regression MA - Strategy by lazy_capitalist | sma linreg ema | v5 strategy | −1,240.4% | 10 | 318.7% |
| Forex SWING Trader by SoftKill21 | wma ema sma | v4 strategy | No trades on this market | ||
| DRSI DMA Scalping Strategy No Repaint by allenlk | sma wma ema | v4 strategy | −99.5% | 44 | 137.7% |
| Profit Maximizer PMax Strategy - Long-Short by melihtuna | sma ema linreg | v4 strategy | +16.2% | 4 | 27.8% |
Where it runs
| Engine | Compiles | Runs | Matches TradingView |
|---|---|---|---|
| Zeal Terminal · OpenPineScript v2 | Yes 70 ms | With a workaround 1,000 bars in 459 ms | Not measured |
| PineTS | No 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)