STD-Filtered Jurik Volty Adaptive TEMA [Loxx] for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
2goktXQ.png

Author Message:
The STD-Filtered Jurik Volty Adaptive TEMA is an advanced moving average overlay indicator that incorporates adaptive period inputs from Jurik Volty into a Triple Exponential Moving Average (TEMA). The resulting value is further refined using a standard deviation filter to minimize noise. This adaptation aims to develop a faster TEMA that leads the standard, non-adaptive TEMA. However, during periods of low volatility, the output may be noisy, so a standard deviation filter is employed to decrease choppiness, yielding a highly responsive TEMA without the noise typically caused by low market volatility.

CODE:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
# https://www.tradingview.com/v/hJZmbFoz/
#// © loxx
#indicator("STD-Filtered Jurik Volty Adaptive TEMA [Loxx]"
# Converted by Sam4Cok@Samer800    - 04/2023
#--------Colors
DefineGlobalColor("up" , CreateColor(49,121,245));
DefineGlobalColor("dn" , CreateColor(255,82,82));
script nz {
    input data  = close;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}
#specema(src, per) =>
script specema {
    input src = close;
    input per = 14;
#    float ema = src
    def ema = if IsNaN(ema[1]) or ema[1]==0 then src else
              CompoundValue(1, (src - ema[1]) * (2 / (per + 1)) + ema[1], src);
    plot out = ema;
}
#tema(src, len) =>
script tema {
    input src = close;
    input len = 14;
    def ema1 = specema(src, len);
    def ema2 = specema(ema1, len);
    def ema3 = specema(ema2, len);
    def out = 3 * (ema1 - ema2) + ema3;
    plot return = out;
}
#stdFilter(float src, int len, float filter)=>
script stdFilter {
    input src = close;
    input len = 14;
    input filter = 1;
    def filtdev = filter * StDev(src, len);
    def price   = if isNaN(price[1]) or price[1]==0 then src else
                  CompoundValue(1, if AbsValue(src - price[1]) < filtdev then price[1] else src, src);
    plot out = price;
}
#volty(float src, int len) =>
script volty {
    input src = close;
    input len = 14;
    def bar_index = AbsValue(CompoundValue(1, BarNumber(), 0));
    def avgLen = 65;
    def volty;# = 0.0
    def voltya = 0.0;
    def dVolty;
    def bsmax;# = src
    def bsmin;# = src
    def vsum;# = 0
    def len1 = Max(Log(Sqrt(0.5 * (len - 1))) / Log(2.0) + 2.0, 0);
    def pow1 = Max(len1 - 2.0, 0.5);
    def del1 = src - nz(bsmax[1]);
    def del2 = src - nz(bsmin[1]);
    volty = if bar_index > 9 then
            if AbsValue(del1) > AbsValue(del2) then AbsValue(del1) else AbsValue(del2) else voltya;
    vsum = if isNaN(vsum[1]) then 0 else
            CompoundValue(1, vsum[1] + 0.1 * (volty - nz(volty[10], volty[1])), volty - nz(volty[10], volty[1]));
    def avg = Average(vsum, avgLen);
    def avolty = avg;
#    def dVolty_ = if avolty > 0 then voltya / avolty else 0;

 if nz(dVolty[1]) > Power(len1, 1.0 / pow1) {
        dVolty = Power(len1, 1.0 / pow1);
    } else {
        dVolty =  if nz(dVolty[1]) < 1 then 1.0 else dVolty[1];
    }
    def pow2 = Power(dVolty, pow1);
    def len2 = Sqrt(0.5 * (len - 1)) * len1;
    def Kv   = Power(len2 / (len2 + 1), Sqrt(pow2));
 if del1 > 0 {
        bsmax = src;
    } else {
        bsmax = src - Kv * del1;
    }
    if del2 < 0 {
        bsmin = src;
    } else {
        bsmin = src - Kv * del2;
    }
    def temp = if vsum != 0 then avolty / vsum else 1;
    plot out = temp;
}
input colorBars = yes;      # "Color bars"
input sigStyle = {Default "Arrow", "Bubble", "Don't Show Signal"};
input Source = close;       # "Source"
input len = 27;             # "EMA Length"
input filterOptions = {"Price", "Jurik Volty Adaptive TEMA", default "Both", "None"};    # "Filter Options"
input filter = 1;           # "Filter Devaitions"
input filterperiod = 10;    # "Filter Period"


