T3 Volatility Quality Index (VQI) & Pips Filtering [Loxx] for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
qIgGb5e.png


Creator Message:

T3 Volatility Quality Index ( VQI ) w/ DSL & Pips Filtering is a VQI indicator that uses T3 smoothing and discontinued signal lines to determine breakouts and breakdowns. This also allows filtering by pips.***

CODE:
CSS:
#/ This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © loxx
# https://www.tradingview.com/v/56Q61Aff/
#indicator("T3 Volatility Quality Index (VQI) w/ DSL & Pips Filtering [Loxx]",
# converted by Sam4Cok@Samer800 - 03/2023
declare lower;
#_iT3(src, per, hot, clean)=>
script _iT3 {
    input src = close;
    input per = 5;
    input hot = 0.5;
    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 alpha;
    def t3Type = clean == "T3 New";
    alpha = if t3Type then alpha1 else alpha2;
    def _t30;
    def _t31;
    def _t32;
    def _t33;
    def _t34;
    def _t35;
    _t30 = CompoundValue(1, _t30[1] + alpha * (src -  _t30[1]), src);
    _t31 = CompoundValue(1, _t31[1] + alpha * (_t30 - _t31[1]), _t30);
    _t32 = CompoundValue(1, _t32[1] + alpha * (_t31 - _t32[1]), _t31);
    _t33 = CompoundValue(1, _t33[1] + alpha * (_t32 - _t33[1]), _t32);
    _t34 = CompoundValue(1, _t34[1] + alpha * (_t33 - _t34[1]), _t33);
    _t35 = CompoundValue(1, _t35[1] + alpha * (_t34 - _t35[1]), _t34);
    def out = _c1 * _t35 + _c2 * _t34 + _c3 * _t33 +  _c4 * _t32;
    plot return = out;
}
script _declen {
    def mtckstr = TickValue();
    def dstr = if mtckstr < 1 then mtckstr else 0;
    plot out = dstr;
}
#variant(type, src, len) =>
script variant {
    input type = "Exponential Moving Average - EMA";
    input src = close;
    input len = 5;
    def trig;# = 0.0
    def MovType = type == "Exponential Moving Average - EMA";
    def alpha = (2.0 / (2.0 + (len - 1.0) / 2.0));
    def FEMA;
        FEMA = CompoundValue(1, FEMA[1] + alpha * (src - FEMA[1]), src);
    def ema = ExpAverage(src, len);
    trig = if MovType then ema else FEMA;
    plot out = trig;
}
input PriceSmoothing = 5;    # "Source Smoothing Period"
input t3hot = 0.5;           # "T3 Hot"
input t3Type = {default "T3 New", "T3 Original"};    # "T3 Type"
input FilterInPips = 1.9;    # "Filter in Pips"
input sigmatype = {default "Exponential Moving Average - EMA", "Fast Exponential Moving Average - FEMA"};# "Signal/DSL Smoothing"
input Ma1Period = 9;         # "DSL Period"  
input colorbars = yes;       # "Color bars?"
input showSigs = yes;        # "Show signals?"

def na = Double.NaN;
def pipMultiplier = power(10, _declen() % 2);

def cHigh  = _iT3(high, PriceSmoothing, t3hot, t3Type);
def cLow   = _iT3(low, PriceSmoothing, t3hot, t3Type);
def cOpen  = _iT3(open, PriceSmoothing, t3hot, t3Type);
def cClose = _iT3(close, PriceSmoothing, t3hot, t3Type);
def pClose = _iT3(close[1], PriceSmoothing, t3hot, t3Type);

def val;# = 0.,
def valc;# = 0.
def truerng = Max(cHigh, pClose) - Min(cLow, pClose);
def rng = cHigh - cLow;
def vqi = if (rng != 0 and truerng != 0) then ((cClose - pClose) / truerng + (cClose - cOpen) / rng) * 0.5 else val[1];
def vgiValue =  AbsValue(vqi) * (cClose - pClose + cClose - cOpen) * 0.5;
    valc = CompoundValue(1, val[1] + vgiValue, valc[1]);

def cond = AbsValue(valc-valc[1]) < FilterInPips * TickValue() * pipMultiplier;
if (FilterInPips > 0) {
    if cond {
    val = val[1];
} else {
    val = valc;
}
} else {
        val = val[1];
}
def sig = val[1];
def temp = variant(sigmatype, val, Ma1Period);

