JCFBaux Volatility [Loxx] for ThinkOrSwim

Find below:

9rP2Poi.png


CSS:
#https://www.tradingview.com/script/fSTqdHYh-JCFBaux-Volatility-Loxx/
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © loxx
#indicator("JCFBaux Volatility [Loxx]", shorttitle = "JCFBV [Loxx]",
#Converted by Sam4Cok@Samer800        - 04/2023
declare lower;

input src     = close;         # "Source"
input depth   = 15;            # "Depth"
input JuirkPhase   = 0;        # "Signal - Juirk Smoothing Phase"
input SignalPeriod = 300;      # "Signal - Period"
input colorBars = yes;         # "Color bars?"
input showSignals = yes;       # "Show signals?"

def na = Double.NaN;
def lensmdd = SignalPeriod;
script nz {
    input data  = close;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}
#jurik_filt(float src, int len, float phase) =>
script jurik_filt {
    input src = close;
    input len = 34;
    input phase = 0;
#    //static variales
    def volty;
    def avolty;
    def vsum;
    def bsmax;
    def bsmin;
    def kv;
    def pow2;
    def dVolty;
    def len1 = Max(Log(Sqrt(0.5 * (len - 1))) / Log(2.0) + 2.0, 0);
    def len2 = Sqrt(0.5 * (len - 1)) * len1;
    def pow1 = Max(len1 - 2.0, 0.5);
    def beta = 0.45 * (len - 1) / (0.45 * (len - 1) + 2);
    def div = 1.0 / (10.0 + 10.0 * (Min(Max(len - 10, 0), 100)) / 100);
    def phaseRatio = if phase < -100 then 0.5 else
                     if phase >  100 then 2.5 else 1.5 + phase * 0.01;
    def bet = len2 / (len2 + 1);
#    //Price volatility
    def del1 = CompoundValue(1, src - bsmax[1], 0);
    def del2 = CompoundValue(1, src - bsmin[1], 0);
    volty = if AbsValue(del1) > AbsValue(del2) then AbsValue(del1) else AbsValue(del2);
#    //Relative price volatility factor
    vsum   = CompoundValue(1, vsum[1] + div * (volty - volty[10]), 0);
    avolty = CompoundValue(1, avolty[1] + (2.0 / (Max(4.0 * len, 30) + 1.0)) * (vsum - avolty[1]), 0);
    def dVolt = if avolty > 0 then volty / avolty else 0;
    dVolty = Max(1, Min(Power(len1, 1.0 / pow1), dVolt));
#   //Jurik volatility bands
    pow2 = Power(dVolty, pow1);
    Kv   = Power(bet, Sqrt(pow2));
    bsmax = if del1 > 0 then src else src - Kv * del1;
    bsmin = if del2 < 0 then src else src - Kv * del2;
#    //Jurik Dynamic Factor
    def alpha = Power(beta, pow2);
#    //1st stage - prelimimary smoothing by adaptive EMA
    def jrkout;
    def ma1;
    def det0;
    def e2;
    ma1 = CompoundValue(1, (1 - alpha) * src + alpha * ma1[1], 0);
#    //2nd stage - one more prelimimary smoothing by Kalman filter
    det0 = CompoundValue(1, (src - ma1) * (1 - beta) + beta * det0[1], 0);
    def ma2 = ma1 + phaseRatio * det0;
#    //3rd stage - final smoothing by unique Jurik adaptive filter
    e2     = CompoundValue(len, (ma2 - jrkout[1]) * Power(1 - alpha, 2) + Power(alpha, 2) * e2[1], 0);
    jrkout = CompoundValue(len, e2 + jrkout[1], src);
    plot return = jrkout;
}
#/ @function jcfbaux
#jcfbaux(float src, float depth) =>
script jcfbaux {
    input src = close;
    input depth = 15;
    def bar_index = AbsValue(CompoundValue(1, BarNumber(), 0));
    def cond  = (bar_index >= bar_index - depth * 2);
    def cond1 = (bar_index < bar_index - depth * 2);
    def start = Ceil(depth) - 1;
    def jrc04;
    def jrc05;
    def jrc06;
    def jrc08;
    if cond {
        jrc04 = fold k = 0 to start + 1 with p do
                p + AbsValue(GetValue(src,start - k) - GetValue(src,start - k + 1));
        jrc05 = fold k1 = 0 to start + 1 with p1 do
                p1 + (depth + start-k1) * AbsValue(GetValue(src, start-k1) - GetValue(src,start - k1 + 1));
        jrc06 = fold k2 = 0 to start + 1 with p2 do
                p2 + GetValue(src,start - k2 + 1);
    } else
    if cond1 {
        jrc04 = jrc04[1] - AbsValue(nz(src[depth]) - nz(src[depth + 1])) + AbsValue(src - src[1]);
        jrc05 = jrc05[1] - jrc04 + AbsValue(src - src[1]) * depth;
        jrc06 = jrc06[1] - nz(src[depth + 1]) + src[1];
    } else {
        jrc04 = jrc04[1];
        jrc05 = jrc05[1];
        jrc06 = jrc06[1];
    }
        jrc08 = AbsValue(depth * src - jrc06);
    def jcfbaux = if jrc05 == 0.0 then 0.0 else jrc08 / jrc05;
    plot out = jcfbaux;
}
def jcfbaux = jcfbaux(src, depth);
def signal = jurik_filt(jcfbaux, lensmdd, JuirkPhase);

