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