def levelu = if (val > sig) then temp else levelu[1];
def leveld = if (val < sig) then temp else leveld[1];

def colorout = if val > levelu then 1 else if val < leveld then -1 else 0;

plot VQILine = val;        # "VQI"
VQILine.SetLineWeight(2);
VQILine.AssignValueColor(if colorout > 0 then Color.GREEN else
                         if colorout < 0 then Color.RED else Color.GRAY);

plot LevelUp = levelu;     # "Level Up"
LevelUp.SetDefaultColor(Color.DARK_GREEN);
plot LevelDown = leveld;   # "Level Down"
LevelDown.SetDefaultColor(Color.DARK_RED);

#--- Sig

def goLong  = crosses(val, levelu, CrossingDirection.ABOVE);
def goShort = crosses(val, leveld, CrossingDirection.BELOW);

plot long = if showSigs and goLong then val else na;#, "Long", color.yellow, no);
long.SetPaintingStrategy(PaintingStrategy.SQUARES);
long.SetDefaultColor(Color.CYAN);
long.SetLineWeight(3);
plot short = if showSigs and goShort then val else na;#, "Short", color.MAGENTA, yes);
short.SetPaintingStrategy(PaintingStrategy.SQUARES);
short.SetDefaultColor(Color.MAGENTA);
short.SetLineWeight(3);

AssignPriceColor(if !Colorbars then Color.CURRENT else
                 if colorout > 0 then Color.GREEN else
                 if colorout < 0 then Color.RED else Color.GRAY);


#--- END CODE
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Last edited:
  • Love
Reactions: IPA
In the TV docs., the author mentions -
This indicator is tuned to Forex. If you want to make it useful for other tickers, you must change the pip filtering value to match the asset. This means that for BTC, for example, you likely need to use a value of 10,000 or more for pips filter.

When apply it to future or option data, when u hit apply, there will be a blink show of the indicator and then it will disappear and leave a gray centre line across the chart ...

It seem ok on most other data ...
 
Last edited by a moderator:
@IPA @mactheknife @Zlotko
@AK011


I just excluded the pips calculation from the code. this may work in all markets but with some difference. pls check

CSS:
#/ This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © loxx
# https://www.tradingview.com/v/56Q61Aff/
#indicator("T3 Volatility Quality Index (VQI) w/ DSL & Pips Filtering [Loxx]",
# converted by Sam4Cok@Samer800 - 03/2023
declare lower;
#_iT3(src, per, hot, clean)=>
script _iT3 {
    input src = close;
    input per = 5;
    input hot = 0.5;
    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;
    def _t31;
    def _t32;
    def _t33;
    def _t34;
    def _t35;
    _t30 = CompoundValue(1, _t30[1] + alpha * (src -  _t30[1]), src);
    _t31 = CompoundValue(1, _t31[1] + alpha * (_t30 - _t31[1]), _t30);
    _t32 = CompoundValue(1, _t32[1] + alpha * (_t31 - _t32[1]), _t31);
    _t33 = CompoundValue(1, _t33[1] + alpha * (_t32 - _t33[1]), _t32);
    _t34 = CompoundValue(1, _t34[1] + alpha * (_t33 - _t34[1]), _t33);
    _t35 = CompoundValue(1, _t35[1] + alpha * (_t34 - _t35[1]), _t34);
    def out = _c1 * _t35 + _c2 * _t34 + _c3 * _t33 +  _c4 * _t32;
    plot return = out;
}

#variant(type, src, len) =>
script variant {
    input type = "Exponential Moving Average - EMA";
    input src = close;
    input len = 5;
    def trig;# = 0.0
    def MovType = type == "Exponential Moving Average - EMA";
    def alpha = (2.0 / (2.0 + (len - 1.0) / 2.0));
    def FEMA;
        FEMA = CompoundValue(1, FEMA[1] + alpha * (src - FEMA[1]), src);
    def ema = ExpAverage(src, len);
    trig = if MovType then ema else FEMA;
    plot out = trig;
}
input PriceSmoothing = 5;    # "Source Smoothing Period"
input t3hot = 0.5;           # "T3 Hot"
input t3Type = {default "T3 New", "T3 Original"};    # "T3 Type"
#input FilterInPips = 1.9;    # "Filter in Pips"
input sigmatype = {default "Exponential Moving Average - EMA", "Fast Exponential Moving Average - FEMA"};# "Signal/DSL Smoothing"
input Ma1Period = 9;         # "DSL Period"   
input colorbars = yes;       # "Color bars?"
input showSigs = yes;        # "Show signals?"