def na = Double.NaN;
def price = filterOptions==filterOptions."Price";
def both  = filterOptions==filterOptions."Both";
def Jurik = filterOptions==filterOptions."Jurik Volty Adaptive TEMA";
def arrow = sigStyle==sigStyle."Arrow";
def bubble =  sigStyle==sigStyle."Bubble";

def src = if Both or Price and filter > 0 then stdFilter(Source, filterperiod, filter) else Source;
def out_ = tema(src, len * volty(src, len));

def out = if Both or Jurik and filter > 0 then stdFilter(out_, filterperiod, filter) else out_;
def sig = out[1];

def state = if out > sig then 1 else if out < sig then -1 else 0;
def pregoLong = out > sig and (nz(out[1]) < nz(sig[1]) or nz(out[1]) == nz(sig[1]));
def pregoShort = out < sig and (nz(out[1]) > nz(sig[1]) or nz(out[1]) == nz(sig[1]));

def contsw = if pregoLong then 1 else if pregoShort then -1 else nz(contsw[1]);

def goLong = pregoLong and nz(contsw[1]) == -1;
def goShort = pregoShort and nz(contsw[1]) == 1;

#var color colorout = na
def colorout = if state == -1 then -1 else if state == 1 then 1 else nz(colorout[1]);

#-- plot
plot JVAT = out;    # "Jurik Volty Adaptive TEMA"
JVAT.SetLineWeight(2);
JVAT.AssignValueColor(if colorout>0 then GlobalColor("up") else
                      if colorout<0 then GlobalColor("dn") else Color.GRAY);
#-- Signal
plot ArrowUp = if Arrow and goLong then low else na;
plot ArrowDn = if Arrow and goShort then high else na;
ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowUp.SetDefaultColor(Color.CYAN);
ArrowDn.SetDefaultColor(Color.MAGENTA);

AddChartBubble(bubble and goLong, low, "L", Color.GREEN, no);
AddChartBubble(bubble and goShort, high, "S", Color.RED, yes);

#-- Bar Color
AssignPriceColor(if !colorBars then Color.CURRENT else
                 if colorout>0 then Color.GREEN else
                 if colorout<0 then Color.RED else Color.GRAY);


#--- END of CODE
 
2goktXQ.png

Author Message:
The STD-Filtered Jurik Volty Adaptive TEMA is an advanced moving average overlay indicator that incorporates adaptive period inputs from Jurik Volty into a Triple Exponential Moving Average (TEMA). The resulting value is further refined using a standard deviation filter to minimize noise. This adaptation aims to develop a faster TEMA that leads the standard, non-adaptive TEMA. However, during periods of low volatility, the output may be noisy, so a standard deviation filter is employed to decrease choppiness, yielding a highly responsive TEMA without the noise typically caused by low market volatility.

CODE:

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
# https://www.tradingview.com/v/hJZmbFoz/
#// © loxx
#indicator("STD-Filtered Jurik Volty Adaptive TEMA [Loxx]"
# Converted by Sam4Cok@Samer800    - 04/2023
#--------Colors
DefineGlobalColor("up" , CreateColor(49,121,245));
DefineGlobalColor("dn" , CreateColor(255,82,82));
script nz {
    input data  = close;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}
