[blackcat] L1 Volatility Quality Index (VQI) for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
XqZKkcV.png


Author Message:
The Volatility Quality Index (VQI) is an indicator used to measure the quality of market volatility. Volatility refers to the extent of price changes in the market. VQI helps traders assess market stability and risk levels by analyzing price volatility. This introduction may be a bit abstract, so let me help you understand it with a comparative metaphor if you're not immersed in various technical indicators.

More Info : https://www.tradingview.com/v/3IP3vsu6/

CODE:
CSS:
# https://www.tradingview.com/v/3IP3vsu6/
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0///
#// © blackcat1402
#indicator('[blackcat] L1 Volatility Quality Index (VQI)', shorttitle='VQI'
# Converted by Sam4Cok@Samer800     - 09/2023
declare lower;
input ColorBars = no;
input length = 14;             # 'Period Length'
input Multiplier = 2.0;        # 'Multiplier'

#-- Colors
DefineGlobalColor("0", CreateColor(32,7,218));
DefineGlobalColor("1", CreateColor(45,10,255));
DefineGlobalColor("2", CreateColor(0,56,255));
DefineGlobalColor("3", CreateColor(0,80,255));
DefineGlobalColor("4", CreateColor(0,98,255));
DefineGlobalColor("5", CreateColor(0,113,255));
DefineGlobalColor("6", CreateColor(0,126,255));
DefineGlobalColor("7", CreateColor(0,137,255));
DefineGlobalColor("8", CreateColor(0,147,255));
DefineGlobalColor("9", CreateColor(0,157,255));
DefineGlobalColor("10", CreateColor(0,165,255));
DefineGlobalColor("11", CreateColor(0,173,255));
DefineGlobalColor("12", CreateColor(0,181,255));
DefineGlobalColor("13", CreateColor(0,188,255));
DefineGlobalColor("14", CreateColor(0,194,255));
DefineGlobalColor("15", CreateColor(0,201,255));
DefineGlobalColor("16", CreateColor(0,207,238));
DefineGlobalColor("17", CreateColor(0,214,217));
DefineGlobalColor("18", CreateColor(0,220,196));
DefineGlobalColor("19", CreateColor(0,226,174));
DefineGlobalColor("20", CreateColor(0,232,152));
DefineGlobalColor("21", CreateColor(0,237,130));
DefineGlobalColor("22", CreateColor(0,242,107));
DefineGlobalColor("23", CreateColor(0,247,83));
DefineGlobalColor("24", CreateColor(0,251,56));
DefineGlobalColor("25", CreateColor(15,254,9));
DefineGlobalColor("26", CreateColor(27,242,10));
DefineGlobalColor("27", CreateColor(51,242,3));
DefineGlobalColor("28", CreateColor(67,243,0));
DefineGlobalColor("29", CreateColor(80,243,0));
DefineGlobalColor("30", CreateColor(91,244,0));
DefineGlobalColor("31", CreateColor(100,244,0));
DefineGlobalColor("32", CreateColor(109,245,0));
DefineGlobalColor("33", CreateColor(118,245,0));
DefineGlobalColor("34", CreateColor(125,245,0));
DefineGlobalColor("35", CreateColor(133,246,0));
DefineGlobalColor("36", CreateColor(140,246,0));
DefineGlobalColor("37", CreateColor(147,247,0));
DefineGlobalColor("38", CreateColor(153,247,0));
DefineGlobalColor("39", CreateColor(159,247,0));
DefineGlobalColor("40", CreateColor(165,248,0));
DefineGlobalColor("41", CreateColor(171,248,0));
DefineGlobalColor("42", CreateColor(177,248,0));
DefineGlobalColor("43", CreateColor(183,248,0));
DefineGlobalColor("44", CreateColor(188,249,0));
DefineGlobalColor("45", CreateColor(194,249,0));
DefineGlobalColor("46", CreateColor(199,249,0));
DefineGlobalColor("47", CreateColor(204,249,0));
DefineGlobalColor("48", CreateColor(209,250,0));
DefineGlobalColor("49", CreateColor(214,250,2));
DefineGlobalColor("50", CreateColor(219,250,9));
DefineGlobalColor("51", CreateColor(246,255,13));
DefineGlobalColor("52", CreateColor(249,247,0));
DefineGlobalColor("53", CreateColor(251,240,0));
DefineGlobalColor("54", CreateColor(253,232,0));
DefineGlobalColor("55", CreateColor(255,224,0));
DefineGlobalColor("56", CreateColor(255,217,0));
DefineGlobalColor("57", CreateColor(255,209,0));
DefineGlobalColor("58", CreateColor(255,201,0));
DefineGlobalColor("59", CreateColor(255,193,0));
DefineGlobalColor("60", CreateColor(255,185,0));
DefineGlobalColor("61", CreateColor(255,177,0));
DefineGlobalColor("62", CreateColor(255,168,0));
DefineGlobalColor("63", CreateColor(255,160,0));
DefineGlobalColor("64", CreateColor(255,152,0));
DefineGlobalColor("65", CreateColor(255,143,0));
DefineGlobalColor("66", CreateColor(255,134,0));
DefineGlobalColor("67", CreateColor(255,125,0));
DefineGlobalColor("68", CreateColor(255,116,0));
DefineGlobalColor("69", CreateColor(255,106,0));
DefineGlobalColor("70", CreateColor(255,96,0));
DefineGlobalColor("71", CreateColor(255,86,0));
DefineGlobalColor("72", CreateColor(255,74,0));
DefineGlobalColor("73", CreateColor(255,62,0));
DefineGlobalColor("74", CreateColor(252,47,0));
DefineGlobalColor("75", CreateColor(250,26,9));
DefineGlobalColor("76", CreateColor(255,30,13));
DefineGlobalColor("77", CreateColor(255,7,27));
DefineGlobalColor("78", CreateColor(255,0,37));
DefineGlobalColor("79", CreateColor(255,0,47));
DefineGlobalColor("80", CreateColor(255,0,56));
DefineGlobalColor("81", CreateColor(255,0,65));
DefineGlobalColor("82", CreateColor(255,0,73));
DefineGlobalColor("83", CreateColor(255,0,82));
DefineGlobalColor("84", CreateColor(255,0,91));
DefineGlobalColor("85", CreateColor(255,0,100));
DefineGlobalColor("86", CreateColor(255,0,110));
DefineGlobalColor("87", CreateColor(255,0,119));
DefineGlobalColor("88", CreateColor(255,0,129));
DefineGlobalColor("89", CreateColor(255,0,138));
DefineGlobalColor("90", CreateColor(255,0,148));
DefineGlobalColor("91", CreateColor(255,0,158));
DefineGlobalColor("92", CreateColor(255,0,168));
DefineGlobalColor("93", CreateColor(255,0,178));
DefineGlobalColor("94", CreateColor(255,0,189));
DefineGlobalColor("95", CreateColor(255,0,199));
DefineGlobalColor("96", CreateColor(255,0,209));
DefineGlobalColor("97", CreateColor(255,0,220));
DefineGlobalColor("98", CreateColor(255,0,230));
DefineGlobalColor("99", CreateColor(255,0,240));
DefineGlobalColor("100", CreateColor(247,9,250));

