Optimized Trend Tracker Bands
"Optimized Trend Tracker Bands" by KivancOzbilgic, MPL-2.0. Ported to FloScript by FloSignals; modifications under MPL-2.0. Original: Optimized Trend Tracker Bands (v2.0), read 2026-10-12T16:04:45.671Z; source language v4.
Licence: Mozilla Public License 2.0 (MPL-2.0) — full text. The source is published with it, modifications included, under the same licence.
Optimized Trend Tracker Bands by KivancOzbilgic, ported from Pine v4. Overlay indicator with 8 plots, 8 fills and 9 inputs.
// 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: @kivancozbilgic
// ------------------------------------------------------------------------------------------------
// Original author: KivancOzbilgic
// Original title: Optimized Trend Tracker Bands
// Licence: MPL-2.0 (the header above is the original notice, kept verbatim)
// Pine version: 4
// Fetched: 2026-10-12
// Ported to FloScript by FloSignals; modifications under MPL-2.0.
// Converter: @flosignals/floscript 0.1.0, strict mode, score 100/100
// ------------------------------------------------------------------------------------------------
//@floscript=1
//@version=5
// Converted by the FloScript converter from a Pine-compatible v4 source.
indicator("Optimized Trend Tracker Bands", "OTT Bands", overlay=true, format=format.price, precision=2, timeframe="")
src = input(close, title="Source")
length = input.int(2, "OTT Moving Average Length", minval=1)
percent = input.float(15, "OTT Optimization Coeff", step=0.1, minval=0)
X3 = input.float(0.1, "OTT UPPER BAND Optimization Coeff", step=0.001, minval=0)
X5 = input.float(0.077, "OTT LOWER BAND Optimization Coeff", step=0.001, minval=0)
showfibolines = input.bool(title="Show OTT Bands Fibonacci Levels?", defval=false)
showsupport = input.bool(title="Show Support Line?", defval=false)
highlight = input.bool(title="Show OTT Support Line Color Changes?", defval=false)
mav = input.string(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 = math.sum(vud1, 9)
vDD = math.sum(vdd1, 9)
vCMO = nz((vUD - vDD) / (vUD + vDD))
VAR = 0.0
VAR := nz(valpha * math.abs(vCMO) * src) + (1 - valpha * math.abs(vCMO)) * nz(VAR[1])
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 == math.round(length / 2) ? length / 2 : (length - 1) / 2
zxEMAData = src + (src - src[zxLag])
ZLEMA = ta.ema(zxEMAData, length)
ZLEMA = Zlema_Func(src, length)
Tsf_Func(src, length) =>
lrc = ta.linreg(src, length, 0)
lrc1 = ta.linreg(src, length, 1)
lrs = lrc - lrc1
TSF = ta.linreg(src, length, 0) + lrs
TSF = Tsf_Func(src, length)
getMA(src, length) =>
ma = 0.0
if mav == "SMA"
ma := ta.sma(src, length)
ma
if mav == "EMA"
ma := ta.ema(src, length)
ma
if mav == "WMA"
ma := ta.wma(src, length)
ma
if mav == "TMA"
ma := ta.sma(ta.sma(src, math.ceil(length / 2)), math.floor(length / 2) + 1)
ma
if mav == "VAR"
ma := VAR
ma
if mav == "WWMA"
ma := WWMA
ma
if mav == "ZLEMA"
ma := ZLEMA
ma
if mav == "TSF"
ma := TSF
ma
ma
MAvg = getMA(src, length)
fark = MAvg * percent * 0.01
longStop = MAvg - fark
longStopPrev = nz(longStop[1], longStop)
longStop := MAvg > longStopPrev ? math.max(longStop, longStopPrev) : longStop
shortStop = MAvg + fark
shortStopPrev = nz(shortStop[1], shortStop)
shortStop := MAvg < shortStopPrev ? math.min(shortStop, shortStopPrev) : shortStop
dir = 1
dir := nz(dir[1], dir)
dir := dir == -1 and MAvg > shortStopPrev ? 1 : dir == 1 and MAvg < longStopPrev ? -1 : dir
MT = dir == 1 ? longStop : shortStop
OTT = MAvg > MT ? MT * (200 + percent) / 200 : MT * (200 - percent) / 200
OTTC = highlight ? (MAvg > MAvg[1] ? color.green : color.red) : #0585E1
OTTMAIN = plot(nz(OTT[2]), color=color.new(#B800D9, 0), linewidth=2, title="OTT")
plot(showsupport ? MAvg : na, color=OTTC, linewidth=2, title="Support Line")
OTTUST = plot(nz(OTT[2]) * (1 + X3), color=color.new(#4500C4, 0), linewidth=2, title="OTT UPPER")
OTTUSTYARI = plot(showfibolines ? nz(OTT[2]) * (1 + X3 * 0.618) : nz(OTT[2]) * (1 + X3 / 2), color=color.new(#8400FF, 0), linewidth=1, title="OTT UPPER HALF ")
OTTFIBOUST2 = plot(showfibolines ? nz(OTT[2]) * (1 + X3 * 0.382) : na, color=color.new(#C830FF, 0), linewidth=1, title="OTT UPPER HALF ")
OTTALT = plot(nz(OTT[2]) * (1 - X5), color=color.new(#00A6FF, 0), linewidth=2, title="OTT LOWER")
OTTALTYARI = plot(showfibolines ? nz(OTT[2]) * (1 - X5 * 0.618) : nz(OTT[2]) * (1 - X5 / 2), color=color.new(#007BBD, 0), linewidth=1, title="OTT LOWER HALF")
OTTALTFIBO2 = plot(showfibolines ? nz(OTT[2]) * (1 - X5 * 0.382) : na, color=color.new(#024DE3, 0), linewidth=1, title="OTT LOWER HALF")
fill(OTTUST, OTTUSTYARI, color=color.new(#4500C4, 88))
fill(OTTFIBOUST2, OTTUSTYARI, color=color.new(#8400FF, 88))
fill(OTTUSTYARI, OTTMAIN, color=color.new(#C810FF, 88))
fill(OTTFIBOUST2, OTTMAIN, color=color.new(#C810FF, 88))
fill(OTTALT, OTTALTYARI, color=color.new(#00A6FF, 88))
fill(OTTALTFIBO2, OTTALTYARI, color=color.new(#007BBD, 88))
fill(OTTALTYARI, OTTMAIN, color=color.new(#024DE3, 88))
fill(OTTALTFIBO2, OTTMAIN, color=color.new(#024DE3, 88))
alertcondition(ta.cross(MAvg, OTT[2]), title="Cross Alert", message="OTT - Support Line Crossing!")
alertcondition(ta.crossover(MAvg, OTT[2]), title="Crossover Alarm", message="Support Line BUY SIGNAL!")
alertcondition(ta.crossunder(MAvg, OTT[2]), title="Crossunder Alarm", message="Support Line SELL SIGNAL!")
alertcondition(ta.cross(src, OTT[2]), title="Price Cross Alert", message="OTT - Price Crossing!")
alertcondition(ta.crossover(src, OTT[2]), title="Price Crossover Alarm", message="PRICE OVER OTT - BUY SIGNAL!")
alertcondition(ta.crossunder(src, OTT[2]), title="Price Crossunder Alarm", message="PRICE UNDER OTT - SELL SIGNAL!")
This file is under the Mozilla Public License 2.0; it is a port of the original by KivancOzbilgic, with the original licence header kept and the changes made for FloScript noted in the file.
- v2
Library refresh 2026-10-14
- v1
Library refresh 2026-10-12
Disclaimer. Scripts are written and published by members, or ported by FloSignals from open-source originals, and are their authors' own work and opinion. FloSignals does not review them for correctness and nothing in a script is financial advice or a recommendation to buy or sell anything — read the Risk Disclaimer. Posting here is under the Community Rules; a script that is not the poster's to post can be reported as the Copyright & Takedowns page says.

Comments (0)
No comments yet. Members can leave one.