Heatmap & Volume Spread Analysis for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
b57tVCg.png

MgF8j4D.png


two different volume study to select from.
Heatmap volume:
This indicator colors the volume bars and candles according to the volume traded. The calculation of the heat map zones is done as follows:
how many standard deviations the volume are distant from the average volume?.
VSA:
This indicator tells us whether the volume is ultrahigh volume ,high volume , low volume or average volume . These volume has to be used along with price spread.

CODE:

CSS:
#######################################################
# Combines heatmap and Volume Spread Analysis studies
# combined and mod by Sam4COK @ Samer800 - 09/2022
#------------------------------------------------------
#study(title="Heatmap Volume [xdecow]"
#https://www.tradingview.com/script/unWex8N4-Heatmap-Volume-xdecow/
#######################################################################
declare lower;
declare zerobase;
input VolumeAnalysis = {Default Heatmap, VolumeSpread};
input ColorAnalysis = yes;
input ShowCloud    = yes;
input ShowMALine   = yes;
input maTypeInput = {"WMA", "SMA", "EMA", "VWMA",default "SMMA", "LSMA"};
input maLength     = 30;     
input heatLength = 610;        # For Heatmap
input StdLength  = 610;        # For Heatmap
input thresholdHigh   =  3.0;
input thresholdMedium =  1.5;
input thresholdLow    =  0.5;
input thresholdNormal =  -0.5; # For Heatmap

def na = Double.NaN;
script nz {
    input data  = volume;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}
####################################################################
DefineGlobalColor("extra_high", CreateColor(255,0,0));    # red
DefineGlobalColor("high",       CreateColor(255,120,0));  # orange
DefineGlobalColor("medium",     CreateColor(255,207,3));  # yellow
DefineGlobalColor("normal",     CreateColor(160,214,220));# sky
DefineGlobalColor("low",        CreateColor(65,59,178)); # light blue

def VolAnalysis = if VolumeAnalysis == VolumeAnalysis.Heatmap then 1 else 0;
##################################################################
#                          MA Line                               #
##################################################################

#vwma(source, length)
script VWMA {
    input x = volume;
    input y = 30;
    def VWMA = SimpleMovingAvg(x * volume, y) / SimpleMovingAvg(volume, y);
    plot result = VWMA;
}
########### SCRIPT
#ma(source, length, type) =>
script ma {
    input source = volume;
    input length = 30;
    input type   = "SMA";
    def w = WMA(source, length);
    def ma;
    ma = if type == "SMA" then SimpleMovingAvg(source, length) else
         if type == "EMA" then ExpAverage(source, length) else
         if type == "WMA" then WMA(source, length) else
         if type == "VWMA" then VWMA(source, length) else
         if type == "LSMA" then Inertia(source, length) else
         if type == "SMMA" then if isNaN(w[1]) then SimpleMovingAvg(source, length) else
                    (w[1] * (length - 1) + source) / length else Double.NaN;
    plot result = ma;
}
#//-***** Calculations ***** \\

def avg = ma(volume, maLength, maTypeInput);

plot VolAvg = Avg;
VolAvg.SetHiding(!ShowMALine);
VolAvg.SetStyle(Curve.FIRM);
VolAvg.SetDefaultColor(Color.MAGENTA);
VolAvg.SetLineWeight(1);

################################################################################
#pstdev(Series, Period) =>
script pstdev {
    input Series = volume;
    input Period = 0;
    def mean = Sum(Series, Period) / Period;
    def summation = if IsNaN(summation[1]) then 0 else
                    fold i = 0 to Period - 1 with p do
                     p + ((Series[i] - mean) * (Series[i] - mean));
    plot return = Sqrt(summation / Period);
}

def mean    = SimpleMovingAvg(volume, heatLength);
def std     = pstdev(volume, StdLength);
def stdbar  = (volume - mean) / std;
def dir     = close > open;
def vol     = volume;
def mosc    = mean;

#-- heatmap lines

def ts1 = std * thresholdHigh + mosc;
def ts2 = std * thresholdMedium + mosc;
def ts3 = std * thresholdLow + mosc;
def ts4 = std * thresholdNormal + mosc;