script pine_alma {
    input series = close;
    input windowsize = 9;
    input offset = 0.85;
    input sigma = 6;
    def m = offset * windowsize;
    def s = windowsize / sigma;
    def norm_ = fold i = 0 to windowsize with p do
       p + Exp(-1 * Power(i - m, 2) / (2 * Power(s, 2)));
    def sum_ = fold j = 0 to windowsize with q do
       q + GetValue(series, windowsize - j) *
           Exp(-1 * Power(j - m, 2) / (2 * Power(s, 2)));
    def sum = sum_;
    def norm = norm_;
    def alma = sum / norm;
    plot out = alma;
}
def atr_value = ATR(Length = length);
def hh = Highest(high, length);
def ll = Lowest(low, length);
def atr_range = hh - ll;
def vqi = atr_range / atr_value * Multiplier;
def vqiLongterm = pine_alma(vqi, 377,  0.85, 6);
def vqi_longterm = vqiLongterm;
def Avg_Value = pine_alma(close, 21, 0.85, 6);
def AvgValue = Avg_Value;
def nRSI = rsi(Price = AvgValue,Length = 21);
def rsi_val = Round(nRSI, 0);
def rsival = rsi_val;

#-- Plot
plot ColQiLine = vqi_longterm;
ColQiLine.SetDefaultColor(Color.WHITE);

