Author Message:
Step Generalized Double DEMA (ATR based) works like a T3 moving average but is less smooth. This is on purpose to catch more signals. The addition of ATR stepped filtering reduces noise while maintaining signal integrity.
CODE:
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at
#https://www.tradingview.com/script/s1ZjIZmo-Step-Generalized-Double-DEMA-ATR-based-Loxx/
#indicator("Step Generalized Double DEMA (ATR based) [Loxx]",
# Converted by Sam4Cok@Samer800 - 09/2022
#gdema(float price, float period, float volumeFactor)=>
script gdema {
input price = close;
input period = 0;
input volumeFactor = 0;
def vol = if(volumeFactor > 0) then if (volumeFactor > 1) then 1 else volumeFactor else 0.01;
def volpl = vol + 1;
def alpha = 2.0 / (1.0 + (if period > 1 then period else 1));
def winst1; def winst2; def winst3; def winst4;
winst1 = if isNaN(winst1[1]) then 0 else
winst1[1] + alpha * (price - winst1[1]);
winst2 = if isNaN(winst2[1]) then 0 else
winst2[1] + alpha * (winst1 - winst2[1]);
winst3 = if isNaN(winst3[1]) then 0 else
winst3[1] + alpha * ((winst1 * volpl - winst2 * vol) - winst3[1]);
winst4 = if isNaN(winst4[1]) then 0 else
winst4[1] + alpha * (winst3 - winst4[1]);
def winst = winst3 * volpl - winst4 * vol;
plot return = winst;
}
#----- Settings
input src = Close; # "Source Settings",
input DoubleDEMAPeriod = 14; # "Double DEMA period"
input volumeFactor = 0.7; # "Double DEMA volume factor"
input StepSizePercentage = 20; # "Step Size in % of ATR"
input atrPeriod = 50; # "ATR Period"
input showSigs = yes; # "Show signals?"
input colorBars = no; # "Color bars?"
#-----------------------
def bar = BarNumber();
def na = Double.NaN;
def multout = StepSizePercentage/100;
def nATR = atr(Length=atrPeriod);
def val1 = gdema(src, DoubleDEMAPeriod, volumeFactor);
def stepSize = multout * nATR;
def val;
val = val[1] + (if ((val1 - val[1]) < stepSize and (val1 - val[1]) > -stepSize) then 0
else ((val1 - val[1]) / stepSize) * stepSize);
def goLong_pre = (val crosses above val[1]);
def goShort_pre = (val crosses below val[1]);
def contSwitch = if goLong_pre then 1 else
if goShort_pre then -1 else contSwitch[1];
def goLong = goLong_pre and (contSwitch-contSwitch[1]);
def goShort = goShort_pre and (contSwitch-contSwitch[1]);
plot SGDDEMA = if bar<2 then na else val;
SGDDEMA.AssignValueColor(if contSwitch == 1 then Color.CYAN else Color.MAGENTA);
SGDDEMA.SetLineWeight(2);
AddChartBubble(showSigs and goLong, low, "Long", Color.CYAN, no);
AddChartBubble(showSigs and goShort, high, "Short", Color.MAGENTA, yes);
AssignPriceColor(if colorbars then if contSwitch == 1 then Color.CYAN else
Color.DARK_ORANGE else Color.CURRENT);
#----- END
Last edited by a moderator: