Multiple Frequency Volatility Correlation for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
IZ4ns1K.png



// description:
// This is a complex indicator that looks to provide some insight
// into the correlation between volume and price volatility.
// Rising volatility is depicted with the color green while falling
// volatility is depicted with purple.
// Lightness of the color is used to depict the length of the window
// used, darker == shorter in the 0 -> 512 window range.

CODE:


CSS:
#// © RicardoSantos
#//@version=5
#indicator('Multiple Frequency Volatility Correlation', shorttitle='MFVC'
#// description:
#//  This is a complex indicator that looks to provide some insight
#//  into the correlation between volume and price volatility.
#//  Rising volatility is depicted with the color green while falling
#//  volatility is depicted with purple.
#//  Lightness of the color is used to depict the length of the window
#//  used, darker == shorter in the 0 -> 512 window range.

# Converted by Sam4COK@Samer800 - 08/2022

declare lower;
input smoothing = 10;

#import RicardoSantos/ColorExtension/4 as colExt
#// @function determines color and correlation level.
#hsl (hue, Saturation, lightness) =>
script hsl {
input hue=0.0;
input saturation=0.0;
input lightness=0.0;
    def _h_30 = hue / 30.0;
    def _l1 = lightness * 0.01;
    def _a = saturation * min(_l1, 1.0 - _l1) * 0.01;
    def _rk = _h_30 % 12.0;
    def _r = 255.0 * (_l1 - _a * max(min(min(_rk - 3.0, 9.0 - _rk), 1.0), -1.0));
    def _gk = (8.0 + _h_30) % 12.0;
    def _g = 255.0 * (_l1 - _a * max(min(min(_gk - 3.0, 9.0 - _gk), 1.0), -1.0));
    def _bk = (4.0 + _h_30) % 12.0;
    def _b = 255.0 * (_l1 - _a * max(min(min(_bk - 3.0, 9.0 - _bk), 1.0), -1.0));
  plot r = _r;
  plot g = _g;
  plot b = _b;
}
#vc (window, smoothing) =>
script vc {
input window = 0;
input smoothing = 0;
    def _price = stdev(close, window);
    def _vol   = stdev(volume, window);
    def _cor   = Correlation(_price, _vol, smoothing);
    def _vol_filter = if (_price > _price[1]) then 100 else 300;# // green : purple
    def _win_filter = 25 + (window / 512) * 40; # // higher value, lighter color
plot cor =  _cor;
plot r   = hsl(_vol_filter, 60, _win_filter).r;
plot g   = hsl(_vol_filter, 60, _win_filter).g;
plot b   = hsl(_vol_filter, 60, _win_filter).b;

}
#//
def v002 = vc(  2, smoothing).cor;
def r002 = vc(  2, smoothing).r;
def g002 = vc(  2, smoothing).g;
def b002 = vc(  2, smoothing).b;

def v003 = vc(  3, smoothing).cor;
def r003 = vc(  3, smoothing).r;
def g003 = vc(  3, smoothing).g;
def b003 = vc(  3, smoothing).b;

def v004 = vc(  4, smoothing).cor;
def r004 = vc(  4, smoothing).r;
def g004 = vc(  4, smoothing).g;
def b004 = vc(  4, smoothing).b;

def v006 = vc(  6, smoothing).cor;
def r006 = vc(  6, smoothing).r;
def g006 = vc(  6, smoothing).g;
def b006 = vc(  6, smoothing).b;

def v008 = vc(  8, smoothing).cor;
def r008 = vc(  8, smoothing).r;
def g008 = vc(  8, smoothing).g;
def b008 = vc(  8, smoothing).b;

def v012 = vc( 12, smoothing).cor;
def r012 = vc( 12, smoothing).r;
def g012 = vc( 12, smoothing).g;
def b012 = vc( 12, smoothing).b;

def v016 = vc( 16, smoothing).cor;
def r016 = vc( 16, smoothing).r;
def g016 = vc( 16, smoothing).g;
def b016 = vc( 16, smoothing).b;

def v024 = vc( 24, smoothing).cor;
def r024 = vc( 24, smoothing).r;
def g024 = vc( 24, smoothing).g;
def b024 = vc( 24, smoothing).b;

def v032 = vc( 32, smoothing).cor;
def r032 = vc( 32, smoothing).r;
def g032 = vc( 32, smoothing).g;
def b032 = vc( 32, smoothing).b;

def v048 = vc( 48, smoothing).cor;
def r048 = vc( 48, smoothing).r;
def g048 = vc( 48, smoothing).g;
def b048 = vc( 48, smoothing).b;

def v064 = vc( 64, smoothing).cor;
def r064 = vc( 64, smoothing).r;
def g064 = vc( 64, smoothing).g;
def b064 = vc( 64, smoothing).b;

def v096 = vc( 96, smoothing).cor;
def r096 = vc( 96, smoothing).r;
def g096 = vc( 96, smoothing).g;
def b096 = vc( 96, smoothing).b;

def v128 = vc(128, smoothing).cor;
def r128 = vc( 32, smoothing).r;
def g128 = vc( 32, smoothing).g;
def b128 = vc( 32, smoothing).b;

def v192 = vc(192, smoothing).cor;
def r192 = vc(192, smoothing).r;
def g192 = vc(192, smoothing).g;
def b192 = vc(192, smoothing).b;

def v256 = vc(256, smoothing).cor;
def r256 = vc(256, smoothing).r;
def g256 = vc(256, smoothing).g;
def b256 = vc(256, smoothing).b;

def v384 = vc(384, smoothing).cor;
def r384 = vc(384, smoothing).r;
def g384 = vc(384, smoothing).g;
def b384 = vc(384, smoothing).b;

def v512 = vc(512, smoothing).cor;
def r512 = vc(512, smoothing).r;
def g512 = vc(512, smoothing).g;
def b512 = vc(512, smoothing).b;


def data = v002 + v003+ v004+ v006+ v008+ v012+ v016+ v024+ v032+ v048+ v064+ v096+ v128+ v192+ v256+ v384+ v512;

def min = min(v002,min( v003,min( v004,min( v006, min(v008,min( v012, min(v016, min(v024,min( v032,
      min(v048,min( v064,min( v096,min( v128,min( v192, min(v256, min(v384, v512))))))))))))))));
def max = max(v002,max( v003,max( v004,max( v006, max(v008,max( v012, max(v016, max(v024,max( v032,
      max(v048,max( v064,max( v096,max( v128,max( v192, max(v256, max(v384, v512))))))))))))))));
def avg = data / 17;

plot series2=v002;
series2.SetStyle(Curve.POINTS);
series2.AssignValueColor(CreateColor(r002,g002,b002));

plot series3=v003;
series3.SetStyle(Curve.POINTS);
series3.AssignValueColor(CreateColor(r003,g003,b003));

plot series4=v004;
series4.SetStyle(Curve.POINTS);
series4.AssignValueColor(CreateColor(r004,g004,b004));

plot series6=v006;
series6.SetStyle(Curve.POINTS);
series6.AssignValueColor(CreateColor(r006,g006,b006));

plot series8=v008;
series8.SetStyle(Curve.POINTS);
series8.AssignValueColor(CreateColor(r008,g008,b008));

plot series12=v012;
series12.SetStyle(Curve.POINTS);
series12.AssignValueColor(CreateColor(r012,g012,b012));

plot series16=v016;
series16.SetStyle(Curve.POINTS);
series16.AssignValueColor(CreateColor(r016,g016,b016));

plot series24=v024;
series24.SetStyle(Curve.POINTS);
series24.AssignValueColor(CreateColor(r024,g024,b024));

plot series32=v032;
series32.SetStyle(Curve.POINTS);
series32.AssignValueColor(CreateColor(r032,g032,b032));

plot series48=v048;
series48.SetStyle(Curve.POINTS);
series48.AssignValueColor(CreateColor(r048,g048,b048));

plot series64=v064;
series64.SetStyle(Curve.POINTS);
series64.AssignValueColor(CreateColor(r064,g064,b064));

plot series96=v096;
series96.SetStyle(Curve.POINTS);
series96.AssignValueColor(CreateColor(r064,g064,b064));

plot series128=v128;
series128.SetStyle(Curve.POINTS);
series128.AssignValueColor(CreateColor(r128,g128,b128));

plot series192=v192;
series192.SetStyle(Curve.POINTS);
series192.AssignValueColor(CreateColor(r192,g192,b192));

plot series256=v256;
series256.SetStyle(Curve.POINTS);
series256.AssignValueColor(CreateColor(r256,g256,b256));

plot series384=v384;
series384.SetStyle(Curve.POINTS);
series384.AssignValueColor(CreateColor(r384,g384,b384));

plot series512=v512;
series512.SetStyle(Curve.POINTS);
series512.AssignValueColor(CreateColor(r512,g512,b512));

plot seriesmin = min;
seriesmin.SetDefaultColor(CreateColor(120, 123, 134));
plot seriesmax = max;
seriesmax.SetDefaultColor(CreateColor(120, 123, 134));
plot seriesavg = avg;
seriesavg.SetDefaultColor(Color.WHITE);
seriesavg.SetLineWeight(2);

plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.GRAY);
ZeroLine.SetPaintingStrategy(PaintingStrategy.DASHES);


##### END
 

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