plot Sig = signal;
plot jcfbauxLine = jcfbaux;

Sig.SetDefaultColor(Color.WHITE);
jcfbauxLine.AssignValueColor(if jcfbaux >= signal then Color.GREEN else Color.GRAY);
jcfbauxLine.SetLineWeight(2);

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if jcfbaux >= signal then Color.GREEN else Color.GRAY);

def goVol = crosses(jcfbaux, signal, CrossingDirection.ABOVE);

plot SigLine = if!showSignals then na else if goVol then 0.03 else 0;    # "Volatility Rising"
SigLine.SetDefaultColor(Color.ORANGE);
AddCloud(SigLine, 0, Color.ORANGE);



#--- END of CODE
 
Last edited by a moderator:
Find below:

9rP2Poi.png


CSS:
#https://www.tradingview.com/script/fSTqdHYh-JCFBaux-Volatility-Loxx/
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © loxx
#indicator("JCFBaux Volatility [Loxx]", shorttitle = "JCFBV [Loxx]",
#Converted by Sam4Cok@Samer800        - 04/2023
declare lower;

input src     = close;         # "Source"
input depth   = 15;            # "Depth"
input JuirkPhase   = 0;        # "Signal - Juirk Smoothing Phase"
input SignalPeriod = 300;      # "Signal - Period"
input colorBars = yes;         # "Color bars?"
input showSignals = yes;       # "Show signals?"

def na = Double.NaN;
def lensmdd = SignalPeriod;
script nz {
    input data  = close;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}
#jurik_filt(float src, int len, float phase) =>
script jurik_filt {
    input src = close;
    input len = 34;
    input phase = 0;
#    //static variales
    def volty;
    def avolty;
    def vsum;
    def bsmax;
    def bsmin;
    def kv;
    def pow2;
    def dVolty;
    def len1 = Max(Log(Sqrt(0.5 * (len - 1))) / Log(2.0) + 2.0, 0);
    def len2 = Sqrt(0.5 * (len - 1)) * len1;
    def pow1 = Max(len1 - 2.0, 0.5);
    def beta = 0.45 * (len - 1) / (0.45 * (len - 1) + 2);
    def div = 1.0 / (10.0 + 10.0 * (Min(Max(len - 10, 0), 100)) / 100);
    def phaseRatio = if phase < -100 then 0.5 else
                     if phase >  100 then 2.5 else 1.5 + phase * 0.01;
    def bet = len2 / (len2 + 1);
#    //Price volatility
    def del1 = CompoundValue(1, src - bsmax[1], 0);
    def del2 = CompoundValue(1, src - bsmin[1], 0);
    volty = if AbsValue(del1) > AbsValue(del2) then AbsValue(del1) else AbsValue(del2);
#    //Relative price volatility factor
    vsum   = CompoundValue(1, vsum[1] + div * (volty - volty[10]), 0);
    avolty = CompoundValue(1, avolty[1] + (2.0 / (Max(4.0 * len, 30) + 1.0)) * (vsum - avolty[1]), 0);
    def dVolt = if avolty > 0 then volty / avolty else 0;
    dVolty = Max(1, Min(Power(len1, 1.0 / pow1), dVolt));
#   //Jurik volatility bands
    pow2 = Power(dVolty, pow1);
    Kv   = Power(bet, Sqrt(pow2));
    bsmax = if del1 > 0 then src else src - Kv * del1;
    bsmin = if del2 < 0 then src else src - Kv * del2;
#    //Jurik Dynamic Factor
    def alpha = Power(beta, pow2);
#    //1st stage - prelimimary smoothing by adaptive EMA
    def jrkout;
    def ma1;
    def det0;
    def e2;
    ma1 = CompoundValue(1, (1 - alpha) * src + alpha * ma1[1], 0);
#    //2nd stage - one more prelimimary smoothing by Kalman filter
    det0 = CompoundValue(1, (src - ma1) * (1 - beta) + beta * det0[1], 0);
    def ma2 = ma1 + phaseRatio * det0;
#    //3rd stage - final smoothing by unique Jurik adaptive filter
    e2     = CompoundValue(len, (ma2 - jrkout[1]) * Power(1 - alpha, 2) + Power(alpha, 2) * e2[1], 0);
    jrkout = CompoundValue(len, e2 + jrkout[1], src);
    plot return = jrkout;
}
#/ @function jcfbaux
#jcfbaux(float src, float depth) =>
script jcfbaux {
    input src = close;
    input depth = 15;
    def bar_index = AbsValue(CompoundValue(1, BarNumber(), 0));
    def cond  = (bar_index >= bar_index - depth * 2);
    def cond1 = (bar_index < bar_index - depth * 2);
    def start = Ceil(depth) - 1;
    def jrc04;
    def jrc05;
    def jrc06;
    def jrc08;
    if cond {
        jrc04 = fold k = 0 to start + 1 with p do
                p + AbsValue(GetValue(src,start - k) - GetValue(src,start - k + 1));
        jrc05 = fold k1 = 0 to start + 1 with p1 do
                p1 + (depth + start-k1) * AbsValue(GetValue(src, start-k1) - GetValue(src,start - k1 + 1));
        jrc06 = fold k2 = 0 to start + 1 with p2 do
                p2 + GetValue(src,start - k2 + 1);
    } else
    if cond1 {
        jrc04 = jrc04[1] - AbsValue(nz(src[depth]) - nz(src[depth + 1])) + AbsValue(src - src[1]);
        jrc05 = jrc05[1] - jrc04 + AbsValue(src - src[1]) * depth;
        jrc06 = jrc06[1] - nz(src[depth + 1]) + src[1];
    } else {
        jrc04 = jrc04[1];
        jrc05 = jrc05[1];
        jrc06 = jrc06[1];
    }
        jrc08 = AbsValue(depth * src - jrc06);
    def jcfbaux = if jrc05 == 0.0 then 0.0 else jrc08 / jrc05;
    plot out = jcfbaux;
}
def jcfbaux = jcfbaux(src, depth);
def signal = jurik_filt(jcfbaux, lensmdd, JuirkPhase);

plot Sig = signal;
plot jcfbauxLine = jcfbaux;

Sig.SetDefaultColor(Color.WHITE);
jcfbauxLine.AssignValueColor(if jcfbaux >= signal then Color.GREEN else Color.GRAY);
jcfbauxLine.SetLineWeight(2);

AssignPriceColor(if !colorBars then Color.CURRENT else
                 if jcfbaux >= signal then Color.GREEN else Color.GRAY);

def goVol = crosses(jcfbaux, signal, CrossingDirection.ABOVE);

plot SigLine = if!showSignals then na else if goVol then 0.03 else 0;    # "Volatility Rising"
SigLine.SetDefaultColor(Color.ORANGE);
AddCloud(SigLine, 0, Color.ORANGE);



#--- END of CODE
I had to put 20 years of data for it to work
 

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

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
312 Online
Create Post

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