plot volplot  = volume;
volplot.SetLineWeight(2);
volplot.SetHiding(ColorAnalysis);
volplot.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
volplot.AssignValueColor(if dir  then CreateColor(0,175,0) else
                                      CreateColor(239,83,80));
volplot.HideTitle();
volplot.HideBubble();

def bcolor = if VolAnalysis then if ColorAnalysis then if stdbar > thresholdHigh then 4 else
             if stdbar > thresholdMedium then 3 else
             if stdbar > thresholdLow then 2 else
             if stdbar > thresholdNormal then 1 else 0 else na else na;

AddChart(high = if bcolor == 4 then volume else na ,
         low = 0,
         open = volume,
         close = 0,
         type = ChartType.CANDLE, growcolor = GlobalColor("extra_high"));
AddChart(high = if bcolor == 3 then volume else na,
         low = 0,
         open = volume,
         close = 0,
         type = ChartType.CANDLE, growcolor = GlobalColor("high"));
AddChart(high = if bcolor == 2 then volume else na,
         low = 0,
         open = volume,
         close = 0,
         type = ChartType.CANDLE, growcolor = GlobalColor("medium"));
AddChart(high = if bcolor == 1 then volume else na,
         low = 0,
         open = volume,
         close = 0,
         type = ChartType.CANDLE, growcolor = GlobalColor("normal"));
AddChart(high = if bcolor == 0 then volume else na,
         low = 0,
         open = volume,
         close = 0,
         type = ChartType.CANDLE, growcolor = GlobalColor("low"));

AddCloud (if VolAnalysis then if ShowCloud then ts1 else na else na, ts2, GlobalColor("high"));
AddCloud (if VolAnalysis then if ShowCloud then ts2 else na else na, ts3, GlobalColor("medium"));
AddCloud (if VolAnalysis then if ShowCloud then ts3 else na else na, ts4, GlobalColor("normal"));
AddCloud (if VolAnalysis then if ShowCloud then ts4 else na else na, 0, GlobalColor("low"));

### VSA
#// © theehoganator
#https://www.tradingview.com/script/hEsIX3VF-Volume-Spread-for-VSA-Custom/
#indicator(title="Volume Spread Analysis Custom",

def ma1 = avg * thresholdLow;
def ma2 = avg * thresholdMedium;
def ma3 = avg * thresholdHigh;

#//-***** Plot Everything ***** \\

def ma1plot = if !VolAnalysis and ShowCloud then ma1 else na; # "Moving Average 1"
def ma2plot = if !VolAnalysis and ShowCloud then ma2 else na; # "Moving Average 2"
def ma3plot = if !VolAnalysis and ShowCloud then ma3 else na; # "Moving Average 3"

AddCloud(ma1plot, 0, Color.GRAY); # "Low Volume Background"
AddCloud(ma2plot, ma1plot, Color.ORANGE);# "Med  Volume Background"
AddCloud(ma2plot,  ma3plot, Color.DARK_RED); # "High Volume Background"

def m1 = !VolAnalysis and ColorAnalysis and volume < ma1;
def m2 = !VolAnalysis and ColorAnalysis and !m1 and volume < ma2;
def m3 = !VolAnalysis and ColorAnalysis and !m1 and !m2 and volume < ma3;
def m4 = !VolAnalysis and ColorAnalysis and volume > ma3;
AddChart(high = if m1 then volume else na,
         low = 0,
         open = volume,
         close = 0,
         type = ChartType.CANDLE, growcolor = CreateColor(65,59,178));
AddChart(high = if m2 then volume else na,
         low = 0,
         open = volume,
         close = 0,
         type = ChartType.CANDLE, growcolor = CreateColor(160,214,220));
AddChart(high = if m3 then volume else na,
         low = 0,
         open = volume,
         close = 0,
         type = ChartType.CANDLE, growcolor = Color.Yellow);
AddChart(high = if m4 then volume else na,
         low = 0,
         open = volume,
         close = 0,
         type = ChartType.CANDLE, growcolor = Color.Red);

#### END Code
 
Last edited by a moderator:

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

Hi guys, is there any way to use this indicator in the scanner, to scan for ultra high candles. @samer800 @BenTen Please help us to get this Indicator in Scaner, Thanks in advance
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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