
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