HIGH and LOW Optimized Trend Tracker HOTT LOTT for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
fPBBexK.png


Optimized Trend Tracker created by Kivanc Ozbilgic.
OTT is an indicator that allows traders to find an existing trend. In other words to see which side of the current trend we are on.

The area between HOTT and LOTT is FLAT ZONE which developer advises to do nothing.
Bars will be highlighted to Turquoise when candles close over HOTT, means an UPTREND SIGNAL

and to Fuchia when candles begin closing under LOTT line to indicate a DOWNTREND SIGNAL.

FLAT ZONE is highlighted also to have the maximum concentration on sideways market conditions.

There are three quantitative parameters in this indicator:
The first parameter in the OTT indicator set by the two parameters is the period/length.
OTT lines will be much sensitive to trend movements if it is smaller.
And vice versa, will be less sensitive when it is longer.
As the period increases it will become less sensitive to little trends and price actions.
In this way, your choice of period, will be closely related to which of the sort of trends you are interested in.

The OTT percent parameter in OTT is an optimization coefficient. Just like in the period
small values are better at capturing short term fluctuations, while large values
will be more suitable for long-term trends.

The final adjustable quantitative parameter is HIGHEST and LOWEST length which is the source of calculations.

SOURCE CODE

CSS:
#// © KivancOzbilgic
#//created by: @Anil_Ozeksi
#//developer: ANIL ÖZEKŞİ
#//author: @kivancozbilgic
#https://www.tradingview.com/script/5qkKOlVg-HIGH-and-LOW-Optimized-Trend-Tracker-HOTT-LOTT/
#indicator('HIGH AND LOW Optimized Trend Tracker', 'HL OTT', overlay=true)
# Converted and mod by Sam4Cok @ Samer800 08/2022