plot VolQi = vqi;    # 'VQI'
VolQi.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
VolQi.AssignValueColor(if vqi > vqi_longterm then
                       if rsival <= 0 then  GlobalColor("0") else
                       if rsival <= 1 then  GlobalColor("1") else
                       if rsival <= 2 then  GlobalColor("2") else
                       if rsival <= 3 then  GlobalColor("3") else
                       if rsival <= 4 then  GlobalColor("4") else
                       if rsival <= 5 then  GlobalColor("5") else
                       if rsival <= 6 then  GlobalColor("6") else
                       if rsival <= 7 then  GlobalColor("7") else
                       if rsival <= 8 then  GlobalColor("8") else
                       if rsival <= 9 then  GlobalColor("9") else
                       if rsival <= 10 then  GlobalColor("10") else
                       if rsival <= 11 then  GlobalColor("11") else
                       if rsival <= 12 then  GlobalColor("12") else
                       if rsival <= 13 then  GlobalColor("13") else
                       if rsival <= 14 then  GlobalColor("14") else
                       if rsival <= 15 then  GlobalColor("15") else
                       if rsival <= 16 then  GlobalColor("16") else
                       if rsival <= 17 then  GlobalColor("17") else
                       if rsival <= 18 then  GlobalColor("18") else
                       if rsival <= 19 then  GlobalColor("19") else
                       if rsival <= 20 then  GlobalColor("20") else
                       if rsival <= 21 then  GlobalColor("21") else
                       if rsival <= 22 then  GlobalColor("22") else
                       if rsival <= 23 then  GlobalColor("23") else
                       if rsival <= 24 then  GlobalColor("24") else
                       if rsival <= 25 then  GlobalColor("25") else
                       if rsival <= 26 then  GlobalColor("26") else
                       if rsival <= 27 then  GlobalColor("27") else
                       if rsival <= 28 then  GlobalColor("28") else
                       if rsival <= 29 then  GlobalColor("29") else
                       if rsival <= 30 then  GlobalColor("30") else
                       if rsival <= 31 then  GlobalColor("31") else
                       if rsival <= 32 then  GlobalColor("32") else
                       if rsival <= 33 then  GlobalColor("33") else
                       if rsival <= 34 then  GlobalColor("34") else
                       if rsival <= 35 then  GlobalColor("35") else
                       if rsival <= 36 then  GlobalColor("36") else
                       if rsival <= 37 then  GlobalColor("37") else
                       if rsival <= 38 then  GlobalColor("38") else
                       if rsival <= 39 then  GlobalColor("39") else
                       if rsival <= 40 then  GlobalColor("40") else
                       if rsival <= 41 then  GlobalColor("41") else
                       if rsival <= 42 then  GlobalColor("42") else
                       if rsival <= 43 then  GlobalColor("43") else
                       if rsival <= 44 then  GlobalColor("44") else
                       if rsival <= 45 then  GlobalColor("45") else
                       if rsival <= 46 then  GlobalColor("46") else
                       if rsival <= 47 then  GlobalColor("47") else
                       if rsival <= 48 then  GlobalColor("48") else
                       if rsival <= 49 then  GlobalColor("49") else
                       if rsival <= 50 then  GlobalColor("50") else
                       if rsival <= 51 then  GlobalColor("51") else
                       if rsival <= 52 then  GlobalColor("52") else
                       if rsival <= 53 then  GlobalColor("53") else
                       if rsival <= 54 then  GlobalColor("54") else
                       if rsival <= 55 then  GlobalColor("55") else
                       if rsival <= 56 then  GlobalColor("56") else
                       if rsival <= 57 then  GlobalColor("57") else
                       if rsival <= 58 then  GlobalColor("58") else
                       if rsival <= 59 then  GlobalColor("59") else
                       if rsival <= 60 then  GlobalColor("60") else
                       if rsival <= 61 then  GlobalColor("61") else
                       if rsival <= 62 then  GlobalColor("62") else
                       if rsival <= 63 then  GlobalColor("63") else
                       if rsival <= 64 then  GlobalColor("64") else
                       if rsival <= 65 then  GlobalColor("65") else
                       if rsival <= 66 then  GlobalColor("66") else
                       if rsival <= 67 then  GlobalColor("67") else
                       if rsival <= 68 then  GlobalColor("68") else
                       if rsival <= 69 then  GlobalColor("69") else
                       if rsival <= 70 then  GlobalColor("70") else
                       if rsival <= 71 then  GlobalColor("71") else
                       if rsival <= 72 then  GlobalColor("72") else
                       if rsival <= 73 then  GlobalColor("73") else
                       if rsival <= 74 then  GlobalColor("74") else
                       if rsival <= 75 then  GlobalColor("75") else
                       if rsival <= 76 then  GlobalColor("76") else
                       if rsival <= 77 then  GlobalColor("77") else
                       if rsival <= 78 then  GlobalColor("78") else
                       if rsival <= 79 then  GlobalColor("79") else
                       if rsival <= 80 then  GlobalColor("80") else
                       if rsival <= 81 then  GlobalColor("81") else
                       if rsival <= 82 then  GlobalColor("82") else
                       if rsival <= 83 then  GlobalColor("83") else
                       if rsival <= 84 then  GlobalColor("84") else
                       if rsival <= 85 then  GlobalColor("85") else
                       if rsival <= 86 then  GlobalColor("86") else
                       if rsival <= 87 then  GlobalColor("87") else
                       if rsival <= 88 then  GlobalColor("88") else
                       if rsival <= 89 then  GlobalColor("89") else
                       if rsival <= 90 then  GlobalColor("90") else
                       if rsival <= 91 then  GlobalColor("91") else
                       if rsival <= 92 then  GlobalColor("92") else
                       if rsival <= 93 then  GlobalColor("93") else
                       if rsival <= 94 then  GlobalColor("94") else
                       if rsival <= 95 then  GlobalColor("95") else
                       if rsival <= 96 then  GlobalColor("96") else
                       if rsival <= 97 then  GlobalColor("97") else
                       if rsival <= 98 then  GlobalColor("98") else
                       if rsival <= 99 then  GlobalColor("99") else
                         GlobalColor("100") else Color.GRAY);

