Creator Message: https://www.tradingview.com/v/X72V8xjH/
CODE:
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © traderharikrishna
#https://www.tradingview.com/v/X72V8xjH/
#indicator("Smart QQE",overlay=true)
#// Credits to Glaz
#// Rescaled for overlay by @traderharikrishna
# Converted by Sam4Cok@Samer800 - 03/2023
input ColorBars = yes; # 'color bars?'
input ShowRsiCloud = yes;
input src = close; # 'RSI Source'
input rsiMaType1 = {SMA, default EMA, RMA, WMA, VWMA, DEMA, TEMA, HMA, ALMA, SWMA, PEMA, LSMA};
input RSI_Period1 = 14; # 'RSI Length'
input rsiMaType2 = {"EMA", "HMA", default "SMA", "WMA", "RMA", "VWMA"}; # 'RSI MA Type'
input RSI_Period2 = 50; # 'RSI 100 level'
input RsiSmoothing = 5; # 'RSI Smoothing'
input FastQqeFactor = 4.238; # 'Fast QQE Factor'
input ThreshHold = 10; # 'Thresh-hold'
input alma_offset = 0.85; # '* Arnaud Legoux (ALMA) Only - Offset Value'
input alma_sigma = 6; # '* Arnaud Legoux (ALMA) Only - Sigma Value'
def na = Double.NaN;
#---- Color
DefineGlobalColor("blue" , CreateColor(7, 196, 243));
DefineGlobalColor("red" , CreateColor(247, 4, 117));
DefineGlobalColor("orange" , CreateColor(255, 152, 0));
DefineGlobalColor("dgreen" , CreateColor(20, 78, 05));
DefineGlobalColor("dred" , CreateColor(134, 3, 3));
DefineGlobalColor("yellow" , CreateColor(241,226,14));
#// ] -------------- FUNCTIONS : Moving Avg ------------------ [
script nz {
input data = close;
input repl = 0;
def ret_val = if !IsNaN(data) then data else repl;
plot return = ret_val;
}
#pine_swma(source) =>
script swma {
input source = close;
def swma = source[3] * 1 / 6 + source[2] * 2 / 6 + source[1] * 2 / 6 + source[0] * 1 / 6;
plot retun = swma;
}
#pine_alma(series, windowsize, offset, sigma) =>
script ALMA {
input series = close;
input windowsize = 9;
input Offset = 0.85;
input Sigma = 6;
def m = Offset * (windowsize - 1);
def s = windowsize / Sigma;
def norm = fold z = 0 to windowsize with CW do
CW + Exp(-(Sqr(z - m)) / (2 * Sqr(s)));
def sum = fold y = 0 to windowsize with WS do
WS + Exp(-(Sqr(y - m)) / (2 * Sqr(s))) * GetValue(series, windowsize - 1 - y);
plot ALMA = sum / norm ;
}
#vwma(source, length)
script VWMA {
input src = close;
input len = 15;
def v = volume;
def VWMA = SimpleMovingAvg(src * nz(v, 1), len) / SimpleMovingAvg(nz(v, 1), len);
plot result = VWMA;
}
#export multiMa(float source, simple int length, string type) =>
script Ma {
input type = "SMA";
input source = close;
input length = 14;
input alma_offset = 0.85;
input alma_sigma = 6;
def ema1 = ExpAverage(source, length);
def ema2 = ExpAverage(ema1, length);
def ema3 = ExpAverage(ema2, length);
def ema4 = ExpAverage(ema3, length);
def ema5 = ExpAverage(ema4, length);
def ema6 = ExpAverage(ema5, length);
def ema7 = ExpAverage(ema6, length);
def ema8 = ExpAverage(ema7, length);
def pema = 8 * ema1 - 28 * ema2 + 56 * ema3 - 70 * ema4 + 56 * ema5 - 28 * ema6 + 8 * ema7 - ema8;
def multiMa =
if type == "SMA" then SimpleMovingAvg(source, length) else
if type == "EMA" then ExpAverage(source, length) else
if type == "RMA" then WildersAverage(source, length) else
if type == "WMA" then WMA(source, length) else
if type == "VWMA" then vwma(source, length) else
if type == "DEMA" then DEMA(source, length) else
if type == "TEMA" then TEMA(source, length) else
if type == "LSMA" then Inertia(source, length) else
if type == "PEMA" then pema else
if type == "ALMA" then ALMA(source, length, alma_offset, alma_sigma) else
if type == "SWMA" then SWMA(source) else
if type == "HMA" then HullMovingAvg(source, length) else Double.NaN;
plot return = multiMa;
}
def Wilders_Period = RSI_Period1 * 2 - 1;
def Rsi = RSI(PRICE = src, LENGTH = RSI_Period1);
def RsiMa = Ma(rsiMaType1, Rsi, RsiSmoothing , alma_offset, alma_sigma);
def AtrRsi = AbsValue(RsiMa[1] - RsiMa);
def MaAtrRsi = Ma(rsiMaType1, AtrRsi, Wilders_Period, alma_offset, alma_sigma);
def dar = Ma(rsiMaType1, MaAtrRsi, Wilders_Period, alma_offset, alma_sigma) * FastQqeFactor;
def longband;# = 0.0
def shortband;# = 0.0
def trendx;# = 0
def DeltaFastAtrRsi = dar;
def RSIndex = RsiMa;
def newshortband = RSIndex + DeltaFastAtrRsi;
def newlongband = RSIndex - DeltaFastAtrRsi;
longband = if RSIndex[1] > longband[1] and RSIndex > longband[1] then Max(longband[1], newlongband) else newlongband;
shortband = if RSIndex[1] < shortband[1] and RSIndex < shortband[1] then Min(shortband[1], newshortband) else newshortband;
def cross_1 = Crosses(longband[1], RSIndex);
trendx = if Crosses(RSIndex, shortband[1]) then 1 else if cross_1 then -1 else nz(trendx[1], 1);
def FastAtrRsiTL = if trendx == 1 then longband else shortband;
#//
#// Find all the QQE Crosses
def QQExlong;# = 0
def QQExshort;# = 0
def QQExlong1 = nz(QQExlong[1]);
def QQExshort1 = nz(QQExshort[1]);
QQExlong = if FastAtrRsiTL < RSIndex then QQExlong1 + 1 else 0;
QQExshort = if FastAtrRsiTL > RSIndex then QQExshort1 + 1 else 0;
def hcolor = if RsiMa - 50 > ThreshHold then 1 else
if RsiMa - 50 < 0 - ThreshHold then -1 else 0;
#//EOF
AssignPriceColor(if !ColorBars then Color.CURRENT else
if hcolor > 0 then GlobalColor("blue") else
if hcolor < 0 then GlobalColor("red") else GlobalColor("orange"));
def nATR = ATR(Length = 100);
def orsi = RSI(PRICE = close, LENGTH = RSI_Period1);
def adjrsi = close + nATR * orsi / 100;
def rma = Ma(rsiMaType2, adjrsi, RSI_Period2);
def rsi100 = rma + nATR * (50 / 10);
def rsi0 = rma - nATR * (50 / 10);
def r100 = rsi100;
def r0 = rsi0;
def rsi90 = rma + nATR * (30 / 10);
def rsi10 = rma - nATR * (30 / 10);
def r90 = rsi90;
def r10 = rsi10;
AddCloud(r100, r90, Color.DARK_RED, Color.DARK_RED, yes); # 'Overbought'
AddCloud(r10, r0, Color.DARK_GREEN, Color.DARK_GREEN, yes); # 'Oversold'
plot midBand = rma;
midBand.AssignValueColor(if open>rma then GlobalColor("blue") else if open<rma then Color.RED else GlobalColor("yellow"));
def rsim = rma + nATR * (RsiMa - 50) / 10;
def frsim = rma + nATR * (FastAtrRsiTL - 50) / 10;
def QQE_RSI = if ShowRsiCloud then Ma(rsiMaType1, rsim, RsiSmoothing) else na;
def Fast_RSI = Ma(rsiMaType1, frsim, RsiSmoothing);
AddCloud(QQE_RSI,Fast_RSI,GlobalColor("dgreen"), GlobalColor("dred")); # 'QQE Trend'
def qqeLong = if QQExlong == 1 then frsim else na;
def qqeShort = if QQExshort == 1 then frsim else na;
AddChartBubble(qqeLong,low, "Long", Color.GREEN, no);
AddChartBubble(qqeShort, high, "Short", Color.RED, yes);
#--- END CODE
Last edited by a moderator: