Triple Confirmation Kernel Regression Overlay [QuantraAI] For ThinkOrSwim

Minefieldhopscotch

New member
VIP
The author states:
The Kernel Regression Oscillator (ᏦᏒᎧ) represents an advanced tool for traders looking to capitalize on market trends.
This Indicator is valuable in identifying and confirming trend directions, as well as probabilistic and dynamic oversold and overbought zones.

It achieves this through a unique composite approach using three distinct Kernel Regressions combined in an Oscillator.
The additional Chart Overlay Indicator adds confidence to the signal.
Which is this Indicator.

This methodology helps the trader to significantly reduce false signals and offers a more reliable indication of market movements than more widely used indicators can.
GbspiW3.png


Triple Confirmation Kernel Regression Overlay [QuantraAI]
https://www.tradingview.com/script/QbkEr6o9-Triple-Confirmation-Kernel-Regression-Overlay-QuantraAI/

Could this be converted to thinkscript? Thank you both for all that you do for our benefit.
 
Last edited by a moderator:
Upper Study -
CSS:
#https://www.tradingview.com/v/6VgJlewW/
#// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla
#// © QuantraAI
#indicator("Triple Confirmation Kernel Regression Oscillator [QuantraAI]", [QuantraAI]"
# Cconverted and mod to upper study by Sam4Cok@Samer800 - 12/2023

#// Kernel Regression Settings
input BarColoring = yes;      # "Enable Bar Coloring"
input showSignals = yes;      # "Enable Overbought/Oversold Shading"
input source    = close;    # "Source"
input bandwidth = 45;       # "Bandwidth"
input RelativeWeighting = 2.0;   # 'Relative weighting of time frames. Recommended range: 0.25-25'
input stdevLength = 150;
input sdevMulti = 3.0;      # "Standard Deviation Extreme for OB/OS Border"
input stdevMultiplier = 2.0; #,          "Standard Deviation Extreme for OB/OS Border",


def na = Double.NaN;
def last = isNaN(close);

DefineGlobalColor("up", CreateColor(95, 250, 224));
DefineGlobalColor("dn", CreateColor(194, 46, 208));
DefineGlobalColor("dup",CreateColor(3, 106, 89));
DefineGlobalColor("ddn", CreateColor(89, 21, 96));

#//    Functions    //
#epanechnikov(source, bandwidth) =>
Script epanechnikov {
input source = close;
input bandwidth = 45;
input width = 1;
    def sum = fold i = 0 to bandwidth with p do
            p + source[i] * (if AbsValue((Sqr(i) / Sqr(bandwidth))/width) <= 1 then
                    (3/4) * (1 - Sqr((Sqr(i) / Sqr(bandwidth))/width)) else 0);
    def sumw = fold j = 0 to bandwidth with q do
            q + (if AbsValue((Sqr(j) / Sqr(bandwidth))/width) <= 1 then
                (3/4) * (1 - Sqr((Sqr(j) / Sqr(bandwidth))/width)) else 0);
    def kernel_regression = (sum / sumw);
    plot out = kernel_regression;
}
#logistic(source, bandwidth) =>
Script logistic {
input source = close;
input bandwidth = 45;
input width = 1;
    def sum = fold i = 0 to bandwidth with p do
            p + source[i] * (1 / (Exp((Sqr(i) / Sqr(bandwidth)) / width) + 2
              + Exp(-(Sqr(i) / Sqr(bandwidth)) / width)));
    def sumw = fold j = 0 to bandwidth with q do
            q + (1 / (Exp((Sqr(j) / Sqr(bandwidth)) / width) + 2
              + Exp(-(Sqr(j) / Sqr(bandwidth)) / width)));
    def kernel_regression = (sum / sumw);
    plot out = kernel_regression;
}
#wave(source, bandwidth) =>
Script wave {
input source = close;
input bandwidth = 45;
input width = 1;
    def pi = Double.Pi;
    def sum = fold i = 0 to bandwidth with p do
        p + source[i] * (if (AbsValue((Sqr(i) / Sqr(bandwidth))/width) <= 1) then
          (1 - AbsValue((Sqr(i) / Sqr(bandwidth))/width)) * Cos(pi * (Sqr(i) / Sqr(bandwidth)) / width)  else 0);
    def sumw = fold j = 0 to bandwidth with q do
        q + (if (AbsValue((Sqr(j) / Sqr(bandwidth))/width) <= 1) then
          (1 - AbsValue((Sqr(j) / Sqr(bandwidth))/width)) * Cos(pi * (Sqr(j) / Sqr(bandwidth)) / width)  else 0);
    def kernel_regression = (sum / sumw);
    plot out = kernel_regression;
}
Script waveCalculation {
input source = close;
input bandwidth = 45;
input width = 2;
    def pi = Double.Pi;
    def sum = fold i = 0 to bandwidth  with p do
        p + source[i] * (if ((i * i) / (bandwidth * bandwidth) / width) <= 1 then
            (1 - ((i * i) / (bandwidth * bandwidth) / width)) * cos(pi * ((i * i) / (bandwidth * bandwidth) / width)) else 0.0);
    def sumw = fold j = 0 to bandwidth with q do
               q + (if ((j * j) / (bandwidth * bandwidth) / width) <= 1 then
            (1 - ((j * j) / (bandwidth * bandwidth) / width)) * cos(pi * ((j * j) / (bandwidth * bandwidth) / width)) else 0.0);
    def kernel_regression = sum / sumw;
    plot out = kernel_regression;
}

#// Triple Confirmations
def Wav = waveCalculation(source, bandwidth, RelativeWeighting);
def Ep = epanechnikov(source, bandwidth, RelativeWeighting);
def Lo = logistic(source, bandwidth, RelativeWeighting);
def Wa = wave(source, bandwidth, RelativeWeighting);
def up = Wav>Wav[1];            # 'Wave'
def dn = wav<wav[1];
#// Average
def AV = Average((Ep + Lo + Wa) / 3, 1);
def Mid = Average(AV, stdevLength);
#// Base Plots
plot pAV = Wav;
def Epanechnikov = Ep;    # 'Epanechnikov'
def Logistic = Lo;        # 'Logistic'

pAV.SetLineWeight(2);
pAV.AssignValueColor(if up then GlobalColor("up") else if dn then GlobalColor("dn") else Color.GRAY);

#// Calculate Dynamic OB/OS Zones
def basis = Average(AV, stdevLength);
def dev   = stdev(AV, stdevLength);
def u1    = basis + sdevMulti/2 * dev;
def l1    = basis - sdevMulti/2 * dev;
def u2    = basis + sdevMulti * dev;
def l2    = basis - sdevMulti * dev;

##// Final Plots + Fill
plot avg = basis;
plot pu1 = u1;
plot pl1 = l1;
def pu2 = u2;
def pl2 = l2;

avg.SetDefaultColor(Color.GRAY);
pu1.SetDefaultColor(GlobalColor("dn"));
pl1.SetDefaultColor(GlobalColor("up"));

AssignPriceColor(if !BarColoring then Color.CURRENT else
                 if up and wav > av then Color.GREEN else #GlobalColor("up") else
                 if up then Color.DARK_GREEN else
                 if dn and wav < av then GlobalColor("dn") else
                 if dn then Color.PLUM else Color.GRAY);


AddCloud(if source > pAV then pAV - (pAV - source)/2 else na,pAV , GlobalColor("dup"));
AddCloud(if source > pAV then na else pAV, pAV + (source - pAV)/2, GlobalColor("ddn"));

AddCloud(pu2, pu1, GlobalColor("ddn"));
AddCloud(pl1, pl2, GlobalColor("dup"));

def sigUp = av > (l1 - (l1-l2)/2);# and av > av[1];
def sigDn = av < (u1 + (u2-u1)/2);# and av < av[1];

def sig = if showSignals then (if sigUp and !sigUp[1] then  1 else
                               if sigDn and !sigDn[1] then -1 else 0) else na;
# and sig[1]<0;
#def arrUp = Wac > Wac[1];# and !(Wac[1] > Wac[2]);
#def arrDn = Wac < Wac[1];# and !(Wac[1] < Wac[2]);

AddChartBubble(sig>0, low, "B", Color.GREEN, no);
AddChartBubble(sig<0, high, "S", Color.RED);


#-- END of CODE

Lower Study -

CSS:
#https://www.tradingview.com/script/tQ7O9bpf-Triple-Confirmation-Kernel-Regression-Base-QuantraAI/
#// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla
#// © QuantraAI
# indicator("Triple Confirmation Kernel Regression Oscillator Base [QuantraAI]",  "??? ???? [QuantraAI]"
# Converted by Sam4Cok@Samer800    - 12/2023

declare lower;
#// Kernel Regression Settings
input BarColoring = yes;                    # "Enable Bar Coloring"
input OverboughtOversoldShading = yes;      # "Enable Overbought/Oversold Shading"
input source    = close;    # "Source"
input bandwidth = 45;       # "Bandwidth"
input stdevMultiplier = 2.0; #,          "Standard Deviation Extreme for OB/OS Border",
input RelativeWeighting = 1.0;   # 'Relative weighting of time frames. Recommended range: 0.25-25'
input UseZeroAsMidLine = no;
input StandardDeviationLookback = 150;


def na = Double.NaN;
def last = isNaN(close);
def sdLook = StandardDeviationLookback;
def Mean = UseZeroAsMidLine;
def sdMult = stdevMultiplier;
DefineGlobalColor("up", CreateColor(95, 250, 224));
DefineGlobalColor("dn", CreateColor(194, 46, 208));
DefineGlobalColor("dup",CreateColor(3, 106, 89));
DefineGlobalColor("ddn", CreateColor(89, 21, 96));
DefineGlobalColor("BgU", CreateColor(6, 182, 153));
DefineGlobalColor("BgD", CreateColor(149, 35, 160));

#//    Functions    //
#epanechnikov(source, bandwidth) =>
Script epanechnikov {
input source = close;
input bandwidth = 45;
input width = 1;
    def sum = fold i = 0 to bandwidth with p do
            p + source[i] * (if AbsValue((Sqr(i) / Sqr(bandwidth))/width) <= 1 then
                    (3/4) * (1 - Sqr((Sqr(i) / Sqr(bandwidth))/width)) else 0);
    def sumw = fold j = 0 to bandwidth with q do
            q + (if AbsValue((Sqr(j) / Sqr(bandwidth))/width) <= 1 then
                (3/4) * (1 - Sqr((Sqr(j) / Sqr(bandwidth))/width)) else 0);
    def kernel_regression = (source - sum / sumw) / source;
    plot out = kernel_regression;
}
#logistic(source, bandwidth) =>
Script logistic {
input source = close;
input bandwidth = 45;
input width = 1;
    def sum = fold i = 0 to bandwidth with p do
            p + source[i] * (1 / (Exp((Sqr(i) / Sqr(bandwidth)) / width) + 2
              + Exp(-(Sqr(i) / Sqr(bandwidth)) / width)));
    def sumw = fold j = 0 to bandwidth with q do
            q + (1 / (Exp((Sqr(j) / Sqr(bandwidth)) / width) + 2
              + Exp(-(Sqr(j) / Sqr(bandwidth)) / width)));
    def kernel_regression = (source - sum / sumw) / source;
    plot out = kernel_regression;
}
#wave(source, bandwidth) =>
Script wave {
input source = close;
input bandwidth = 45;
input width = 1;
    def pi = Double.Pi;
    def sum = fold i = 0 to bandwidth with p do
        p + source[i] * (if (AbsValue((Sqr(i) / Sqr(bandwidth))/width) <= 1) then
          (1 - AbsValue((Sqr(i) / Sqr(bandwidth))/width)) * Cos(pi * (Sqr(i) / Sqr(bandwidth)) / width)  else 0);
    def sumw = fold j = 0 to bandwidth with q do
        q + (if (AbsValue((Sqr(j) / Sqr(bandwidth))/width) <= 1) then
          (1 - AbsValue((Sqr(j) / Sqr(bandwidth))/width)) * Cos(pi * (Sqr(j) / Sqr(bandwidth)) / width)  else 0);
    def kernel_regression = (source - sum / sumw) / source;
    plot out = kernel_regression;
}
#// Triple Confirmations
def Ep = epanechnikov(source, bandwidth, RelativeWeighting);
def Lo = logistic(source, bandwidth, RelativeWeighting);
def Wa = wave(source, bandwidth, RelativeWeighting);

#// Average
def AV = (Ep + Lo + Wa) / 3;
#// Base Plots
plot pAV = AV;
plot Epanechnikov = Ep;    # 'Epanechnikov'
plot Logistic = Lo;        # 'Logistic'
plot Wave = Wa;            # 'Wave'
plot mid = if last then na else if Mean then 0 else Average(AV, sdLook);

pAV.SetLineWeight(2);
pAV.AssignValueColor(if AV>0 then GlobalColor("up") else GlobalColor("dn"));
Epanechnikov.AssignValueColor(if AV>0 then GlobalColor("dup") else GlobalColor("ddn"));
Logistic.AssignValueColor(if AV>0 then GlobalColor("dup") else GlobalColor("ddn"));
Wave.AssignValueColor(if AV>0 then GlobalColor("dup") else GlobalColor("ddn"));
mid.SetDefaultColor(Color.GRAY);

#// Calculate Dynamic OB/OS Zones
def basis = Average(AV, sdLook);
def dev   = stdev(AV, sdLook);
def u1    = basis + dev * sdMult/2;
def l1    = basis - dev * sdMult/2;
def u2    = basis + dev * sdMult;
def l2    = basis - dev * sdMult;

##// Final Plots + Fill
plot pu1 = u1;
plot pl1 = l1;
def pu2 = u2;
def pl2 = l2;

pu1.SetDefaultColor(GlobalColor("dn"));
pl1.SetDefaultColor(GlobalColor("up"));


AssignPriceColor(if !BarColoring then Color.CURRENT else
                 if AV > 0 then GlobalColor("up") else GlobalColor("dn"));

AddCloud(if pAV > 0 then pAV else na, pAV/2, GlobalColor("dup"));
AddCloud(if pAV > 0 then na else pAV/2, pAV, GlobalColor("ddn"));

AddCloud(pu2, pu2 - (pu2-pu1)/2, GlobalColor("ddn"));
AddCloud(pl2 + (pl1-pl2)/2, pl2, GlobalColor("dup"));

def pos = Double.POSITIVE_INFINITY;
def neg = Double.NEGATIVE_INFINITY;
def sig = if OverboughtOversoldShading then (if AV > u2 then -1 else
          if AV < l2 then 1 else 0) else 0;
def sigUp = sig>0 or sig[-1]>0;
def sigDn = sig<0 or sig[-1]<0;
AddCloud(if sigDn then pos else na, neg, GlobalColor("bgD"));
AddCloud(if sigUp then pos else na, neg, GlobalColor("bgU"));

#-- END of CODE
 
Last edited by a moderator:
Is there anyway to have the candle change color, lets say white, when these trigger?

Rich (BB code):
AddCloud(if sigDn then pos else na, neg, GlobalColor("bgD"));
AddCloud(if sigUp then pos else na, neg, GlobalColor("bgU"));

or hopefully this clarifies, to candle change color when it breaches

Rich (BB code):
AddCloud(pu2, pu2 - (pu2-pu1)/2, GlobalColor("ddn"));
AddCloud(pl2 + (pl1-pl2)/2, pl2, GlobalColor("dup"));
 

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

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
401 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