EMA-Deviation-Corrected T3 [Loxx] for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
FBouhkw.png


Author Message:

EMA-Deviation-Corrected T3 is a T3 moving average that uses EMA deviation correcting to produce signals. This comes via the beloved genius Mladen.

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/V2Sr2MNG/
#// © loxx
#indicator("EMA-Deviation-Corrected T3 [Loxx]",   
# Converted by Sam4Cok@Samer800    - 07/2023

input useChartTimeframe =  {default"Yes", "No"};
input manualTimeframe   = AggregationPeriod.FIFTEEN_MIN;
input Source = Close;        # "Source"
input movAvgType = {Default EMA, SMA, WMA};
input t3Period = 20;         # "T3 Period"
input t3Hot = 0.6;           # "T3 Hot"
input t3Type = {default "T3 New", "T3 Original"};    # "T3 Settings"
input colorBars = no;        # "Color bars?"
input showsignals = yes;     # "Show signals?"

def na = Double.NaN;

DefineGlobalColor("up", CreateColor(100, 181, 246));
DefineGlobalColor("dn", CreateColor(239, 83, 80));
DefineGlobalColor("cup", CreateColor(7, 71, 123));
DefineGlobalColor("cdn", CreateColor(113, 12, 10));
#-- MTF
def src;
Switch (useChartTimeframe) {
case "Yes" :
    src = close;
case "No"  :
    src = close(Period=manualTimeframe);
}
#---
#_iT3(src, per, hot, clean)=>
script t3filter {
    input src = close;
    input per = 10;
    input hot = 0.7;
    input clean = "T3 New";
    def a = hot;
    def _c1 = -a * a * a;
    def _c2 = 3 * a * a + 3 * a * a * a;
    def _c3 = -6 * a * a - 3 * a - 3 * a * a * a;
    def _c4 = 1 + 3 * a + a * a * a + 3 * a * a;
    def alpha1 = 2.0 / (2.0 + (per - 1.0) / 2.0);
    def alpha2 = 2.0 / (1.0 + per);
    def t3Type = clean == "T3 New";
    def alpha = if t3Type then alpha1 else alpha2;
    def _t30 = _t30[1] + alpha * (src -  _t30[1]);
    def _t31 = _t31[1] + alpha * (_t30 - _t31[1]);
    def _t32 = _t32[1] + alpha * (_t31 - _t32[1]);
    def _t33 = _t33[1] + alpha * (_t32 - _t33[1]);
    def _t34 = _t34[1] + alpha * (_t33 - _t34[1]);
    def _t35 = _t35[1] + alpha * (_t34 - _t35[1]);
    def out = _c1 * _t35 + _c2 * _t34 + _c3 * _t33 +  _c4 * _t32;
    plot return = out;
}
#corrMaEmaDev(float price, float avg, simple int period)=>
script corrMaEmaDev {
    input price = close;
    input avg = close;
    input period = 10;
    input movType = {Default EMA, SMA, WMA};
    def corr;
    def DuPrice = price * price;
    def alpha = 2.0 / (1.0 + period);
    def ema0 = ExpAverage(price, period);
    def ema1 = ExpAverage(DuPrice, period);
    def sma0 = Average(price, period);
    def sma1 = Average(DuPrice, period);
    def wma0 = WMA(price, period);
    def wma1 = WMA(DuPrice, period);
    def ma0;def ma1;
    Switch (movType) {
    Case "EMA" :
        ma0 = ema0;
        ma1 = ema1;
    Case "SMA" :
        ma0 = sma0;
        ma1 = sma1;
    Case "WMA" :
        ma0 = wma0;
        ma1 = wma1;}
    def TotSum = ma1 - ma0 * ma0;
    def max = Max(period - 1, 1);
    def sqrPer = Sqrt(period * TotSum / max);
    def _deviation = Max(sqrPer, 0.0);
    def v1 = Power(_deviation, 2);
    def v2 = Power(corr[1] - avg, 2);
    def c = if (v2 < v1 or v2 == 0) then 0 else 1 - v1 / v2;
    corr = corr[1] + c * (avg - corr[1]);
    plot out = corr;
}
def t3 = t3filter(src, t3Period, t3hot, t3Type);
def corrout = corrMaEmaDev(src, t3, t3Period, movAvgType);

def colUp = t3 > corrout;

plot t3Line = t3;
plot corLine = corrout;

t3Line.SetLineWeight(2);
t3Line.AssignValueColor(if colUp then GlobalColor("up") else GlobalColor("dn"));
corLine.AssignValueColor(if colUp then GlobalColor("up") else GlobalColor("dn"));

AddCloud(t3, corLine, GlobalColor("cup"), GlobalColor("cdn"));

#--- Sig

def goLong  = crosses(t3, corrout, CrossingDirection.ABOVE);
def goShort = crosses(t3, corrout, CrossingDirection.BELOW);

plot long = if showsignals and goLong then corrout else na;#, "Long"
long.SetPaintingStrategy(PaintingStrategy.SQUARES);
long.SetDefaultColor(Color.CYAN);
long.SetLineWeight(3);
plot short = if showsignals and goShort then corrout else na;#, "Short"
short.SetPaintingStrategy(PaintingStrategy.SQUARES);
short.SetDefaultColor(Color.MAGENTA);
short.SetLineWeight(3);

#-- Bar Color

AssignPriceColor(if !colorbars then Color.CURRENT else
                 if colUp then Color.GREEN else Color.RED);


#-- 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
403 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