Step Generalized Double DEMA (ATR based) [Loxx] for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
IsN91SC.png

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:

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