def na = Double.NaN;
def tick = TickSize();
def dstr = if tick < 1 then tick else 0;
def declen = dstr;
def decPower = declen % 2;
def pipMultiplier = power(10, decPower);

def cHigh  = _iT3(high, PriceSmoothing, t3hot, t3Type);
def cLow   = _iT3(low, PriceSmoothing, t3hot, t3Type);
def cOpen  = _iT3(open, PriceSmoothing, t3hot, t3Type);
def cClose = _iT3(close, PriceSmoothing, t3hot, t3Type);
def pClose = _iT3(close[1], PriceSmoothing, t3hot, t3Type);

def val;# = 0.,
#def valc;# = 0.
def truerng = Max(cHigh, pClose) - Min(cLow, pClose);
def rng = cHigh - cLow;
def vqi = if (rng != 0 and truerng != 0) then ((cClose - pClose) / truerng + (cClose - cOpen) / rng) * 0.5 else val[1];
def vgiValue =  AbsValue(vqi) * (cClose - pClose + cClose - cOpen) * 0.5;
def valc = CompoundValue(1, val[1] + vgiValue, valc[1]);

def cond = AbsValue(valc-valc[1]) < tick;
    if cond {
    val = val[1];
} else {
    val = valc;
}
def sig = val[1];
def temp = variant(sigmatype, val, Ma1Period);

def levelu = if (val > sig) then temp else levelu[1];
def leveld = if (val < sig) then temp else leveld[1];

def colorout = if val > levelu then 1 else if val < leveld then -1 else 0;

plot VQILine = val;        # "VQI"
VQILine.SetLineWeight(2);
VQILine.AssignValueColor(if colorout > 0 then Color.GREEN else
                         if colorout < 0 then Color.RED else Color.GRAY);

plot LevelUp = levelu;     # "Level Up"
LevelUp.SetDefaultColor(Color.DARK_GREEN);
plot LevelDown = leveld;   # "Level Down"
LevelDown.SetDefaultColor(Color.DARK_RED);

#--- Sig

def goLong  = crosses(val, levelu, CrossingDirection.ABOVE);
def goShort = crosses(val, leveld, CrossingDirection.BELOW);

plot long = if showSigs and goLong then val else na;#, "Long", color.yellow, no);
long.SetPaintingStrategy(PaintingStrategy.SQUARES);
long.SetDefaultColor(Color.CYAN);
long.SetLineWeight(3);
plot short = if showSigs and goShort then val else na;#, "Short", color.MAGENTA, yes);
short.SetPaintingStrategy(PaintingStrategy.SQUARES);
short.SetDefaultColor(Color.MAGENTA);
short.SetLineWeight(3);

AssignPriceColor(if !Colorbars then Color.CURRENT else
                 if colorout > 0 then Color.GREEN else
                 if colorout < 0 then Color.RED else Color.GRAY);


#--- END CODE
 
@IPA @mactheknife @Zlotko
@AK011


I just excluded the pips calculation from the code. this may work in all markets but with some difference. pls check

CSS:
#/ This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © loxx
# https://www.tradingview.com/v/56Q61Aff/
#indicator("T3 Volatility Quality Index (VQI) w/ DSL & Pips Filtering [Loxx]",
# converted by Sam4Cok@Samer800 - 03/2023
declare lower;
#_iT3(src, per, hot, clean)=>
script _iT3 {
    input src = close;
    input per = 5;
    input hot = 0.5;
    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;
    def _t31;
    def _t32;
    def _t33;
    def _t34;
    def _t35;
    _t30 = CompoundValue(1, _t30[1] + alpha * (src -  _t30[1]), src);
    _t31 = CompoundValue(1, _t31[1] + alpha * (_t30 - _t31[1]), _t30);
    _t32 = CompoundValue(1, _t32[1] + alpha * (_t31 - _t32[1]), _t31);
    _t33 = CompoundValue(1, _t33[1] + alpha * (_t32 - _t33[1]), _t32);
    _t34 = CompoundValue(1, _t34[1] + alpha * (_t33 - _t34[1]), _t33);
    _t35 = CompoundValue(1, _t35[1] + alpha * (_t34 - _t35[1]), _t34);
    def out = _c1 * _t35 + _c2 * _t34 + _c3 * _t33 +  _c4 * _t32;
    plot return = out;
}