AssignPriceColor(if !ColorBars then Color.CURRENT else
                       if vqi <= vqi_longterm then Color.GRAY else
                       if rsival <= 0 then  GlobalColor("0") else
                       if rsival <= 1 then  GlobalColor("1") else
                       if rsival <= 2 then  GlobalColor("2") else
                       if rsival <= 3 then  GlobalColor("3") else
                       if rsival <= 4 then  GlobalColor("4") else
                       if rsival <= 5 then  GlobalColor("5") else
                       if rsival <= 6 then  GlobalColor("6") else
                       if rsival <= 7 then  GlobalColor("7") else
                       if rsival <= 8 then  GlobalColor("8") else
                       if rsival <= 9 then  GlobalColor("9") else
                       if rsival <= 10 then  GlobalColor("10") else
                       if rsival <= 11 then  GlobalColor("11") else
                       if rsival <= 12 then  GlobalColor("12") else
                       if rsival <= 13 then  GlobalColor("13") else
                       if rsival <= 14 then  GlobalColor("14") else
                       if rsival <= 15 then  GlobalColor("15") else
                       if rsival <= 16 then  GlobalColor("16") else
                       if rsival <= 17 then  GlobalColor("17") else
                       if rsival <= 18 then  GlobalColor("18") else
                       if rsival <= 19 then  GlobalColor("19") else
                       if rsival <= 20 then  GlobalColor("20") else
                       if rsival <= 21 then  GlobalColor("21") else
                       if rsival <= 22 then  GlobalColor("22") else
                       if rsival <= 23 then  GlobalColor("23") else
                       if rsival <= 24 then  GlobalColor("24") else
                       if rsival <= 25 then  GlobalColor("25") else
                       if rsival <= 26 then  GlobalColor("26") else
                       if rsival <= 27 then  GlobalColor("27") else
                       if rsival <= 28 then  GlobalColor("28") else
                       if rsival <= 29 then  GlobalColor("29") else
                       if rsival <= 30 then  GlobalColor("30") else
                       if rsival <= 31 then  GlobalColor("31") else
                       if rsival <= 32 then  GlobalColor("32") else
                       if rsival <= 33 then  GlobalColor("33") else
                       if rsival <= 34 then  GlobalColor("34") else
                       if rsival <= 35 then  GlobalColor("35") else
                       if rsival <= 36 then  GlobalColor("36") else
                       if rsival <= 37 then  GlobalColor("37") else
                       if rsival <= 38 then  GlobalColor("38") else
                       if rsival <= 39 then  GlobalColor("39") else
                       if rsival <= 40 then  GlobalColor("40") else
                       if rsival <= 41 then  GlobalColor("41") else
                       if rsival <= 42 then  GlobalColor("42") else
                       if rsival <= 43 then  GlobalColor("43") else
                       if rsival <= 44 then  GlobalColor("44") else
                       if rsival <= 45 then  GlobalColor("45") else
                       if rsival <= 46 then  GlobalColor("46") else
                       if rsival <= 47 then  GlobalColor("47") else
                       if rsival <= 48 then  GlobalColor("48") else
                       if rsival <= 49 then  GlobalColor("49") else
                       if rsival <= 50 then  GlobalColor("50") else
                       if rsival <= 51 then  GlobalColor("51") else
                       if rsival <= 52 then  GlobalColor("52") else
                       if rsival <= 53 then  GlobalColor("53") else
                       if rsival <= 54 then  GlobalColor("54") else
                       if rsival <= 55 then  GlobalColor("55") else
                       if rsival <= 56 then  GlobalColor("56") else
                       if rsival <= 57 then  GlobalColor("57") else
                       if rsival <= 58 then  GlobalColor("58") else
                       if rsival <= 59 then  GlobalColor("59") else
                       if rsival <= 60 then  GlobalColor("60") else
                       if rsival <= 61 then  GlobalColor("61") else
                       if rsival <= 62 then  GlobalColor("62") else
                       if rsival <= 63 then  GlobalColor("63") else
                       if rsival <= 64 then  GlobalColor("64") else
                       if rsival <= 65 then  GlobalColor("65") else
                       if rsival <= 66 then  GlobalColor("66") else
                       if rsival <= 67 then  GlobalColor("67") else
                       if rsival <= 68 then  GlobalColor("68") else
                       if rsival <= 69 then  GlobalColor("69") else
                       if rsival <= 70 then  GlobalColor("70") else
                       if rsival <= 71 then  GlobalColor("71") else
                       if rsival <= 72 then  GlobalColor("72") else
                       if rsival <= 73 then  GlobalColor("73") else
                       if rsival <= 74 then  GlobalColor("74") else
                       if rsival <= 75 then  GlobalColor("75") else
                       if rsival <= 76 then  GlobalColor("76") else
                       if rsival <= 77 then  GlobalColor("77") else
                       if rsival <= 78 then  GlobalColor("78") else
                       if rsival <= 79 then  GlobalColor("79") else
                       if rsival <= 80 then  GlobalColor("80") else
                       if rsival <= 81 then  GlobalColor("81") else
                       if rsival <= 82 then  GlobalColor("82") else
                       if rsival <= 83 then  GlobalColor("83") else
                       if rsival <= 84 then  GlobalColor("84") else
                       if rsival <= 85 then  GlobalColor("85") else
                       if rsival <= 86 then  GlobalColor("86") else
                       if rsival <= 87 then  GlobalColor("87") else
                       if rsival <= 88 then  GlobalColor("88") else
                       if rsival <= 89 then  GlobalColor("89") else
                       if rsival <= 90 then  GlobalColor("90") else
                       if rsival <= 91 then  GlobalColor("91") else
                       if rsival <= 92 then  GlobalColor("92") else
                       if rsival <= 93 then  GlobalColor("93") else
                       if rsival <= 94 then  GlobalColor("94") else
                       if rsival <= 95 then  GlobalColor("95") else
                       if rsival <= 96 then  GlobalColor("96") else
                       if rsival <= 97 then  GlobalColor("97") else
                       if rsival <= 98 then  GlobalColor("98") else
                       if rsival <= 99 then  GlobalColor("99") else
                         GlobalColor("100"));

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