#// © bartua
#// Optimized Trend Tracker function under copyright and courtesy of KivancOzbilgic.
# https://www.tradingview.com/script/gztIGBjt-RSI-Wave-Signals/
# indicator("RSI Wave Signals", overlay=false)
# Converted and mod by Sam4Cok@Samer800 11/2022
declare lower;
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;
input length = 2; # OTT Period
input percent = 0.7; # OTT Optimization Coeff
input rsiLength = 12; # "RSI Period"
input overBought = 60; # "Over Bought Limit"
input overSold = 40; # "Over Sold Limit"
input showSignals = yes; # "Show Support Line Crossing Signals?"
input ColorOttLine = no; #="Show OTT Color Changes?"
def na = Double.NaN;
def c = Source;
def h = high;
def l = low;
def mPlot = ohlc4;
#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 nRsi = RSI(Length = rsiLength) + 1000;
def MAvg = getMA(nRsi, length, MovAvgType);
def MT = OTT(MAvg, percent);
def OTT = if MAvg > MT then MT * (200 + percent) / 200 else MT * (200 - percent) / 200;
plot SupportLine = MAvg; # "Support Line"
SupportLine.SetDefaultColor(CreateColor(5, 133, 225));
def OTTC = if ColorOttLine then if OTT[2] > OTT[3] then 1 else -1 else 0;
plot pALL = If(IsNaN(c), na, OTT[2]); # "OTT LINE"
pALL.SetLineWeight(2);
pALL.AssignValueColor(if OTTC > 0 then Color.GREEN else
if OTTC < 0 then Color.RED else CreateColor(255, 82, 82));
def overSoldLevel = overSold + 1000;
def overBoughtLevel = overBought + 1000;
plot midLine = if(isNaN(c),na,(overSoldLevel + overBoughtLevel) / 2);
midLine.SetDefaultColor(Color.DARK_GRAY);
midLine.SetStyle(Curve.SHORT_DASH);
plot obLevel = if(isNaN(c),na,overBoughtLevel);
obLevel.SetDefaultColor(Color.GRAY);
obLevel.SetStyle(Curve.MEDIUM_DASH);
plot osLevel = if(isNaN(c),na,overSoldLevel);
osLevel.SetDefaultColor(Color.GRAY);
osLevel.SetStyle(Curve.MEDIUM_DASH);
#---- Signals
def buySignalk = If(showSignals, Crosses(MAvg, OTT[2], CrossingDirection.ABOVE), na);
def sellSignalk = If(showSignals, Crosses(MAvg, OTT[2], CrossingDirection.BELOW), na);
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;
plot buySignal = if buySignalk then pALL else na;
buySignal.SetStyle(Curve.POINTS);
buySignal.SetDefaultColor(Color.GREEN);
buySignal.SetLineWeight(3);
plot sellSignal = if sellSignalk then pALL else na;
sellSignal.SetStyle(Curve.POINTS);
sellSignal.SetDefaultColor(Color.RED);
sellSignal.SetLineWeight(3);
#--- Clouds
AddCloud(If(longFillColor, Double.POSITIVE_INFINITY, na), Double.NEGATIVE_INFINITY, Color.DARK_GREEN, Color.DARK_GREEN);
AddCloud(If(shortFillColor, Double.POSITIVE_INFINITY, na), Double.NEGATIVE_INFINITY, Color.DARK_RED, Color.DARK_RED);
#--- Bubbles
#--- Price Color
def ExtUp = MAvg>pALL and MAvg>=MAvg[1] and pALL>=pALL[1];
def Up = MAvg>pALL and MAvg<MAvg[1] and pALL<pALL[1];
def ExtDn = MAvg<pALL and MAvg<=MAvg[1] and pALL<=pALL[1];
def Dn = MAvg<pALL and MAvg>MAvg[1] and pALL>pALL[1];
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 CODE