Volume Analysis for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
tn6vxpp.png


This indicator is based on Volume . It shows multi colored volume based on your defined ratio with Bar color option


CODE:
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © Codextent
#indicator(title='Volume Analysis', shorttitle='VolAna')
# Converted and mod by Sam4Cok@Samer800 - 12/2022
declare lower;
input BarColor            = yes;
input showVolMA           = {Default Histogram, Line, None};    # 'Show Moving Average'
input lengthVolumeMA      = 22;     # 'Length of MA applied on Volume'
input ratioUltraVolume    = 2.4;    # 'Ultra Ratio'
input ratioVeryHighVolume = 1.8;    # 'Very High Ratio'
input ratioHighVolume     = 1.2;    # 'High Ratio'
input ratioNormalVolume   = 0.8;    # 'Normal Ratio'
input ratioLowVolume      = 0.4;    # 'Low Ratio'
input ratioVeryLowVolume  = 0.2;    # 'Very Low Ratio'

def na = Double.NaN;
def Style = if showVolMA==showVolMA.Histogram then 1 else
            if showVolMA==showVolMA.Line then -1 else 0;
def volStyle = Style;
def raising = close > open;
def v = volume;
script nz {
    input data  = close;
    input repl  = 0;
    def ret_val = if IsNaN(data) then repl else data;
    plot return = ret_val;
}
script nzero {
    input data  = close;
    input repl  = 0;
    def ret_val = if data <= 0 then repl else data;
    plot return = ret_val;
}
#----Colors
DefineGlobalColor("UltHigh" , Color.GREEN);
DefineGlobalColor("VeryHigh", Color.DARK_GREEN);
DefineGlobalColor("High"    , Color.LIGHT_GREEN);
DefineGlobalColor("Normal"  , Color.WHITE);
DefineGlobalColor("Low"     , Color.GRAY);
DefineGlobalColor("VLow"    , Color.DARK_GRAY);
DefineGlobalColor("UltLow"  , Color.RED);
DefineGlobalColor("VeryLow" , Color.DARK_RED);
DefineGlobalColor("lHigh"   , Color.PINK);
DefineGlobalColor("ma"      , CreateColor(54,58,69));
#// Volume MA
def volumeMA;
volumeMA = nzero(volumeMA[1],v) + (v - nz(volumeMA[1])) / lengthVolumeMA;
#// Ratio
def ultraHighVolumeMin = volumeMA * ratioUltraVolume;
def veryHighVolumeMin  = volumeMA * ratioVeryHighVolume;
def highVolumeMin      = volumeMA * ratioHighVolume;
def normalVolumeMin    = volumeMA * ratioNormalVolume;
def lowVolumeMin       = volumeMA * ratioLowVolume;
def veryLowVolumeMin   = volumeMA * ratioVeryLowVolume;
#// Ratio check
def volUltraHigh = if v >= ultraHighVolumeMin then 1 else 0;
def volVeryHigh  = if v >= veryHighVolumeMin and v < ultraHighVolumeMin then 1 else 0;
def volHigh      = if v >= highVolumeMin and v < veryHighVolumeMin then 1 else 0;
def volNormal    = if v >= normalVolumeMin and v < highVolumeMin then 1 else 0;
def volLow       = if v >= lowVolumeMin and v < normalVolumeMin then 1 else 0;
def volVeryLow   = if v < lowVolumeMin then 1 else 0;

#//Plot
def palette = if volUltraHigh then 3 else if volVeryHigh then 2 else if volHigh then 1 else
              if volNormal then 0 else if volLow then -1 else -2;
plot VolHist = if raising then v else v * -1;#, color=palette, style=plot.style_columns, title='Volume')
VolHist.SetLineWeight(2);
VolHist.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
VolHist.AssignValueColor(if raising then
                         if palette==3  then GlobalColor("UltHigh") else
                         if palette==2  then GlobalColor("VeryHigh") else
                         if palette==1  then GlobalColor("High") else
                         if palette==0  then GlobalColor("Normal") else
                         if palette==-1 then GlobalColor("Low") else GlobalColor("VLow") else
                         if palette>2   then GlobalColor("UltLow") else
                         if palette>1   then GlobalColor("VeryLow") else
                         if palette>0   then GlobalColor("lHigh") else
                         if palette>-1  then GlobalColor("Normal") else
                         if palette>-2  then GlobalColor("Low") else GlobalColor("VLow"));
plot VolMa   = if Style!=0 then volumeMA else na;    #'Volume MA'
VolMa.SetDefaultColor(GlobalColor("ma"));
VolMa.SetLineWeight(5);
VolMa.SetPaintingStrategy(if volStyle> 0 then PaintingStrategy.HISTOGRAM else PaintingStrategy.LINE);
plot VolMaLo   = if Style!=0 then -volumeMA else na;    #'Volume MA'
VolMaLo.SetPaintingStrategy(if volStyle> 0 then PaintingStrategy.HISTOGRAM else PaintingStrategy.LINE);
VolMaLo.SetDefaultColor(GlobalColor("ma"));
VolMaLo.SetLineWeight(5);


AssignPriceColor(if !BarColor then Color.CURRENT else if raising then
                 if palette==3  then GlobalColor("UltHigh") else
                 if palette==2  then GlobalColor("VeryHigh") else
                 if palette==1  then GlobalColor("High") else
                 if palette==0  then GlobalColor("Normal") else
                 if palette==-1 then GlobalColor("Low") else GlobalColor("VLow") else
                 if palette==3  then GlobalColor("UltLow") else
                 if palette==2  then GlobalColor("VeryLow") else
                 if palette==1  then GlobalColor("lHigh") else
                 if palette==0  then GlobalColor("Normal") else
                 if palette==-1 then GlobalColor("Low") else GlobalColor("VLow"));

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

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