#specema(src, per) =>
script specema {
    input src = close;
    input per = 14;
#    float ema = src
    def ema = if IsNaN(ema[1]) or ema[1]==0 then src else
              CompoundValue(1, (src - ema[1]) * (2 / (per + 1)) + ema[1], src);
    plot out = ema;
}
#tema(src, len) =>
script tema {
    input src = close;
    input len = 14;
    def ema1 = specema(src, len);
    def ema2 = specema(ema1, len);
    def ema3 = specema(ema2, len);
    def out = 3 * (ema1 - ema2) + ema3;
    plot return = out;
}
#stdFilter(float src, int len, float filter)=>
script stdFilter {
    input src = close;
    input len = 14;
    input filter = 1;
    def filtdev = filter * StDev(src, len);
    def price   = if isNaN(price[1]) or price[1]==0 then src else
                  CompoundValue(1, if AbsValue(src - price[1]) < filtdev then price[1] else src, src);
    plot out = price;
}
#volty(float src, int len) =>
script volty {
    input src = close;
    input len = 14;
    def bar_index = AbsValue(CompoundValue(1, BarNumber(), 0));
    def avgLen = 65;
    def volty;# = 0.0
    def voltya = 0.0;
    def dVolty;
    def bsmax;# = src
    def bsmin;# = src
    def vsum;# = 0
    def len1 = Max(Log(Sqrt(0.5 * (len - 1))) / Log(2.0) + 2.0, 0);
    def pow1 = Max(len1 - 2.0, 0.5);
    def del1 = src - nz(bsmax[1]);
    def del2 = src - nz(bsmin[1]);
    volty = if bar_index > 9 then
            if AbsValue(del1) > AbsValue(del2) then AbsValue(del1) else AbsValue(del2) else voltya;
    vsum = if isNaN(vsum[1]) then 0 else
            CompoundValue(1, vsum[1] + 0.1 * (volty - nz(volty[10], volty[1])), volty - nz(volty[10], volty[1]));
    def avg = Average(vsum, avgLen);
    def avolty = avg;
#    def dVolty_ = if avolty > 0 then voltya / avolty else 0;

 if nz(dVolty[1]) > Power(len1, 1.0 / pow1) {
        dVolty = Power(len1, 1.0 / pow1);
    } else {
        dVolty =  if nz(dVolty[1]) < 1 then 1.0 else dVolty[1];
    }
    def pow2 = Power(dVolty, pow1);
    def len2 = Sqrt(0.5 * (len - 1)) * len1;
    def Kv   = Power(len2 / (len2 + 1), Sqrt(pow2));
 if del1 > 0 {
        bsmax = src;
    } else {
        bsmax = src - Kv * del1;
    }
    if del2 < 0 {
        bsmin = src;
    } else {
        bsmin = src - Kv * del2;
    }
    def temp = if vsum != 0 then avolty / vsum else 1;
    plot out = temp;
}
input colorBars = yes;      # "Color bars"
input sigStyle = {Default "Arrow", "Bubble", "Don't Show Signal"};
input Source = close;       # "Source"
input len = 27;             # "EMA Length"
input filterOptions = {"Price", "Jurik Volty Adaptive TEMA", default "Both", "None"};    # "Filter Options"
input filter = 1;           # "Filter Devaitions"
input filterperiod = 10;    # "Filter Period"


def na = Double.NaN;
def price = filterOptions==filterOptions."Price";
def both  = filterOptions==filterOptions."Both";
def Jurik = filterOptions==filterOptions."Jurik Volty Adaptive TEMA";
def arrow = sigStyle==sigStyle."Arrow";
def bubble =  sigStyle==sigStyle."Bubble";

def src = if Both or Price and filter > 0 then stdFilter(Source, filterperiod, filter) else Source;
def out_ = tema(src, len * volty(src, len));

def out = if Both or Jurik and filter > 0 then stdFilter(out_, filterperiod, filter) else out_;
def sig = out[1];

def state = if out > sig then 1 else if out < sig then -1 else 0;
def pregoLong = out > sig and (nz(out[1]) < nz(sig[1]) or nz(out[1]) == nz(sig[1]));
def pregoShort = out < sig and (nz(out[1]) > nz(sig[1]) or nz(out[1]) == nz(sig[1]));

def contsw = if pregoLong then 1 else if pregoShort then -1 else nz(contsw[1]);