#variant(type, src, len) =>
script variant {
    input type = "Exponential Moving Average - EMA";
    input src = close;
    input len = 5;
    def trig;# = 0.0
    def MovType = type == "Exponential Moving Average - EMA";
    def alpha = (2.0 / (2.0 + (len - 1.0) / 2.0));
    def FEMA;
        FEMA = CompoundValue(1, FEMA[1] + alpha * (src - FEMA[1]), src);
    def ema = ExpAverage(src, len);
    trig = if MovType then ema else FEMA;
    plot out = trig;
}
input PriceSmoothing = 5;    # "Source Smoothing Period"
input t3hot = 0.5;           # "T3 Hot"
input t3Type = {default "T3 New", "T3 Original"};    # "T3 Type"
#input FilterInPips = 1.9;    # "Filter in Pips"
input sigmatype = {default "Exponential Moving Average - EMA", "Fast Exponential Moving Average - FEMA"};# "Signal/DSL Smoothing"
input Ma1Period = 9;         # "DSL Period"  
input colorbars = yes;       # "Color bars?"
input showSigs = yes;        # "Show signals?"

def na = Double.NaN;
def tick = TickSize();
def dstr = if tick < 1 then tick else 0;
def declen = dstr;
def decPower = declen % 2;
def pipMultiplier = power(10, decPower);

def cHigh  = _iT3(high, PriceSmoothing, t3hot, t3Type);
def cLow   = _iT3(low, PriceSmoothing, t3hot, t3Type);
def cOpen  = _iT3(open, PriceSmoothing, t3hot, t3Type);
def cClose = _iT3(close, PriceSmoothing, t3hot, t3Type);
def pClose = _iT3(close[1], PriceSmoothing, t3hot, t3Type);

def val;# = 0.,
#def valc;# = 0.
def truerng = Max(cHigh, pClose) - Min(cLow, pClose);
def rng = cHigh - cLow;
def vqi = if (rng != 0 and truerng != 0) then ((cClose - pClose) / truerng + (cClose - cOpen) / rng) * 0.5 else val[1];
def vgiValue =  AbsValue(vqi) * (cClose - pClose + cClose - cOpen) * 0.5;
def valc = CompoundValue(1, val[1] + vgiValue, valc[1]);

def cond = AbsValue(valc-valc[1]) < tick;
    if cond {
    val = val[1];
} else {
    val = valc;
}
def sig = val[1];
def temp = variant(sigmatype, val, Ma1Period);

def levelu = if (val > sig) then temp else levelu[1];
def leveld = if (val < sig) then temp else leveld[1];

def colorout = if val > levelu then 1 else if val < leveld then -1 else 0;

plot VQILine = val;        # "VQI"
VQILine.SetLineWeight(2);
VQILine.AssignValueColor(if colorout > 0 then Color.GREEN else
                         if colorout < 0 then Color.RED else Color.GRAY);

plot LevelUp = levelu;     # "Level Up"
LevelUp.SetDefaultColor(Color.DARK_GREEN);
plot LevelDown = leveld;   # "Level Down"
LevelDown.SetDefaultColor(Color.DARK_RED);

#--- Sig

def goLong  = crosses(val, levelu, CrossingDirection.ABOVE);
def goShort = crosses(val, leveld, CrossingDirection.BELOW);

plot long = if showSigs and goLong then val else na;#, "Long", color.yellow, no);
long.SetPaintingStrategy(PaintingStrategy.SQUARES);
long.SetDefaultColor(Color.CYAN);
long.SetLineWeight(3);
plot short = if showSigs and goShort then val else na;#, "Short", color.MAGENTA, yes);
short.SetPaintingStrategy(PaintingStrategy.SQUARES);
short.SetDefaultColor(Color.MAGENTA);
short.SetLineWeight(3);

AssignPriceColor(if !Colorbars then Color.CURRENT else
                 if colorout > 0 then Color.GREEN else
                 if colorout < 0 then Color.RED else Color.GRAY);


#--- END CODE

It works.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
268 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