this is based on OTT code from @KivancOzbilgic.
CODE:
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 = yes; #"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 = yes; # "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" , CreateColor(0,221,255)); # >=90
DefineGlobalColor("Sky2" , CreateColor(4,188,217)); # >=80
DefineGlobalColor("Sky3" , CreateColor(4,156,179)); # >=70
DefineGlobalColor("Sky4" , CreateColor(4,127,145)); # >=60
DefineGlobalColor("Sky5" , CreateColor(4,103,117)); # >=50
DefineGlobalColor("Magenta1" , CreateColor(216,0,255)); # >=40
DefineGlobalColor("Magenta2" , CreateColor(187,4,219)); # >=30
DefineGlobalColor("Magenta3" , CreateColor(155,5,181)); # >=20
DefineGlobalColor("Magenta4" , CreateColor(123,3,143)); # >=10
DefineGlobalColor("Magenta5" , CreateColor(100,2,117)); # >=0
#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 = valpha * AbsValue(vCMO) * src + (1 - valpha * AbsValue(vCMO)) * (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) * (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 = (valphal * AbsValue(vCMOl) * srcl) + (1 - valphal * AbsValue(vCMOl)) * (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) * (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 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 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(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 CreateColor(41,98,255) else
if OTTC==1 then CreateColor(21,49,127) else
if OTTC==-2 then CreateColor(156,39,176) else
if OTTC==-1 then CreateColor(81,20,92) 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