def goLong = pregoLong and nz(contsw[1]) == -1;
def goShort = pregoShort and nz(contsw[1]) == 1;

#var color colorout = na
def colorout = if state == -1 then -1 else if state == 1 then 1 else nz(colorout[1]);

#-- plot
plot JVAT = out;    # "Jurik Volty Adaptive TEMA"
JVAT.SetLineWeight(2);
JVAT.AssignValueColor(if colorout>0 then GlobalColor("up") else
                      if colorout<0 then GlobalColor("dn") else Color.GRAY);
#-- Signal
plot ArrowUp = if Arrow and goLong then low else na;
plot ArrowDn = if Arrow and goShort then high else na;
ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowUp.SetDefaultColor(Color.CYAN);
ArrowDn.SetDefaultColor(Color.MAGENTA);

AddChartBubble(bubble and goLong, low, "L", Color.GREEN, no);
AddChartBubble(bubble and goShort, high, "S", Color.RED, yes);

#-- Bar Color
AssignPriceColor(if !colorBars then Color.CURRENT else
                 if colorout>0 then Color.GREEN else
                 if colorout<0 then Color.RED else Color.GRAY);


#--- END of CODE
@samer800 Could you add a MTF preference?
 
@samer800 Could you add a MTF preference?
check this.

CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
# https://www.tradingview.com/v/hJZmbFoz/
#// © loxx
#indicator("STD-Filtered Jurik Volty Adaptive TEMA [Loxx]"
# Converted by Sam4Cok@Samer800    - 04/2023
# Update - Added MTF option by Sam4Cok@Samer800    - 04/2023
#--------Colors
DefineGlobalColor("up" , CreateColor(49,121,245));
DefineGlobalColor("dn" , CreateColor(255,82,82));
script nz {
    input data  = close;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}
#specema(src, per) =>
script specema {
    input src = close;
    input per = 14;
    def ema;# = src
        ema = if (IsNaN(ema[1]) or ema[1]==0) then src else
              (src - ema[1]) * (2 / (per + 1)) + ema[1];
    plot out = ema;
}
#tema(src, len) =>
script tema {
    input src = close;
    input len = 14;
    def ema1 = specema(src, len);
    def ema2 = specema(ema1, len);
    def ema3 = specema(ema2, len);
    def out = 3 * (ema1 - ema2) + ema3;
    plot return = out;
}
#stdFilter(float src, int len, float filter)=>
script stdFilter {
    input src = close;
    input len = 14;
    input filter = 1;
    def filtdev = filter * StDev(src, len);
    def price   = if (isNaN(price[1]) or price[1]==0) then src else
                  if AbsValue(src - price[1]) < filtdev then price[1] else src;
    plot out = price;
}
#volty(float src, int len) =>
script volty {
    input src = close;
    input len = 14;
    def bar_index = AbsValue(CompoundValue(1, BarNumber(), 0));
    def avgLen = 65;
    def volty;# = 0.0
    def voltya = 0.0;
    def dVolty;
    def bsmax;# = src
    def bsmin;# = src
    def vsum;# = 0
    def len1 = Max(Log(Sqrt(0.5 * (len - 1))) / Log(2.0) + 2.0, 0);
    def pow1 = Max(len1 - 2.0, 0.5);
    def del1 = src - nz(bsmax[1]);
    def del2 = src - nz(bsmin[1]);
    volty = if bar_index > 9 then
            if AbsValue(del1) > AbsValue(del2) then AbsValue(del1) else AbsValue(del2) else voltya;
    vsum = if isNaN(vsum[1]) then 0 else
              vsum[1] + 0.1 * (volty - nz(volty[10], volty[1]));
    def avg = Average(vsum, avgLen);
    def avolty = avg;

 if nz(dVolty[1]) > Power(len1, 1.0 / pow1) {
        dVolty = Power(len1, 1.0 / pow1);
    } else {
        dVolty =  if nz(dVolty[1]) < 1 then 1.0 else dVolty[1];
    }
    def pow2 = Power(dVolty, pow1);
    def len2 = Sqrt(0.5 * (len - 1)) * len1;
    def Kv   = Power(len2 / (len2 + 1), Sqrt(pow2));
 if del1 > 0 {
        bsmax = src;
    } else {
        bsmax = src - Kv * del1;
    }
    if del2 < 0 {
        bsmin = src;
    } else {
        bsmin = src - Kv * del2;
    }
    def temp = if vsum != 0 then avolty / vsum else 1;
    plot out = temp;
}
input colorBars = yes;      # "Color bars"
input UseChartTimeframe = yes;
input ManualTimeframe = AggregationPeriod.FIFTEEN_MIN;
input sigStyle   = {Default "Arrow", "Bubble", "Don't Show Signal"};
input Source     = {Default "Close", "HL2", "HLC3", "OHLC4"};  # "Source"
input len        = 27;             # "EMA Length"
input filterOptions = {"Price", "Jurik Volty Adaptive TEMA", default "Both", "None"};    # "Filter Options"
input filter   = 1;           # "Filter Devaitions"
input filterperiod = 10;    # "Filter Period"