input Alert     = {default "No Alert", "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input ShowCloud = yes;    # Highlighter On/Off ?
input BarColor  = no;
input length    = 2;         # OTT Period
input percent   = 0.6;      # OTT Optimization Coeff
input hllength  = 10;      # Highest and Lowest Length
input MovAvgType = {default VAR, SMA, EMA, WMA, DEMA, TMA, WWMA, ZLEMA, TSF, HULL};

def na = Double.NaN;
script nz {
    input data  = 1;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}
def src  = Highest(high, hllength);
def srcl = Lowest(low, hllength);

#Var_Func(src, length) =>
script Var_Func {
    input src    = close;
    input length = 0;
    def valpha = 2 / (length + 1);
    def vud1 = if src > src[1] then src - src[1] else 0;
    def vdd1 = if src < src[1] then src[1] - src else 0;
    def vUD = Sum(vud1, 9);
    def vDD = Sum(vdd1, 9);
    def vCMO = nz((vUD - vDD) / (vUD + vDD));
    def VAR;
    VAR = valpha * AbsValue(vCMO) * src + (1 - valpha * AbsValue(vCMO)) * nz(VAR[1]);
    plot result = VAR;
}
#Wwma_Func(src, length) =>
script Wwma_Func {
    input src = close;
    input length = 0;
    def wwalpha = 1 / length;
    def WWMA;
    WWMA = wwalpha * src + (1 - wwalpha) * nz(WWMA[1]);
    plot return = WWMA;
}
#Zlema_Func(src, length) =>
script Zlema_Func {
    input src = close;
    input length = 0;
    def zxLag = if length / 2 == Round(length / 2) then length / 2 else (length - 1) / 2;
    def zxEMAData = src + src - src[zxLag];
    def ZLEMA = ExpAverage(zxEMAData, length);
    plot return = ZLEMA;
}
#Tsf_Func(src, length) =>
script Tsf_Func {
    input src = close;
    input length = 0;
    def lrc = Inertia(src, length);
    def lrc1 = Inertia(src[1], length);
    def lrs = lrc - lrc1;
    def TSF = Inertia(src, length) + lrs;
    plot retur = TSF;
}

def HMA = WMA(2 * WMA(src, length / 2) - WMA(src, length), Round(Sqrt(length)));
#Var_Funcl(srcl, length) =>
script Var_Funcl {
    input srcl = close;
    input length = 0;
    def valphal = 2 / (length + 1);
    def vud1l = if srcl > srcl[1] then srcl - srcl[1] else 0;
    def vdd1l = if srcl < srcl[1] then srcl[1] - srcl else 0;
    def vUDl = Sum(vud1l, 9);
    def vDDl = Sum(vdd1l, 9);
    def vCMOl = nz((vUDl - vDDl) / (vUDl + vDDl));
    def VARl;
    VARl = nz(valphal * AbsValue(vCMOl) * srcl) + (1 - valphal * AbsValue(vCMOl)) * nz(VARl[1]);
    plot return = VARl;
}

#Wwma_Funcl(srcl, length) =>
script Wwma_Funcl {
    input srcl = close;
    input length = 0;
    def wwalpha = 1 / length;
    def WWMA;
    WWMA = wwalpha * srcl + (1 - wwalpha) * nz(WWMA[1]);
    plot return = WWMA;
}
#Zlema_Funcl(srcl, length) =>
script Zlema_Funcl {
    input srcl = close;
    input length = 0;
    def zxLag = if length / 2 == Round(length / 2) then length / 2 else (length - 1) / 2;
    def zxEMAData = srcl + srcl - srcl[zxLag];
    def ZLEMA = ExpAverage(zxEMAData, length);
    plot return = ZLEMA;
}
#Tsf_Funcl(srcl, length) =>
script Tsf_Funcl {
    input srcl = close;
    input length = 0;
    def lrc = Inertia(srcl, length);
    def lrc1 = Inertia(srcl[1], length);
    def lrs = lrc - lrc1;
    def TSF = Inertia(srcl, length) + lrs;
    plot retur = TSF;
}

#getMA(src, length, type) =>
script getMA {
    input src = close;
    input length = 100;
    input type   = "SMA";
    def ma;
    ma = if type == "SMA" then SimpleMovingAvg(src, length) else
     if type == "EMA" then ExpAverage(src, length) else
     if type == "WMA" then WMA(src, length) else
     if type == "DEMA" then 2 * ExpAverage(src, length) - ExpAverage(ExpAverage(src, length), length) else
     if type == "TMA" then SimpleMovingAvg(SimpleMovingAvg(src, Ceil(length / 2)), Floor(length / 2) + 1) else
     if type == "VAR" then Var_Func(src, length) else
     if type == "WWMA" then WWMA_Func(src, length) else
     if type == "ZLEMA" then Zlema_Func(src, length) else
     if type == "TSF" then Tsf_Func(src, length) else
     if type == "HULL" then WMA(2 * WMA(src, length / 2) - WMA(src, length), Round(Sqrt(length))) else Double.NaN;
    plot result = ma;
}

#OTT(Source, percent) =>
script OTT {
input Source    = close;
input percent   = 0;
   
    def fark = Source * percent * 0.01;
    def UP = Source + fark;
    def LW = Source - fark;
    def UP_Band = if ((UP < UP_Band[1]) or (Source[1] > UP_Band[1])) then UP else UP_Band[1];
    def LW_Band = if ((LW > LW_Band[1]) or (Source[1] < LW_Band[1])) then LW else LW_Band[1];
    def MT = if ((MT[1] == UP_Band[1]) and (Source < UP_Band)) then UP_Band
        else if ((MT[1] == UP_Band[1]) and (Source > UP_Band)) then LW_Band
        else if ((MT[1] == LW_Band[1]) and (Source > LW_Band)) then LW_Band
        else if ((MT[1] == LW_Band)    and (Source < LW_Band)) then UP_Band
        else LW_Band;
    plot Super = MT;
}

def MAvg = getMA(src, length, MovAvgType);
def MT = OTT(MAvg, percent);
def HOTT = if MAvg > MT then MT * (200 + percent) / 200 else MT * (200 - percent) / 200;

def MAvgl = getMA(srcl, length, MovAvgType);
def MTl = OTT(MAvgl, percent);
def LOTT = if MAvgl > MTl then MTl * (200 + percent) / 200 else MTl * (200 - percent) / 200;

### Plots
plot HOTTLine = if HOTT then nz(HOTT[2]) else na;
plot LOTTLine = if LOTT then nz(LOTT[2]) else na;

HOTTLine.AssignValueColor(CreateColor(41,98,255));
HOTTLine.SetLineWeight(2);
LOTTLine.AssignValueColor(CreateColor(255,82,82));
LOTTLine.SetLineWeight(2);

### Clouds/BarColor
addcloud(if ShowCloud then HOTTLine else na, LOTTLine, CreateColor(48,25,52));
AssignPriceColor(if BarColor then if close > HOTT[2] then CreateColor(0,255,255) else if close < LOTT[2] then CreateColor(255,0,255) else Color.CURRENT else Color.CURRENT);

### Alerts
Alert(if alert ==alert."No Alert" then na else close crosses above HOTT[2],"PRICE OVER HOTT", Alert.ONCE, Alert);
Alert(if alert ==alert."No Alert" then na else close crosses below LOTT[2],"PRICE UNDER LOTT", Alert.ONCE, Alert);

### END of CODE
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

fPBBexK.png


Note By the developer
The area between HOTT and LOTT is FLAT ZONE which developer advises to do nothing.

Bars will be highlighted to Turquoise when candles close over HOTT, means an UPTREND SIGNAL
and to Fuchia when candles begin closing under LOTT line to indicate a DOWNTREND SIGNAL.

FLAT ZONE is highlighted also to have the maximum concentration on sideways market conditions.

There are three quantitative parameters in this indicator:
The first parameter in the OTT indicator set by the two parameters is the period/length.
OTT lines will be much sensitive to trend movements if it is smaller.
And vice versa, will be less sensitive when it is longer.
As the period increases it will become less sensitive to little trends and price actions.
In this way, your choice of period, will be closely related to which of the sort of trends you are interested in.

The OTT percent parameter in OTT is an optimization coefficient. Just like in the period
small values are better at capturing short term fluctuations, while large values
will be more suitable for long-term trends.

The final adjustable quantitative parameter is HIGHEST and LOWEST length which is the source of calculations.

SOURCE CODE

CSS:
#// © KivancOzbilgic
#//created by: @Anil_Ozeksi
#//developer: ANIL ÖZEKŞİ
#//author: @kivancozbilgic
#https://www.tradingview.com/script/5qkKOlVg-HIGH-and-LOW-Optimized-Trend-Tracker-HOTT-LOTT/
#indicator('HIGH AND LOW Optimized Trend Tracker', 'HL OTT', overlay=true)
# Converted and mod by Sam4Cok @ Samer800 08/2022

input Alert     = {default "No Alert", "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input ShowCloud = yes;    # Highlighter On/Off ?
input BarColor  = no;
input length    = 2;         # OTT Period
input percent   = 0.6;      # OTT Optimization Coeff
input hllength  = 10;      # Highest and Lowest Length
input MovAvgType = {default VAR, SMA, EMA, WMA, DEMA, TMA, WWMA, ZLEMA, TSF, HULL};

def na = Double.NaN;
script nz {
    input data  = 1;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}
def src  = Highest(high, hllength);
def srcl = Lowest(low, hllength);

#Var_Func(src, length) =>
script Var_Func {
    input src    = close;
    input length = 0;
    def valpha = 2 / (length + 1);
    def vud1 = if src > src[1] then src - src[1] else 0;
    def vdd1 = if src < src[1] then src[1] - src else 0;
    def vUD = Sum(vud1, 9);
    def vDD = Sum(vdd1, 9);
    def vCMO = nz((vUD - vDD) / (vUD + vDD));
    def VAR;
    VAR = valpha * AbsValue(vCMO) * src + (1 - valpha * AbsValue(vCMO)) * nz(VAR[1]);
    plot result = VAR;
}
#Wwma_Func(src, length) =>
script Wwma_Func {
    input src = close;
    input length = 0;
    def wwalpha = 1 / length;
    def WWMA;
    WWMA = wwalpha * src + (1 - wwalpha) * nz(WWMA[1]);
    plot return = WWMA;
}
#Zlema_Func(src, length) =>
script Zlema_Func {
    input src = close;
    input length = 0;
    def zxLag = if length / 2 == Round(length / 2) then length / 2 else (length - 1) / 2;
    def zxEMAData = src + src - src[zxLag];
    def ZLEMA = ExpAverage(zxEMAData, length);
    plot return = ZLEMA;
}
#Tsf_Func(src, length) =>
script Tsf_Func {
    input src = close;
    input length = 0;
    def lrc = Inertia(src, length);
    def lrc1 = Inertia(src[1], length);
    def lrs = lrc - lrc1;
    def TSF = Inertia(src, length) + lrs;
    plot retur = TSF;
}

def HMA = WMA(2 * WMA(src, length / 2) - WMA(src, length), Round(Sqrt(length)));
#Var_Funcl(srcl, length) =>
script Var_Funcl {
    input srcl = close;
    input length = 0;
    def valphal = 2 / (length + 1);
    def vud1l = if srcl > srcl[1] then srcl - srcl[1] else 0;
    def vdd1l = if srcl < srcl[1] then srcl[1] - srcl else 0;
    def vUDl = Sum(vud1l, 9);
    def vDDl = Sum(vdd1l, 9);
    def vCMOl = nz((vUDl - vDDl) / (vUDl + vDDl));
    def VARl;
    VARl = nz(valphal * AbsValue(vCMOl) * srcl) + (1 - valphal * AbsValue(vCMOl)) * nz(VARl[1]);
    plot return = VARl;
}

#Wwma_Funcl(srcl, length) =>
script Wwma_Funcl {
    input srcl = close;
    input length = 0;
    def wwalpha = 1 / length;
    def WWMA;
    WWMA = wwalpha * srcl + (1 - wwalpha) * nz(WWMA[1]);
    plot return = WWMA;
}
#Zlema_Funcl(srcl, length) =>
script Zlema_Funcl {
    input srcl = close;
    input length = 0;
    def zxLag = if length / 2 == Round(length / 2) then length / 2 else (length - 1) / 2;
    def zxEMAData = srcl + srcl - srcl[zxLag];
    def ZLEMA = ExpAverage(zxEMAData, length);
    plot return = ZLEMA;
}
#Tsf_Funcl(srcl, length) =>
script Tsf_Funcl {
    input srcl = close;
    input length = 0;
    def lrc = Inertia(srcl, length);
    def lrc1 = Inertia(srcl[1], length);
    def lrs = lrc - lrc1;
    def TSF = Inertia(srcl, length) + lrs;
    plot retur = TSF;
}

#getMA(src, length, type) =>
script getMA {
    input src = close;
    input length = 100;
    input type   = "SMA";
    def ma;
    ma = if type == "SMA" then SimpleMovingAvg(src, length) else
     if type == "EMA" then ExpAverage(src, length) else
     if type == "WMA" then WMA(src, length) else
     if type == "DEMA" then 2 * ExpAverage(src, length) - ExpAverage(ExpAverage(src, length), length) else
     if type == "TMA" then SimpleMovingAvg(SimpleMovingAvg(src, Ceil(length / 2)), Floor(length / 2) + 1) else
     if type == "VAR" then Var_Func(src, length) else
     if type == "WWMA" then WWMA_Func(src, length) else
     if type == "ZLEMA" then Zlema_Func(src, length) else
     if type == "TSF" then Tsf_Func(src, length) else
     if type == "HULL" then WMA(2 * WMA(src, length / 2) - WMA(src, length), Round(Sqrt(length))) else Double.NaN;
    plot result = ma;
}

#OTT(Source, percent) =>
script OTT {
input Source    = close;
input percent   = 0;
   
    def fark = Source * percent * 0.01;
    def UP = Source + fark;
    def LW = Source - fark;
    def UP_Band = if ((UP < UP_Band[1]) or (Source[1] > UP_Band[1])) then UP else UP_Band[1];
    def LW_Band = if ((LW > LW_Band[1]) or (Source[1] < LW_Band[1])) then LW else LW_Band[1];
    def MT = if ((MT[1] == UP_Band[1]) and (Source < UP_Band)) then UP_Band
        else if ((MT[1] == UP_Band[1]) and (Source > UP_Band)) then LW_Band
        else if ((MT[1] == LW_Band[1]) and (Source > LW_Band)) then LW_Band
        else if ((MT[1] == LW_Band)    and (Source < LW_Band)) then UP_Band
        else LW_Band;
    plot Super = MT;
}

def MAvg = getMA(src, length, MovAvgType);
def MT = OTT(MAvg, percent);
def HOTT = if MAvg > MT then MT * (200 + percent) / 200 else MT * (200 - percent) / 200;

def MAvgl = getMA(srcl, length, MovAvgType);
def MTl = OTT(MAvgl, percent);
def LOTT = if MAvgl > MTl then MTl * (200 + percent) / 200 else MTl * (200 - percent) / 200;

### Plots
plot HOTTLine = if HOTT then nz(HOTT[2]) else na;
plot LOTTLine = if LOTT then nz(LOTT[2]) else na;

HOTTLine.AssignValueColor(CreateColor(41,98,255));
HOTTLine.SetLineWeight(2);
LOTTLine.AssignValueColor(CreateColor(255,82,82));
LOTTLine.SetLineWeight(2);

### Clouds/BarColor
addcloud(if ShowCloud then HOTTLine else na, LOTTLine, CreateColor(48,25,52));
AssignPriceColor(if BarColor then if close > HOTT[2] then CreateColor(0,255,255) else if close < LOTT[2] then CreateColor(255,0,255) else Color.CURRENT else Color.CURRENT);

### Alerts
Alert(if alert ==alert."No Alert" then na else close crosses above HOTT[2],"PRICE OVER HOTT", Alert.ONCE, Alert);
Alert(if alert ==alert."No Alert" then na else close crosses below LOTT[2],"PRICE UNDER LOTT", Alert.ONCE, Alert);

### END of CODE
hi great indicator, i see you have it on 5 min chart
can multiple timeframe be add to the study?
 
hi great indicator, i see you have it on 5 min chart
can multiple timeframe be add to the study?
MTF - MultiTimeFrame added below with option to enable/disable.

CSS:
#// © KivancOzbilgic
#//created by: @Anil_Ozeksi
#//developer: ANIL ÖZEK??
#//author: @kivancozbilgic
#https://www.tradingview.com/script/5qkKOlVg-HIGH-and-LOW-Optimized-Trend-Tracker-HOTT-LOTT/
#indicator('HIGH AND LOW Optimized Trend Tracker', 'HL OTT', overlay=true)
# Converted and mod by Sam4Cok @ Samer800 08/2022

input Alert     = {default "No Alert", "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input ShowCloud = yes;    # Highlighter On/Off ?
input BarColor  = no;
input length    = 2;         # OTT Period
input percent   = 0.6;      # OTT Optimization Coeff
input hllength  = 10;      # Highest and Lowest Length
input MovAvgType = {default VAR, SMA, EMA, WMA, DEMA, TMA, WWMA, ZLEMA, TSF, HULL};
input multiTime  = no;
input aggregation1 = AggregationPeriod.FIVE_MIN;
input aggregation2 = AggregationPeriod.FIFTEEN_MIN;

def na = Double.NaN;
script nz {
    input data  = 1;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}

def close1; def close2; def high1; def high2; def low1; def low2;
if multiTime then {
high1  = high(Period = aggregation1);
low1   = low(period = aggregation1);
close1 = close(Period = aggregation1);
high2  = high(Period = aggregation2);
low2   = low(period = aggregation2);
close2 = close(Period = aggregation2);}
else {
high1  = na;
low1   = na;
close1 = na;
high2  = na;
low2   = na;
close2 = na;}

def src  = Highest(high, hllength);
def srcl = Lowest(low, hllength);
def src1  = Highest(high1, hllength);
def srcl1 = Lowest(low1, hllength);
def src2  = Highest(high2, hllength);
def srcl2 = Lowest(low2, hllength);

#Var_Func(src, length) =>
script Var_Func {
    input src    = close;
    input length = 0;
    def valpha = 2 / (length + 1);
    def vud1 = if src > src[1] then src - src[1] else 0;
    def vdd1 = if src < src[1] then src[1] - src else 0;
    def vUD = Sum(vud1, 9);
    def vDD = Sum(vdd1, 9);
    def vCMO = nz((vUD - vDD) / (vUD + vDD));
    def VAR;
    VAR = valpha * AbsValue(vCMO) * src + (1 - valpha * AbsValue(vCMO)) * nz(VAR[1]);
    plot result = VAR;
}
#Wwma_Func(src, length) =>
script Wwma_Func {
    input src = close;
    input length = 0;
    def wwalpha = 1 / length;
    def WWMA;
    WWMA = wwalpha * src + (1 - wwalpha) * nz(WWMA[1]);
    plot return = WWMA;
}
#Zlema_Func(src, length) =>
script Zlema_Func {
    input src = close;
    input length = 0;
    def zxLag = if length / 2 == Round(length / 2) then length / 2 else (length - 1) / 2;
    def zxEMAData = src + src - src[zxLag];
    def ZLEMA = ExpAverage(zxEMAData, length);
    plot return = ZLEMA;
}
#Tsf_Func(src, length) =>
script Tsf_Func {
    input src = close;
    input length = 0;
    def lrc = Inertia(src, length);
    def lrc1 = Inertia(src[1], length);
    def lrs = lrc - lrc1;
    def TSF = Inertia(src, length) + lrs;
    plot retur = TSF;
}

#def HMA = WMA(2 * WMA(src, length / 2) - WMA(src, length), Round(Sqrt(length)));
#Var_Funcl(srcl, length) =>
script Var_Funcl {
    input srcl = close;
    input length = 0;
    def valphal = 2 / (length + 1);
    def vud1l = if srcl > srcl[1] then srcl - srcl[1] else 0;
    def vdd1l = if srcl < srcl[1] then srcl[1] - srcl else 0;
    def vUDl = Sum(vud1l, 9);
    def vDDl = Sum(vdd1l, 9);
    def vCMOl = nz((vUDl - vDDl) / (vUDl + vDDl));
    def VARl;
    VARl = nz(valphal * AbsValue(vCMOl) * srcl) + (1 - valphal * AbsValue(vCMOl)) * nz(VARl[1]);
    plot return = VARl;
}

#Wwma_Funcl(srcl, length) =>
script Wwma_Funcl {
    input srcl = close;
    input length = 0;
    def wwalpha = 1 / length;
    def WWMA;
    WWMA = wwalpha * srcl + (1 - wwalpha) * nz(WWMA[1]);
    plot return = WWMA;
}
#Zlema_Funcl(srcl, length) =>
script Zlema_Funcl {
    input srcl = close;
    input length = 0;
    def zxLag = if length / 2 == Round(length / 2) then length / 2 else (length - 1) / 2;
    def zxEMAData = srcl + srcl - srcl[zxLag];
    def ZLEMA = ExpAverage(zxEMAData, length);
    plot return = ZLEMA;
}
#Tsf_Funcl(srcl, length) =>
script Tsf_Funcl {
    input srcl = close;
    input length = 0;
    def lrc = Inertia(srcl, length);
    def lrc1 = Inertia(srcl[1], length);
    def lrs = lrc - lrc1;
    def TSF = Inertia(srcl, length) + lrs;
    plot retur = TSF;
}
#getMA(src, length, type) =>
script getMA {
    input src = close;
    input length = 100;
    input type   = "SMA";
    def ma;
    ma = if type == "SMA" then SimpleMovingAvg(src, length) else
     if type == "EMA" then ExpAverage(src, length) else
     if type == "WMA" then WMA(src, length) else
     if type == "DEMA" then 2 * ExpAverage(src, length) - ExpAverage(ExpAverage(src, length), length) else
     if type == "TMA" then SimpleMovingAvg(SimpleMovingAvg(src, Ceil(length / 2)), Floor(length / 2) + 1) else
     if type == "VAR" then Var_Func(src, length) else
     if type == "WWMA" then WWMA_Func(src, length) else
     if type == "ZLEMA" then Zlema_Func(src, length) else
     if type == "TSF" then Tsf_Func(src, length) else
     if type == "HULL" then WMA(2 * WMA(src, length / 2) - WMA(src, length), Round(Sqrt(length))) else Double.NaN;
    plot result = ma;
}
#OTT(Source, percent) =>
script OTT {
    input Source    = close;
    input percent   = 0;
    def fark = Source * percent * 0.01;
    def UP = Source + fark;
    def LW = Source - fark;
    def UP_Band = if ((UP < UP_Band[1]) or (Source[1] > UP_Band[1])) then UP else UP_Band[1];
    def LW_Band = if ((LW > LW_Band[1]) or (Source[1] < LW_Band[1])) then LW else LW_Band[1];
    def MT = if ((MT[1] == UP_Band[1]) and (Source < UP_Band)) then UP_Band
        else if ((MT[1] == UP_Band[1]) and (Source > UP_Band)) then LW_Band
        else if ((MT[1] == LW_Band[1]) and (Source > LW_Band)) then LW_Band
        else if ((MT[1] == LW_Band)    and (Source < LW_Band)) then UP_Band
        else LW_Band;
    plot return = MT;
}

def MAvg = getMA(src, length, MovAvgType);
def MT   = OTT(MAvg, percent);
def HOTT = if MAvg > MT then MT * (200 + percent) / 200 else MT * (200 - percent) / 200;

def MAvgl = getMA(srcl, length, MovAvgType);
def MTl = OTT(MAvgl, percent);
def LOTT = if MAvgl > MTl then MTl * (200 + percent) / 200 else MTl * (200 - percent) / 200;

### Plots
plot HOTTLine = if HOTT then nz(HOTT[2]) else na;
plot LOTTLine = if LOTT then nz(LOTT[2]) else na;

HOTTLine.AssignValueColor(CreateColor(41, 98, 255));
HOTTLine.SetLineWeight(2);
LOTTLine.AssignValueColor(CreateColor(255, 82, 82));
LOTTLine.SetLineWeight(2);

### Clouds/BarColor
AddCloud(if ShowCloud then HOTTLine else na, LOTTLine, CreateColor(48, 25, 52));
AssignPriceColor(if BarColor then if close > HOTT[2] then CreateColor(0, 255, 255) else if close < LOTT[2] then CreateColor(255, 0, 255) else Color.CURRENT else Color.CURRENT);

### Alerts
Alert(if Alert == Alert."No Alert" then na else close crosses above HOTT[2], "PRICE OVER HOTT", Alert.ONCE, Alert);
Alert(if Alert == Alert."No Alert" then na else close crosses below LOTT[2], "PRICE UNDER LOTT", Alert.ONCE, Alert);
#################################################3

def MAvg1 = getMA(src1, length, MovAvgType);
def MT1   = OTT(MAvg1, percent);
def HOTT1 = if MAvg1 > MT1 then MT1 * (200 + percent) / 200 else MT1 * (200 - percent) / 200;

def MAvgl1 = getMA(srcl1, length, MovAvgType);
def MTl1 = OTT(MAvgl1, percent);
def LOTT1 = if MAvgl1 > MTl1 then MTl1 * (200 + percent) / 200 else MTl1 * (200 - percent) / 200;

### Plots
plot HOTTLine1 = if HOTT1 then nz(HOTT1[2]) else na;
plot LOTTLine1 = if LOTT1 then nz(LOTT1[2]) else na;

HOTTLine1.AssignValueColor(CreateColor(41, 98, 255));
HOTTLine1.SetLineWeight(2);
LOTTLine1.AssignValueColor(CreateColor(255, 82, 82));
LOTTLine1.SetLineWeight(2);

### Clouds/BarColor
AddCloud(if ShowCloud then HOTTLine1 else na, LOTTLine1, CreateColor(48, 25, 52));

### Alerts
Alert(if Alert == Alert."No Alert" then na else close1 crosses above HOTT1[2], "PRICE OVER HOTT", Alert.ONCE, Alert);
Alert(if Alert == Alert."No Alert" then na else close1 crosses below LOTT1[2], "PRICE UNDER LOTT", Alert.ONCE, Alert);

##################################################
def MAvg2 = getMA(src2, length, MovAvgType);
def MT2   = OTT(MAvg2, percent);
def HOTT2 = if MAvg2 > MT2 then MT2 * (200 + percent) / 200 else MT2 * (200 - percent) / 200;

def MAvgl2 = getMA(srcl2, length, MovAvgType);
def MTl2 = OTT(MAvgl2, percent);
def LOTT2 = if MAvgl2 > MTl2 then MTl2 * (200 + percent) / 200 else MTl2 * (200 - percent) / 200;

### Plots
plot HOTTLine2 = if HOTT2 then nz(HOTT2[2]) else na;
plot LOTTLine2 = if LOTT2 then nz(LOTT2[2]) else na;

HOTTLine2.AssignValueColor(CreateColor(41, 98, 255));
HOTTLine2.SetLineWeight(2);
LOTTLine2.AssignValueColor(CreateColor(255, 82, 82));
LOTTLine2.SetLineWeight(2);

### Clouds/BarColor
AddCloud(if ShowCloud then HOTTLine2 else na, LOTTLine2, CreateColor(48, 25, 52));

### Alerts
Alert(if Alert == Alert."No Alert" then na else close2 crosses above HOTT2[2], "PRICE OVER HOTT", Alert.ONCE, Alert);
Alert(if Alert == Alert."No Alert" then na else close2 crosses below LOTT2[2], "PRICE UNDER LOTT", Alert.ONCE, Alert);
### END of CODE
 
MTF - MultiTimeFrame added below with option to enable/disable.

CSS:
#// © KivancOzbilgic
#//created by: @Anil_Ozeksi
#//developer: ANIL ÖZEK??
#//author: @kivancozbilgic
#https://www.tradingview.com/script/5qkKOlVg-HIGH-and-LOW-Optimized-Trend-Tracker-HOTT-LOTT/
#indicator('HIGH AND LOW Optimized Trend Tracker', 'HL OTT', overlay=true)
# Converted and mod by Sam4Cok @ Samer800 08/2022

input Alert     = {default "No Alert", "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input ShowCloud = yes;    # Highlighter On/Off ?
input BarColor  = no;
input length    = 2;         # OTT Period
input percent   = 0.6;      # OTT Optimization Coeff
input hllength  = 10;      # Highest and Lowest Length
input MovAvgType = {default VAR, SMA, EMA, WMA, DEMA, TMA, WWMA, ZLEMA, TSF, HULL};
input multiTime  = no;
input aggregation1 = AggregationPeriod.FIVE_MIN;
input aggregation2 = AggregationPeriod.FIFTEEN_MIN;

def na = Double.NaN;
script nz {
    input data  = 1;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}

def close1; def close2; def high1; def high2; def low1; def low2;
if multiTime then {
high1  = high(Period = aggregation1);
low1   = low(period = aggregation1);
close1 = close(Period = aggregation1);
high2  = high(Period = aggregation2);
low2   = low(period = aggregation2);
close2 = close(Period = aggregation2);}
else {
high1  = na;
low1   = na;
close1 = na;
high2  = na;
low2   = na;
close2 = na;}

def src  = Highest(high, hllength);
def srcl = Lowest(low, hllength);
def src1  = Highest(high1, hllength);
def srcl1 = Lowest(low1, hllength);
def src2  = Highest(high2, hllength);
def srcl2 = Lowest(low2, hllength);

#Var_Func(src, length) =>
script Var_Func {
    input src    = close;
    input length = 0;
    def valpha = 2 / (length + 1);
    def vud1 = if src > src[1] then src - src[1] else 0;
    def vdd1 = if src < src[1] then src[1] - src else 0;
    def vUD = Sum(vud1, 9);
    def vDD = Sum(vdd1, 9);
    def vCMO = nz((vUD - vDD) / (vUD + vDD));
    def VAR;
    VAR = valpha * AbsValue(vCMO) * src + (1 - valpha * AbsValue(vCMO)) * nz(VAR[1]);
    plot result = VAR;
}
#Wwma_Func(src, length) =>
script Wwma_Func {
    input src = close;
    input length = 0;
    def wwalpha = 1 / length;
    def WWMA;
    WWMA = wwalpha * src + (1 - wwalpha) * nz(WWMA[1]);
    plot return = WWMA;
}
#Zlema_Func(src, length) =>
script Zlema_Func {
    input src = close;
    input length = 0;
    def zxLag = if length / 2 == Round(length / 2) then length / 2 else (length - 1) / 2;
    def zxEMAData = src + src - src[zxLag];
    def ZLEMA = ExpAverage(zxEMAData, length);
    plot return = ZLEMA;
}
#Tsf_Func(src, length) =>
script Tsf_Func {
    input src = close;
    input length = 0;
    def lrc = Inertia(src, length);
    def lrc1 = Inertia(src[1], length);
    def lrs = lrc - lrc1;
    def TSF = Inertia(src, length) + lrs;
    plot retur = TSF;
}

#def HMA = WMA(2 * WMA(src, length / 2) - WMA(src, length), Round(Sqrt(length)));
#Var_Funcl(srcl, length) =>
script Var_Funcl {
    input srcl = close;
    input length = 0;
    def valphal = 2 / (length + 1);
    def vud1l = if srcl > srcl[1] then srcl - srcl[1] else 0;
    def vdd1l = if srcl < srcl[1] then srcl[1] - srcl else 0;
    def vUDl = Sum(vud1l, 9);
    def vDDl = Sum(vdd1l, 9);
    def vCMOl = nz((vUDl - vDDl) / (vUDl + vDDl));
    def VARl;
    VARl = nz(valphal * AbsValue(vCMOl) * srcl) + (1 - valphal * AbsValue(vCMOl)) * nz(VARl[1]);
    plot return = VARl;
}

#Wwma_Funcl(srcl, length) =>
script Wwma_Funcl {
    input srcl = close;
    input length = 0;
    def wwalpha = 1 / length;
    def WWMA;
    WWMA = wwalpha * srcl + (1 - wwalpha) * nz(WWMA[1]);
    plot return = WWMA;
}
#Zlema_Funcl(srcl, length) =>
script Zlema_Funcl {
    input srcl = close;
    input length = 0;
    def zxLag = if length / 2 == Round(length / 2) then length / 2 else (length - 1) / 2;
    def zxEMAData = srcl + srcl - srcl[zxLag];
    def ZLEMA = ExpAverage(zxEMAData, length);
    plot return = ZLEMA;
}
#Tsf_Funcl(srcl, length) =>
script Tsf_Funcl {
    input srcl = close;
    input length = 0;
    def lrc = Inertia(srcl, length);
    def lrc1 = Inertia(srcl[1], length);
    def lrs = lrc - lrc1;
    def TSF = Inertia(srcl, length) + lrs;
    plot retur = TSF;
}
#getMA(src, length, type) =>
script getMA {
    input src = close;
    input length = 100;
    input type   = "SMA";
    def ma;
    ma = if type == "SMA" then SimpleMovingAvg(src, length) else
     if type == "EMA" then ExpAverage(src, length) else
     if type == "WMA" then WMA(src, length) else
     if type == "DEMA" then 2 * ExpAverage(src, length) - ExpAverage(ExpAverage(src, length), length) else
     if type == "TMA" then SimpleMovingAvg(SimpleMovingAvg(src, Ceil(length / 2)), Floor(length / 2) + 1) else
     if type == "VAR" then Var_Func(src, length) else
     if type == "WWMA" then WWMA_Func(src, length) else
     if type == "ZLEMA" then Zlema_Func(src, length) else
     if type == "TSF" then Tsf_Func(src, length) else
     if type == "HULL" then WMA(2 * WMA(src, length / 2) - WMA(src, length), Round(Sqrt(length))) else Double.NaN;
    plot result = ma;
}
#OTT(Source, percent) =>
script OTT {
    input Source    = close;
    input percent   = 0;
    def fark = Source * percent * 0.01;
    def UP = Source + fark;
    def LW = Source - fark;
    def UP_Band = if ((UP < UP_Band[1]) or (Source[1] > UP_Band[1])) then UP else UP_Band[1];
    def LW_Band = if ((LW > LW_Band[1]) or (Source[1] < LW_Band[1])) then LW else LW_Band[1];
    def MT = if ((MT[1] == UP_Band[1]) and (Source < UP_Band)) then UP_Band
        else if ((MT[1] == UP_Band[1]) and (Source > UP_Band)) then LW_Band
        else if ((MT[1] == LW_Band[1]) and (Source > LW_Band)) then LW_Band
        else if ((MT[1] == LW_Band)    and (Source < LW_Band)) then UP_Band
        else LW_Band;
    plot return = MT;
}

def MAvg = getMA(src, length, MovAvgType);
def MT   = OTT(MAvg, percent);
def HOTT = if MAvg > MT then MT * (200 + percent) / 200 else MT * (200 - percent) / 200;

def MAvgl = getMA(srcl, length, MovAvgType);
def MTl = OTT(MAvgl, percent);
def LOTT = if MAvgl > MTl then MTl * (200 + percent) / 200 else MTl * (200 - percent) / 200;

### Plots
plot HOTTLine = if HOTT then nz(HOTT[2]) else na;
plot LOTTLine = if LOTT then nz(LOTT[2]) else na;

HOTTLine.AssignValueColor(CreateColor(41, 98, 255));
HOTTLine.SetLineWeight(2);
LOTTLine.AssignValueColor(CreateColor(255, 82, 82));
LOTTLine.SetLineWeight(2);

### Clouds/BarColor
AddCloud(if ShowCloud then HOTTLine else na, LOTTLine, CreateColor(48, 25, 52));
AssignPriceColor(if BarColor then if close > HOTT[2] then CreateColor(0, 255, 255) else if close < LOTT[2] then CreateColor(255, 0, 255) else Color.CURRENT else Color.CURRENT);

### Alerts
Alert(if Alert == Alert."No Alert" then na else close crosses above HOTT[2], "PRICE OVER HOTT", Alert.ONCE, Alert);
Alert(if Alert == Alert."No Alert" then na else close crosses below LOTT[2], "PRICE UNDER LOTT", Alert.ONCE, Alert);
#################################################3

def MAvg1 = getMA(src1, length, MovAvgType);
def MT1   = OTT(MAvg1, percent);
def HOTT1 = if MAvg1 > MT1 then MT1 * (200 + percent) / 200 else MT1 * (200 - percent) / 200;

def MAvgl1 = getMA(srcl1, length, MovAvgType);
def MTl1 = OTT(MAvgl1, percent);
def LOTT1 = if MAvgl1 > MTl1 then MTl1 * (200 + percent) / 200 else MTl1 * (200 - percent) / 200;

### Plots
plot HOTTLine1 = if HOTT1 then nz(HOTT1[2]) else na;
plot LOTTLine1 = if LOTT1 then nz(LOTT1[2]) else na;

HOTTLine1.AssignValueColor(CreateColor(41, 98, 255));
HOTTLine1.SetLineWeight(2);
LOTTLine1.AssignValueColor(CreateColor(255, 82, 82));
LOTTLine1.SetLineWeight(2);

### Clouds/BarColor
AddCloud(if ShowCloud then HOTTLine1 else na, LOTTLine1, CreateColor(48, 25, 52));

### Alerts
Alert(if Alert == Alert."No Alert" then na else close1 crosses above HOTT1[2], "PRICE OVER HOTT", Alert.ONCE, Alert);
Alert(if Alert == Alert."No Alert" then na else close1 crosses below LOTT1[2], "PRICE UNDER LOTT", Alert.ONCE, Alert);

##################################################
def MAvg2 = getMA(src2, length, MovAvgType);
def MT2   = OTT(MAvg2, percent);
def HOTT2 = if MAvg2 > MT2 then MT2 * (200 + percent) / 200 else MT2 * (200 - percent) / 200;

def MAvgl2 = getMA(srcl2, length, MovAvgType);
def MTl2 = OTT(MAvgl2, percent);
def LOTT2 = if MAvgl2 > MTl2 then MTl2 * (200 + percent) / 200 else MTl2 * (200 - percent) / 200;

### Plots
plot HOTTLine2 = if HOTT2 then nz(HOTT2[2]) else na;
plot LOTTLine2 = if LOTT2 then nz(LOTT2[2]) else na;

HOTTLine2.AssignValueColor(CreateColor(41, 98, 255));
HOTTLine2.SetLineWeight(2);
LOTTLine2.AssignValueColor(CreateColor(255, 82, 82));
LOTTLine2.SetLineWeight(2);

### Clouds/BarColor
AddCloud(if ShowCloud then HOTTLine2 else na, LOTTLine2, CreateColor(48, 25, 52));

### Alerts
Alert(if Alert == Alert."No Alert" then na else close2 crosses above HOTT2[2], "PRICE OVER HOTT", Alert.ONCE, Alert);
Alert(if Alert == Alert."No Alert" then na else close2 crosses below LOTT2[2], "PRICE UNDER LOTT", Alert.ONCE, Alert);
### END of CODE
thank you
i will test this
 
@samer800 , thank you SO much for reverse coding this from TV!!! In your first script, not the time aggregation script, why can't it work on a Tick chart? What part of the code confines it to Timed charts? Thx
 
@samer800 , thank you SO much for reverse coding this from TV!!! In your first script, not the time aggregation script, why can't it work on a Tick chart? What part of the code confines it to Timed charts? Thx
I don't use Tick chart so no much experience. However, I noticed scripts don't work on Tick chart so I removed the scripts and it is working now but will lose some moving average options. Check our below code for tick charts.

CSS:
#// © KivancOzbilgic
#//created by: @Anil_Ozeksi
#//developer: ANIL ÖZEK??
#//author: @kivancozbilgic
#https://www.tradingview.com/script/5qkKOlVg-HIGH-and-LOW-Optimized-Trend-Tracker-HOTT-LOTT/
#indicator('HIGH AND LOW Optimized Trend Tracker', 'HL OTT', overlay=true)
# Converted and mod by Sam4Cok @ Samer800 08/2022 for Tick chart

input Alert     = {default "No Alert", "NoSound", "Ding", "Bell", "Chimes", "Ring"};
input ShowCloud = yes;    # Highlighter On/Off ?
input length    = 2;      # OTT Period
input percent   = 0.6;    # OTT Optimization Coeff
input hllength  = 10;     # Highest and Lowest Length
input MovAvgType = AverageType.EXPONENTIAL;

def na = Double.NaN;

def src   = Highest(high, hllength);
def srcl  = Lowest(low, hllength);

def MAvg = MovingAverage(MovAvgType, src, length);
def Source    = MAvg;
def fark = Source * percent * 0.01;
def UP = Source + fark;
def LW = Source - fark;
def UP_Band = if ((UP < UP_Band[1]) or (Source[1] > UP_Band[1])) then UP else UP_Band[1];
def LW_Band = if ((LW > LW_Band[1]) or (Source[1] < LW_Band[1])) then LW else LW_Band[1];
def MT = if ((MT[1] == UP_Band[1]) and (Source < UP_Band)) then UP_Band
    else if ((MT[1] == UP_Band[1]) and (Source > UP_Band)) then LW_Band
    else if ((MT[1] == LW_Band[1]) and (Source > LW_Band)) then LW_Band
    else if ((MT[1] == LW_Band)    and (Source < LW_Band)) then UP_Band
        else LW_Band;
def HOTT = if MAvg > MT then MT * (200 + percent) / 200 else MT * (200 - percent) / 200;

def MAvgl = MovingAverage(MovAvgType, srcl, length);

def Sourcel    = MAvgl;
def fark1 = Sourcel * percent * 0.01;
def UP1 = Sourcel + fark1;
def LW1 = Sourcel - fark1;
def UP_Band1 = if ((UP1 < UP_Band1[1]) or (Sourcel[1] > UP_Band1[1])) then UP1 else UP_Band1[1];
def LW_Band1 = if ((LW1 > LW_Band1[1]) or (Sourcel[1] < LW_Band1[1])) then LW1 else LW_Band1[1];
def MT1 = if ((MT1[1] == UP_Band1[1]) and (Sourcel < UP_Band1)) then UP_Band1
        else if ((MT1[1] == UP_Band1[1]) and (Sourcel > UP_Band1)) then LW_Band1
        else if ((MT1[1] == LW_Band1[1]) and (Sourcel > LW_Band1)) then LW_Band1
        else if ((MT1[1] == LW_Band1)    and (Sourcel < LW_Band1)) then UP_Band1
        else LW_Band1;

def LOTT = if MAvgl > MT1 then MT1 * (200 + percent) / 200 else MT1 * (200 - percent) / 200;

### Plots
plot HOTTLine = if HOTT then (HOTT[2]) else na;
plot LOTTLine = if LOTT then (LOTT[2]) else na;

HOTTLine.AssignValueColor(CreateColor(41, 98, 255));
HOTTLine.SetLineWeight(2);
LOTTLine.AssignValueColor(CreateColor(255, 82, 82));
LOTTLine.SetLineWeight(2);

### Clouds/BarColor
AddCloud(if ShowCloud then HOTTLine else na, LOTTLine, CreateColor(48, 25, 52));

### Alerts
Alert(if Alert == Alert."No Alert" then na else close crosses above HOTT[2], "PRICE OVER HOTT", Alert.ONCE, Alert);
Alert(if Alert == Alert."No Alert" then na else close crosses below LOTT[2], "PRICE UNDER LOTT", Alert.ONCE, Alert);

### END
 
@samer800 Is it possible to change the color the lines? I struggle to see the blue line on the charts. Thanks
I adjusted the colors. You can change them from the settings as well.

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at http
#// © KivancOzbilgic
#//created by: @Anil_Ozeksi
#//developer: ANIL ÖZEK??
#study("Optimized Trend Tracker","OTT", overlay=true)
# Converted and mod by Sam4Cok@Samer800 11/2022
declare upper;
input BarColor  = no;
input ShowCloud = no;      #"Highlighter On/Off ?"
input MovAvgType = {default VAR, SMA, EMA, WMA, DEMA, TMA, WWMA, ZLEMA, TSF, HULL};
input Source    = close;#(close, title="Source")
input OttLength = 2;        # OTT Period
input OttCoeff  = 1.4;      # OTT Optimization Coeff
input showSupportLine = no; # "Show Support Line?"
input showBubbles = no;    # "Show Support Line Crossing Signals?"
input ColorOttLine = yes;    #="Show OTT Color Changes?"

def na = Double.NaN;

def c = Source;
def h = high;
def l = low;
def mPlot = ohlc4;
############## theme 3########################################
DefineGlobalColor("Sky1" , Color.CYAN);  # >=90
DefineGlobalColor("Sky2" , CreateColor(0,137,137));  # >=80
DefineGlobalColor("Magenta1" , Color.MAGENTA);  # >=40
DefineGlobalColor("Magenta2" , Color.PLUM);  # >=30

#Var_Func(src, length) =>
script Var_Func {
    input src    = close;
    input length = 0;
    def valpha = 2 / (length + 1);
    def vud1 = if src > src[1] then src - src[1] else 0;
    def vdd1 = if src < src[1] then src[1] - src else 0;
    def vUD = Sum(vud1, 9);
    def vDD = Sum(vdd1, 9);
    def vCMO = ((vUD - vDD) / (vUD + vDD));
    def VAR;
    VAR = CompoundValue(1, valpha * AbsValue(vCMO) * src + (1 - valpha * AbsValue(vCMO)) * (VAR[1]), src);
    plot result = VAR;
}
#Wwma_Func(src, length) =>
script Wwma_Func {
    input src = close;
    input length = 0;
    def wwalpha = 1 / length;
    def WWMA;
    WWMA = wwalpha * src + (1 - wwalpha) * (WWMA[1]);
    plot return = WWMA;
}
#Zlema_Func(src, length) =>
script Zlema_Func {
    input src = close;
    input length = 0;
    def zxLag = if length / 2 == Round(length / 2) then length / 2 else (length - 1) / 2;
    def zxEMAData = src + src - src[zxLag];
    def ZLEMA = ExpAverage(zxEMAData, length);
    plot return = ZLEMA;
}
#Tsf_Func(src, length) =>
script Tsf_Func {
    input src = close;
    input length = 0;
    def lrc = Inertia(src, length);
    def lrc1 = Inertia(src[1], length);
    def lrs = lrc - lrc1;
    def TSF = Inertia(src, length) + lrs;
    plot retur = TSF;
}
#Var_Funcl(srcl, length) =>
script Var_Funcl {
    input srcl = close;
    input length = 0;
    def valphal = 2 / (length + 1);
    def vud1l = if srcl > srcl[1] then srcl - srcl[1] else 0;
    def vdd1l = if srcl < srcl[1] then srcl[1] - srcl else 0;
    def vUDl = Sum(vud1l, 9);
    def vDDl = Sum(vdd1l, 9);
    def vCMOl = ((vUDl - vDDl) / (vUDl + vDDl));
    def VARl;
    VARl = CompoundValue(1, (valphal * AbsValue(vCMOl) * srcl) + (1 - valphal * AbsValue(vCMOl)) * (VARl[1]), srcl);
    plot return = VARl;
}
#Wwma_Funcl(srcl, length) =>
script Wwma_Funcl {
    input srcl = close;
    input length = 0;
    def wwalpha = 1 / length;
    def WWMA;
    WWMA = CompoundValue(1, wwalpha * srcl + (1 - wwalpha) * (WWMA[1]), srcl);
    plot return = WWMA;
}
#Zlema_Funcl(srcl, length) =>
script Zlema_Funcl {
    input srcl = close;
    input length = 0;
    def zxLag = if length / 2 == Round(length / 2,0) then length / 2 else (length - 1) / 2;
    def zxEMAData = srcl + srcl - srcl[zxLag];
    def ZLEMA = ExpAverage(zxEMAData, length);
    plot return = ZLEMA;
}
#Tsf_Funcl(srcl, length) =>
script Tsf_Funcl {
    input srcl = close;
    input length = 0;
    def lrc = Inertia(srcl, length);
    def lrc1 = Inertia(srcl[1], length);
    def lrs = lrc - lrc1;
    def TSF = Inertia(srcl, length) + lrs;
    plot retur = TSF;
}
#getMA(src, length, type) =>
script getMA {
    input src = close;
    input length = 100;
    input type   = "SMA";
    def ma;
    ma = if type == "SMA" then Average(src, length) else
     if type == "EMA" then ExpAverage(src, length) else
     if type == "WMA" then WMA(src, length) else
     if type == "DEMA" then DEMA(src, length) else
     if type == "TMA" then Average(SimpleMovingAvg(src, Ceil(length / 2)), Floor(length / 2) + 1) else
     if type == "VAR" then Var_Func(src, length) else
     if type == "WWMA" then WWMA_Func(src, length) else
     if type == "ZLEMA" then Zlema_Func(src, length) else
     if type == "TSF" then Tsf_Func(src, length) else
     if type == "HULL" then HullMovingAvg(src, length) else Double.NaN;
    plot result = ma;
}
#OTT(Source, percent) =>
script OTT {
    input Source    = close;
    input percent   = 0;
    def fark = Source * percent * 0.01;
    def UP = Source + fark;
    def LW = Source - fark;
    def UP_Band = if ((UP < UP_Band[1]) or (Source[1] > UP_Band[1])) then UP else UP_Band[1];
    def LW_Band = if ((LW > LW_Band[1]) or (Source[1] < LW_Band[1])) then LW else LW_Band[1];
    def MT = if ((MT[1] == UP_Band[1]) and (Source < UP_Band)) then UP_Band
        else if ((MT[1] == UP_Band[1]) and (Source > UP_Band)) then LW_Band
        else if ((MT[1] == LW_Band[1]) and (Source > LW_Band)) then LW_Band
        else if ((MT[1] == LW_Band)    and (Source < LW_Band)) then UP_Band
        else LW_Band;
    plot return = MT;
}
def MAvg = getMA(c, OttLength, MovAvgType);
def MT   = OTT(MAvg, OttCoeff);
def OTT = if MAvg > MT then MT * (200 + OttCoeff) / 200 else MT * (200 - OttCoeff) / 200;

plot SupportLine = if(!showSupportLine,na, MAvg);    # "Support Line"
SupportLine.SetDefaultColor(CreateColor(5,133,225));

def OTTC = if OTT[2] > OTT[3] then 2 else
           if OTT[2] < OTT[3] then -2 else
           if OTT[2] == OTT[3] and  MAvg>OTT[2] then 1 else
           if OTT[2] == OTT[3] and  MAvg<OTT[2] then -1 else 0;
plot OttLine  = if(isNaN(c),na,OTT);             # "OTT LINE"
OttLine.SetHiding(yes);
plot OttLine1 = if(isNaN(c),na,OTT[1]);          # "OTT LINE"
OttLine1.SetHiding(yes);
plot OttLine2 = if(isNaN(c),na,OTT[2]);          # "OTT LINE"
#OttLine2.SetHiding(yes);

OttLine2.SetLineWeight(2);
OttLine2.AssignValueColor(if !ColorOttLine then Color.CYAN else
                          if OTTC==2 then GlobalColor("Sky1") else
                          if OTTC==1 then GlobalColor("Sky2") else
                          if OTTC==-2 then GlobalColor("Magenta1") else
                          if OTTC==-1 then GlobalColor("Magenta2") else Color.GRAY);

def buySignalk  = crosses(MAvg, OTT[2],CrossingDirection.ABOVE);
def sellSignalk = crosses(MAvg, OTT[2],CrossingDirection.BELOW);
def SigCount = if (buySignalk or sellSignalk) then 1 else SigCount[1] + 1;
def buySignal = buySignalk and SigCount[1]>5;
def sellSignal = sellSignalk and SigCount[1]>5;

def longFillColor = if ShowCloud then if MAvg>OTT then yes else na else na;
def shortFillColor = if ShowCloud then if MAvg<OTT then yes else na else na;

#--- Clouds
AddCloud(if(longFillColor,mPlot,na), OttLine2, CreateColor(21,49,127),CreateColor(21,49,127));
AddCloud(if(shortFillColor,mPlot,na), OttLine2,CreateColor(81,20,92), CreateColor(81,20,92));

AddCloud(OttLine , OttLine2, CreateColor(21,49,127), CreateColor(81,20,92));
AddCloud(OttLine1, OttLine2, CreateColor(21,49,127), CreateColor(81,20,92));

#--- Bubbles
AddChartBubble(buySignal and showBubbles,l,"B", CreateColor(41,98,255), no);
AddChartBubble(sellSignal and showBubbles,h,"S", Color.MAGENTA,yes);

#--- Price Color
def ExtUp = OTT[2] > OTT[3] and Source>OttLine2 and mPlot>MAvg;
def Up    = mPlot>MAvg and Source>OttLine2;
def ExtDn = OTT[2] < OTT[3] and Source<OttLine2 and mPlot<MAvg;
def Dn    = mPlot<MAvg and Source<OttLine2;

AssignPriceColor(if !BarColor then Color.CURRENT else
                 if ExtUp then Color.GREEN else
                 if Up then Color.DARK_GREEN else
                 if ExtDn then Color.RED else
                 if Dn then Color.DARK_RED else Color.GRAY);

### END of CODE
 
I adjusted the colors. You can change them from the settings as well.

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at http
#// © KivancOzbilgic
#//created by: @Anil_Ozeksi
#//developer: ANIL ÖZEK??
#study("Optimized Trend Tracker","OTT", overlay=true)
# Converted and mod by Sam4Cok@Samer800 11/2022
declare upper;
input BarColor  = no;
input ShowCloud = no;      #"Highlighter On/Off ?"
input MovAvgType = {default VAR, SMA, EMA, WMA, DEMA, TMA, WWMA, ZLEMA, TSF, HULL};
input Source    = close;#(close, title="Source")
input OttLength = 2;        # OTT Period
input OttCoeff  = 1.4;      # OTT Optimization Coeff
input showSupportLine = no; # "Show Support Line?"
input showBubbles = no;    # "Show Support Line Crossing Signals?"
input ColorOttLine = yes;    #="Show OTT Color Changes?"

def na = Double.NaN;

def c = Source;
def h = high;
def l = low;
def mPlot = ohlc4;
############## theme 3########################################
DefineGlobalColor("Sky1" , Color.CYAN);  # >=90
DefineGlobalColor("Sky2" , CreateColor(0,137,137));  # >=80
DefineGlobalColor("Magenta1" , Color.MAGENTA);  # >=40
DefineGlobalColor("Magenta2" , Color.PLUM);  # >=30

#Var_Func(src, length) =>
script Var_Func {
    input src    = close;
    input length = 0;
    def valpha = 2 / (length + 1);
    def vud1 = if src > src[1] then src - src[1] else 0;
    def vdd1 = if src < src[1] then src[1] - src else 0;
    def vUD = Sum(vud1, 9);
    def vDD = Sum(vdd1, 9);
    def vCMO = ((vUD - vDD) / (vUD + vDD));
    def VAR;
    VAR = CompoundValue(1, valpha * AbsValue(vCMO) * src + (1 - valpha * AbsValue(vCMO)) * (VAR[1]), src);
    plot result = VAR;
}
#Wwma_Func(src, length) =>
script Wwma_Func {
    input src = close;
    input length = 0;
    def wwalpha = 1 / length;
    def WWMA;
    WWMA = wwalpha * src + (1 - wwalpha) * (WWMA[1]);
    plot return = WWMA;
}
#Zlema_Func(src, length) =>
script Zlema_Func {
    input src = close;
    input length = 0;
    def zxLag = if length / 2 == Round(length / 2) then length / 2 else (length - 1) / 2;
    def zxEMAData = src + src - src[zxLag];
    def ZLEMA = ExpAverage(zxEMAData, length);
    plot return = ZLEMA;
}
#Tsf_Func(src, length) =>
script Tsf_Func {
    input src = close;
    input length = 0;
    def lrc = Inertia(src, length);
    def lrc1 = Inertia(src[1], length);
    def lrs = lrc - lrc1;
    def TSF = Inertia(src, length) + lrs;
    plot retur = TSF;
}
#Var_Funcl(srcl, length) =>
script Var_Funcl {
    input srcl = close;
    input length = 0;
    def valphal = 2 / (length + 1);
    def vud1l = if srcl > srcl[1] then srcl - srcl[1] else 0;
    def vdd1l = if srcl < srcl[1] then srcl[1] - srcl else 0;
    def vUDl = Sum(vud1l, 9);
    def vDDl = Sum(vdd1l, 9);
    def vCMOl = ((vUDl - vDDl) / (vUDl + vDDl));
    def VARl;
    VARl = CompoundValue(1, (valphal * AbsValue(vCMOl) * srcl) + (1 - valphal * AbsValue(vCMOl)) * (VARl[1]), srcl);
    plot return = VARl;
}
#Wwma_Funcl(srcl, length) =>
script Wwma_Funcl {
    input srcl = close;
    input length = 0;
    def wwalpha = 1 / length;
    def WWMA;
    WWMA = CompoundValue(1, wwalpha * srcl + (1 - wwalpha) * (WWMA[1]), srcl);
    plot return = WWMA;
}
#Zlema_Funcl(srcl, length) =>
script Zlema_Funcl {
    input srcl = close;
    input length = 0;
    def zxLag = if length / 2 == Round(length / 2,0) then length / 2 else (length - 1) / 2;
    def zxEMAData = srcl + srcl - srcl[zxLag];
    def ZLEMA = ExpAverage(zxEMAData, length);
    plot return = ZLEMA;
}
#Tsf_Funcl(srcl, length) =>
script Tsf_Funcl {
    input srcl = close;
    input length = 0;
    def lrc = Inertia(srcl, length);
    def lrc1 = Inertia(srcl[1], length);
    def lrs = lrc - lrc1;
    def TSF = Inertia(srcl, length) + lrs;
    plot retur = TSF;
}
#getMA(src, length, type) =>
script getMA {
    input src = close;
    input length = 100;
    input type   = "SMA";
    def ma;
    ma = if type == "SMA" then Average(src, length) else
     if type == "EMA" then ExpAverage(src, length) else
     if type == "WMA" then WMA(src, length) else
     if type == "DEMA" then DEMA(src, length) else
     if type == "TMA" then Average(SimpleMovingAvg(src, Ceil(length / 2)), Floor(length / 2) + 1) else
     if type == "VAR" then Var_Func(src, length) else
     if type == "WWMA" then WWMA_Func(src, length) else
     if type == "ZLEMA" then Zlema_Func(src, length) else
     if type == "TSF" then Tsf_Func(src, length) else
     if type == "HULL" then HullMovingAvg(src, length) else Double.NaN;
    plot result = ma;
}
#OTT(Source, percent) =>
script OTT {
    input Source    = close;
    input percent   = 0;
    def fark = Source * percent * 0.01;
    def UP = Source + fark;
    def LW = Source - fark;
    def UP_Band = if ((UP < UP_Band[1]) or (Source[1] > UP_Band[1])) then UP else UP_Band[1];
    def LW_Band = if ((LW > LW_Band[1]) or (Source[1] < LW_Band[1])) then LW else LW_Band[1];
    def MT = if ((MT[1] == UP_Band[1]) and (Source < UP_Band)) then UP_Band
        else if ((MT[1] == UP_Band[1]) and (Source > UP_Band)) then LW_Band
        else if ((MT[1] == LW_Band[1]) and (Source > LW_Band)) then LW_Band
        else if ((MT[1] == LW_Band)    and (Source < LW_Band)) then UP_Band
        else LW_Band;
    plot return = MT;
}
def MAvg = getMA(c, OttLength, MovAvgType);
def MT   = OTT(MAvg, OttCoeff);
def OTT = if MAvg > MT then MT * (200 + OttCoeff) / 200 else MT * (200 - OttCoeff) / 200;

plot SupportLine = if(!showSupportLine,na, MAvg);    # "Support Line"
SupportLine.SetDefaultColor(CreateColor(5,133,225));

def OTTC = if OTT[2] > OTT[3] then 2 else
           if OTT[2] < OTT[3] then -2 else
           if OTT[2] == OTT[3] and  MAvg>OTT[2] then 1 else
           if OTT[2] == OTT[3] and  MAvg<OTT[2] then -1 else 0;
plot OttLine  = if(isNaN(c),na,OTT);             # "OTT LINE"
OttLine.SetHiding(yes);
plot OttLine1 = if(isNaN(c),na,OTT[1]);          # "OTT LINE"
OttLine1.SetHiding(yes);
plot OttLine2 = if(isNaN(c),na,OTT[2]);          # "OTT LINE"
#OttLine2.SetHiding(yes);

OttLine2.SetLineWeight(2);
OttLine2.AssignValueColor(if !ColorOttLine then Color.CYAN else
                          if OTTC==2 then GlobalColor("Sky1") else
                          if OTTC==1 then GlobalColor("Sky2") else
                          if OTTC==-2 then GlobalColor("Magenta1") else
                          if OTTC==-1 then GlobalColor("Magenta2") else Color.GRAY);

def buySignalk  = crosses(MAvg, OTT[2],CrossingDirection.ABOVE);
def sellSignalk = crosses(MAvg, OTT[2],CrossingDirection.BELOW);
def SigCount = if (buySignalk or sellSignalk) then 1 else SigCount[1] + 1;
def buySignal = buySignalk and SigCount[1]>5;
def sellSignal = sellSignalk and SigCount[1]>5;

def longFillColor = if ShowCloud then if MAvg>OTT then yes else na else na;
def shortFillColor = if ShowCloud then if MAvg<OTT then yes else na else na;

#--- Clouds
AddCloud(if(longFillColor,mPlot,na), OttLine2, CreateColor(21,49,127),CreateColor(21,49,127));
AddCloud(if(shortFillColor,mPlot,na), OttLine2,CreateColor(81,20,92), CreateColor(81,20,92));

AddCloud(OttLine , OttLine2, CreateColor(21,49,127), CreateColor(81,20,92));
AddCloud(OttLine1, OttLine2, CreateColor(21,49,127), CreateColor(81,20,92));

#--- Bubbles
AddChartBubble(buySignal and showBubbles,l,"B", CreateColor(41,98,255), no);
AddChartBubble(sellSignal and showBubbles,h,"S", Color.MAGENTA,yes);

#--- Price Color
def ExtUp = OTT[2] > OTT[3] and Source>OttLine2 and mPlot>MAvg;
def Up    = mPlot>MAvg and Source>OttLine2;
def ExtDn = OTT[2] < OTT[3] and Source<OttLine2 and mPlot<MAvg;
def Dn    = mPlot<MAvg and Source<OttLine2;

AssignPriceColor(if !BarColor then Color.CURRENT else
                 if ExtUp then Color.GREEN else
                 if Up then Color.DARK_GREEN else
                 if ExtDn then Color.RED else
                 if Dn then Color.DARK_RED else Color.GRAY);

### END of CODE
Thank you! @samer800
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
455 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top