def na = Double.NaN;
def cClose = Source==Source."Close";
def cHL2   = Source==Source."HL2";
def cHLC3  = Source==Source."HLC3";

def current = GetAggregationPeriod();
def tf = if UseChartTimeframe then current else ManualTimeframe;
def src_ = if cClose then close(Period=tf) else
           if cHL2 then hl2(Period=tf) else
           if cHLC3 then hlc3(Period=tf) else ohlc4(Period=tf);#

def price = filterOptions==filterOptions."Price";
def both  = filterOptions==filterOptions."Both";
def Jurik = filterOptions==filterOptions."Jurik Volty Adaptive TEMA";
def arrow = sigStyle==sigStyle."Arrow";
def bubble =  sigStyle==sigStyle."Bubble";

def stdFilter = stdFilter(src_, filterperiod, filter);
def src = if Both or Price and filter > 0 then stdFilter else src_;

def out_ = tema(src, len * volty(src, len));
def stdFilterOut =  stdFilter(out_, filterperiod, filter);

def out = if Both or Jurik and filter > 0 then stdFilterOut else out_;
def sig = out[1];

def state = if out > sig then 1 else if out < sig then -1 else 0;
def pregoLong = out > sig and (nz(out[1]) < nz(sig[1]) or nz(out[1]) == nz(sig[1]));
def pregoShort = out < sig and (nz(out[1]) > nz(sig[1]) or nz(out[1]) == nz(sig[1]));

def contsw = if pregoLong then 1 else if pregoShort then -1 else nz(contsw[1]);

def goLong = pregoLong and nz(contsw[1]) == -1;
def goShort = pregoShort and nz(contsw[1]) == 1;

#var color colorout = na
def colorout = if state == -1 then -1 else if state == 1 then 1 else nz(colorout[1]);

#-- plot
plot JVAT = out;    # "Jurik Volty Adaptive TEMA"
JVAT.SetLineWeight(2);
JVAT.AssignValueColor(if colorout>0 then GlobalColor("up") else
                      if colorout<0 then GlobalColor("dn") else Color.GRAY);
#-- Signal
plot ArrowUp = if Arrow and goLong then low else na;
plot ArrowDn = if Arrow and goShort then high else na;
ArrowUp.SetPaintingStrategy(PaintingStrategy.ARROW_UP);
ArrowDn.SetPaintingStrategy(PaintingStrategy.ARROW_DOWN);
ArrowUp.SetDefaultColor(Color.CYAN);
ArrowDn.SetDefaultColor(Color.MAGENTA);

AddChartBubble(bubble and goLong, low, "L", Color.GREEN, no);
AddChartBubble(bubble and goShort, high, "S", Color.RED, yes);

#-- Bar Color
AssignPriceColor(if !colorBars then Color.CURRENT else
                 if colorout>0 then Color.GREEN else
                 if colorout<0 then Color.RED else Color.GRAY);


#--- END of CODE
 

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
359 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