Better Volume Indicator for ThinkorSwim

netarchitech

Well-known member
# TS_BetterVolume_Indicator
# A better volume indicator with color coded histogram plot that shows 4 different colors depending on price action and volume.
# Yellow - Low volume for the size of the bar - Amateurs at work
# White - Climax down
# Blue -Climax up
# Red - Churn - Pros buying at lows or unloading at highs
# Magenta - Climax Churn - Pros taking profits at highs or lows
# Gray - Normal (default) Bar

vNHOUnE.png


thinkScript Code

Rich (BB code):
#
#Better Volume for Thinkorswim
#
#
#hint: Verbatim translation of the TradeStation code from http://emini-watch.com/free-stuff/volume-indicator/
#==========================================================================

#DECLARATIONS
#==========================================================================
declare on_volume;
declare real_size;

#INPUTS
#==========================================================================
input iShowLowVol      = YES;
input iShowClimaxUp    = YES;
input iShowClimaxDown  = YES;
input iShowChurn       = YES;
input iShowClimaxChurn = YES;

input iUseTwoBars = {default "YES", "NO"};
input iLookback   = 20;

#VARS
#==========================================================================
def vValue1;
def vValue2;
def vValue3;
def vValue4;
def vValue5;
def vValue6;
def vValue7;
def vValue8;
def vValue9;
def vValue10;
def vValue11;
def vValue12;
def vValue13;
def vValue14;
def vValue15;
def vValue16;
def vValue17;
def vValue18;
def vValue19;
def vValue20;
def vValue21;
def vValue22;

def vCondition1;
def vCondition2;
def vCondition3;
def vCondition4;
def vCondition5;
def vCondition6;
def vCondition7;
def vCondition8;
def vCondition9;
def vCondition10;
def vCondition11;
def vCondition12;
def vCondition13;
def vCondition14;
def vCondition15;
def vCondition16;
def vCondition17;
def vCondition18;
def vCondition19;
def vCondition20;

def vRange;

#LOGIC
#==========================================================================
vRange = high - low;

if close > open and vRange <> 0
    then {vValue1 = (vRange/(2*vRange + open - close))*volume;
          vValue2 = volume - vValue1;}
else if close < open and vRange <> 0
    then {vValue1 = ((vRange + close - open)/(2*vRange + close - open))*volume;
          vValue2 = volume - vValue1;}
else if close == open
    then {vValue1 = 0.5*volume;
          vValue2 = volume - vValue1;}
    else {vValue1 = 0;
          vValue2 = 0;}

vValue3 = AbsValue(vValue1 + vValue2);
vValue4 = vValue1*vRange;
vValue5 = (vValue1 - vValue2)*vRange;
vValue6 = vValue2*vRange;
vValue7 = (vValue2 - vValue1)*vRange;

if vRange <> 0
    then {vValue8  = vValue1/vRange;
          vValue9  = (vValue1 - vValue2)/vRange;
          vValue10 = vValue2/vRange;
          vValue11 = (vValue2 - vValue1)/vRange;
          vValue12 = vValue3/vRange;}
    else {vValue8  = 0;
          vValue9  = 0;
          vValue10 = 0;
          vValue11 = 0;
          vValue12 = 0;}

switch(iUseTwoBars)
{
    case "YES":
        vValue13 = vValue3 + vValue3[1];
        vValue14 = (vValue1 + vValue1[1])*(Highest(high,2) - Lowest(low,2));
        vValue15 = (vValue1 + vValue1[1] - vValue2 - vValue2[1])*(Highest(high,2) - Lowest(low,2));
        vValue16 = (vValue2 + vValue2[1])*(Highest(high,2) - Lowest(low,2));
        vValue17 = (vValue2 + vValue2[1] - vValue1 - vValue1[1])*(Highest(high,2) - Lowest(low,2));
  
        if Highest(high,2) <> Lowest(low,2)
            then {vValue18 = (vValue1 + vValue1[1])/(Highest(high,2) - Lowest(low,2));
                  vValue19 = (vValue1 + vValue1[1] - vValue2 - vValue2[1])/(Highest(high,2) - Lowest(low,2));
                  vValue20 = (vValue2 + vValue2[1])/(Highest(high,2) - Lowest(low,2));
                  vValue21 = (vValue2 + vValue2[1] - vValue1 - vValue1[1])/(Highest(high,2) - Lowest(low,2));
                  vValue22 = vValue13/(Highest(high,2) - Lowest(low,2));}
            else {vValue18 = 0;
                  vValue19 = 0;
                  vValue20 = 0;
                  vValue21 = 0;
                  vValue22 = 0;}
  
        vCondition1  = 0;
        vCondition2  = 0;
        vCondition3  = 0;
        vCondition4  = 0;
        vCondition5  = 0;
        vCondition6  = 0;
        vCondition7  = 0;
        vCondition8  = 0;
        vCondition9  = 0;
        vCondition10 = 0;
        vCondition11 = vValue13 == Lowest(vValue13, iLookback);
        vCondition12 = vValue14 == Highest(vValue14, iLookback) and close > open and close[1] > open[1];
        vCondition13 = vValue15 == Highest(vValue15, iLookback) and close > open and close[1] > open[1];
        vCondition14 = vValue16 == Highest(vValue16, iLookback) and close < open and close[1] < open[1];
        vCondition15 = vValue17 == Highest(vValue17, iLookback) and close < open and close[1] < open[1];
        vCondition16 = vValue18 == Lowest(vValue18, iLookback)  and close < open and close[1] < open[1];
        vCondition17 = vValue19 == Lowest(vValue19, iLookback)  and close < open and close[1] < open[1];
        vCondition18 = vValue20 == Lowest(vValue20, iLookback)  and close > open and close[1] > open[1];
        vCondition19 = vValue21 == Lowest(vValue21, iLookback)  and close > open and close[1] > open[1];
        vCondition20 = vValue22 == Highest(vValue22, iLookback);
  
    case "NO":
        vValue13 = 0;
        vValue14 = 0;
        vValue15 = 0;
        vValue16 = 0;
        vValue17 = 0;
        vValue18 = 0;
        vValue19 = 0;
        vValue20 = 0;
        vValue21 = 0;
        vValue22 = 0;
  
        vCondition1  = vValue3  == Lowest(vValue3, iLookback);
        vCondition2  = vValue4  == Highest(vValue4, iLookback) and close > open;
        vCondition3  = vValue5  == Highest(vValue5, iLookback) and close > open;
        vCondition4  = vValue6  == Highest(vValue6, iLookback) and close < open;
        vCondition5  = vValue7  == Highest(vValue7, iLookback) and close < open;
        vCondition6  = vValue8  == Lowest(vValue8, iLookback)  and close < open;
        vCondition7  = vValue9  == Lowest(vValue9, iLookback)  and close < open;
        vCondition8  = vValue10 == Lowest(vValue10, iLookback) and close > open;
        vCondition9  = vValue11 == Lowest(vValue11, iLookback) and close > open;
        vCondition10 = vValue12 == Highest(vValue12, iLookback);
        vCondition11 = 0;
        vCondition12 = 0;
        vCondition13 = 0;
        vCondition14 = 0;
        vCondition15 = 0;
        vCondition16 = 0;
        vCondition17 = 0;
        vCondition18 = 0;
        vCondition19 = 0;
        vCondition20 = 0;
}

#PLOTS
#==========================================================================
plot pBetterVolume = volume;

#PLOT STYLES & SETTINGS
#==========================================================================
pBetterVolume.DefineColor("LowVol",      Color.YELLOW);
pBetterVolume.DefineColor("ClimaxUp",    Color.RED);
pBetterVolume.DefineColor("ClimaxDown",  Color.WHITE);
pBetterVolume.DefineColor("Churn",       Color.BLUE);
pBetterVolume.DefineColor("ClimaxChurn", Color.MAGENTA);
pBetterVolume.DefineColor("Default",     Color.CYAN);

pBetterVolume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

pBetterVolume.AssignValueColor
(
         if iShowLowVol      and (vCondition1 or vCondition11)  then pBetterVolume.Color("LowVol")
    else if iShowClimaxUp    and (vCondition2 or vCondition3 or vCondition8 or vCondition9 or vCondition12
                                  or vCondition13 or vCondition18 or vCondition19)
                                                                  then pBetterVolume.Color("ClimaxUp")
    else if iShowClimaxDown  and (vCondition4 or vCondition5 or vCondition6 or vCondition7 or vCondition14
                                  or vCondition15 or vCondition16 or vCondition17)
                                                                  then pBetterVolume.Color("ClimaxDown")
    else if iShowChurn       and (vCondition10 or vCondition20) then pBetterVolume.Color("Churn")
    else if iShowClimaxChurn and (vCondition10 or vCondition20)
                             and (vCondition2 or vCondition3 or vCondition4 or vCondition5 or vCondition6
                                  or vCondition7 or vCondition8 or vCondition9 or vCondition12
                                  or vCondition13 or vCondition14 or vCondition15 or vCondition16
                                  or vCondition17 or vCondition18 or vCondition19)
                                                                  then pBetterVolume.Color("ClimaxChurn")
    else pBetterVolume.Color("Default")
);

AssignPriceColor
(
         if iShowLowVol      and (vCondition1 or vCondition11)  then pBetterVolume.Color("LowVol")
    else if iShowClimaxUp    and (vCondition2 or vCondition3 or vCondition8 or vCondition9 or vCondition12
                                  or vCondition13 or vCondition18 or vCondition19)
                                                                  then pBetterVolume.Color("ClimaxUp")
    else if iShowClimaxDown  and (vCondition4 or vCondition5 or vCondition6 or vCondition7 or vCondition14
                                  or vCondition15 or vCondition16 or vCondition17)
                                                                  then pBetterVolume.Color("ClimaxDown")
    else if iShowChurn       and (vCondition10 or vCondition20) then pBetterVolume.Color("Churn")
    else if iShowClimaxChurn and (vCondition10 or vCondition20)
                             and (vCondition2 or vCondition3 or vCondition4 or vCondition5 or vCondition6
                                  or vCondition7 or vCondition8 or vCondition9 or vCondition12
                                  or vCondition13 or vCondition14 or vCondition15 or vCondition16
                                  or vCondition17 or vCondition18 or vCondition19)
                                                                  then pBetterVolume.Color("ClimaxChurn")
    else pBetterVolume.Color("Default")
);

Colors can be configured in the study customization window:

tV8OOgk.png


Shareable Link

https://tos.mx/PDkQYF

Code:
Source: https://thinkscripter.com/

Credit: Fil @ analyticsfortraders.com

More Info: https://emini-watch.com/free-stuff/volume-indicator/

Better Volume_v3 by Mobius

Code:
#Hint: BetterVolume_v3 \n Shows volume and dbl average as well as Vol_Buzz \n VolBuzz is current bar volume vs the average volume for a relatively longer period = VolAvgPeriod \n  The directional volume is the Net of Buy vs Sell avg vol for N = Length bars \n v3 adds  informative labels with dynamic coloring & options in visualization - in V3 we switch to Barry Taylor's algo for directional volume calc \n RedK @ Live . com  ---  Mayl 2013

declare lower;
#declare zerobase;

input Length = 7;
input VolAvgPeriod = 50;
input Volume_Bias_Based_on = { default "Close_Price" , "Trend" }; ## this makes a difference only in few bars.. it's not used in any calc
input VolPlotMode= { default "Both", "Classic" , "Pressure" };
input ShowLabels = yes;
Input VxNetSmooth = 3;

def VolState;
switch (Volume_Bias_Based_on) {
case Trend:
    VolState = if close > close[1] then 1 else if close == close [1] then 0 else -1;
default :
    VolState = if close > open then 1 else if close == open then 0 else  -1;
}

plot Vol = volume;
Vol.sethiding( VolPlotMode == VolPlotMode.Pressure);
plot VolSlowAvg = Average(volume, VolAvgPeriod);
plot VolFastAvg = WMA(volume, Length);

Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Vol.SetLineWeight(3);
Vol.DefineColor("Up", Color.UPTICK);
Vol.DefineColor("Down", Color.DOWNTICK);
Vol.DefineColor("Doji", GetColor(8));

Vol.AssignValueColor(if VolState == 1 then Vol.Color("Up") else if VolState == -1 then Vol.Color("Down") else Vol.Color("Doji"));
VolSlowAvg.SetDefaultColor(color.blue);
VolFastAvg.SetDefaultColor(Color.orange); VolFastAvg.setStyle (curve.SHORT_DASH);
VolFastAvg.SetLineWeight(1);

def VolBuzz = Round((volume / VolSlowAvg * 100), 1);
def FastVRatio = Round((VolFastAvg / VolSlowAvg * 100), 1);
AddLabel(ShowLabels, "Vol_Buzz: " + VolBuzz + "%", if VolBuzz < 80 then Color.dark_orange else if VolBuzz > 120 then Color.GREEN else Color.Yellow) ;

## adding a volume Dx (Directional Index) calc .. similar to Elder's calc, but uses all volume compared to Avg Volume during Fast Length
# in V3, we change to use the algo in BetterVolume study originally developed by Barry Taylor at EminiWatch for TradeStation
# this algo is OK (though i believe not the best) , and signal is better than using the whole volume bar as up or down.
## v3.a - add a PressureCalc option to see either WMA or SUM of directional volume
input VolPressureCalc= { default "WAverage", "Sum" };

def Vx =  if VolPressureCalc == VolPressureCalc.SUM then sum(volume,Length) else WMA(volume, Length) ;
def C = close; def O = Open; Def Range = High - low;
Def VolUp = If C > O and Range <> 0 then (Range/(2*Range+O-C))*Volume
else If C < O and Range <> 0 then ((Range+C-O)/(2*Range+C-O))*Volume
else 0.5*Volume;

def VolDn = Volume - VolUp;

def VxPlus = if VolPressureCalc == VolPressureCalc.SUM then sum (VolUp, Length) else WMA (VolUp, Length);
def VxMinus = if VolPressureCalc == VolPressureCalc.SUM then sum (VolDn, Length) else WMA (VolDn, Length);

def VxNetRaw = VXPlus-VXMinus ;

## Smooth with a very short zero-lag to eliminate outliers - Color the result
plot VxNet = 2 * WMA(VxNetRaw, VxNetSmooth) - WMA(WMA(VxNetRaw, VxNetSmooth),VxNetSmooth);
VxNet.DefineColor("PosUp", Color.GREEN);
VxNet.DefineColor("PosDn", Color.DARK_GREEN);
VxNet.DefineColor("NegDn", Color.RED);
VxNet.DefineColor("NegUp", Color.DARK_RED);
VxNet.AssignValueColor(if VxNet >= 0 then if VxNet > VxNet[1] then VxNet.color("PosUp") else VxNet.color("PosDn") else if VxNet < VxNet[1] then VxNet.color("NegDn") else VxNet.color("NegUp"));
VXNet.setlineWeight (3);
VxNet.sethiding(VolPlotMode == VolPlotMode.Classic);

## add volume pressure shade and the labels
def VxRatio = round(100 * VxNetRaw/VX,1);
def VxCloud = if VolPlotMode != VolPlotMode.Classic then VxNet else double.NaN ;
addcloud(VXCloud, 0);
AddLabel(ShowLabels, "FastVol: " + FastVRatio + "%", if FastVRatio > 100 then if VxRatio < 0 then Color.light_red else Color.GREEN else Color.orange) ;
AddLabel (ShowLabels ,"VxPlus: "+ round(VxPlus/VX*100,1)+"%", color.light_green);
AddLabel (ShowLabels , "VxMinus: "+ round(VxMinus/VX*100,1)+"%", color.Light_red);
AddLabel (ShowLabels , "VxNet: " + VxRatio + "%", if between(VxRatio, -10, 10) then color.yellow else if VxRatio >= 10 then color.green else color.dark_orange);
 
Last edited:

Takata

New member
Better Volume (show me how to Scan for red candles) Code below:

Code:
input lookback = 8;
input Use2Bars = {"No", default "Yes"};
input LowVol = {"No",default "Yes"};
input ClimaxUp = {"No",default "Yes"};
input ClimaxDown = {"No",default "Yes"};
input Churn = {"No",default "Yes"};
input ClimaxChurn = {"No",default "Yes"};
#
def LowVolColor = 8;
def ClimaxUpColor = 9;
def ClimaxDownColor = 1;
def ChurnColor = 5;
def ClimaxChurnColor = 0;
def DefaultBarColor = 7;
def AvgColor = 0;
#
def Range = TrueRange(high,low,close);
def Value1 = if (close >= open,Volume * ((Range) / ((2+(Range*Range)/10) * Range + (open - close))),
Volume * (((Range + close - open)) / (2+(Range*Range)/10) * Range + (close - open)));
def Value2 = Volume - Value1;
def Value3 = Value1 + Value2;
def Value4 = Value1 * Range;
def Value5 = (Value1 - Value2) * Range;
def Value6 = Value2 * Range;
def Value7 = (Value2 - Value1) * Range;
def Value8 = if (Range <> 0, Value1 / Range, 1);
def Value9 = if (Range <> 0, (Value1 - Value2) / Range, 1);
def Value10 = if (Range <> 0, Value2 / Range, 1);
def Value11 = if (Range <> 0, (Value2 - Value1) / Range, 1);
def Value12 = if (Range <> 0, Value3 / Range, 1);
def Value13 = if (Use2Bars, Value3 + Value3[1],1);
def Value14 = if (Use2Bars, (Value1 + Value1[1])*(Highest(High,2)-Lowest(Low,2)),1);
def Value15 = if (Use2Bars, (Value1 + Value1[1]-Value2-Value2[1])*(Highest(High,2)-Lowest(Low,2)),1);
def Value16 = if (Use2Bars, (Value2 + Value2[1])*(Highest(High,2)-Lowest(Low,2)),1);
def Value17 = if (Use2Bars, (Value2 + Value2[1]-Value1-Value1[1])*(Highest(High,2)-Lowest(Low,2)),1);
def Value18 = if ((Use2Bars and (Highest(High,2)<>Lowest(Low,2))),(Value1+Value1[1])/(Highest(High,2)-Lowest(Low,2)),1);
def Value19 = if ((Use2Bars and (Highest(High,2)<>Lowest(Low,2))),(Value1+Value1[1]-Value2-Value2[1])/(Highest(High,2)-Lowest(Low,2)),1);
def Value20 = if ((Use2Bars and (Highest(High,2)<>Lowest(Low,2))),(Value2+Value2[1])/(Highest(High,2)-Lowest(Low,2)),1);
def Value21 = if ((Use2Bars and (Highest(High,2)<>Lowest(Low,2))),(Value2+Value2[1]-Value1-Value1[1])/(Highest(High,2)-Lowest(Low,2)),1);
def Value22 = if ((Use2Bars and (Highest(High,2)<>Lowest(Low,2))),Value13/(Highest(High,2)-Lowest(Low,2)),1);
#
def Condition1 = if(Value3 == Lowest(Value3, Lookback), 1, 0);
def Condition2 = if((Value4 == Highest(Value4, Lookback) and close > open), 1, 0);
def Condition3 = if((Value5 == Highest(Value5, Lookback) and close > open), 1, 0);
def Condition4 = if((Value6 == Highest(Value6, Lookback) and close < open), 1, 0);
plot Condition5 = if((Value7 == Highest(Value7, Lookback) and close < open), 1, 0);
def Condition6 = if((Value8 == Lowest(Value8, Lookback) and close < open), 1, 0);
def Condition7 = if((Value9 == Lowest(Value9, Lookback) and close < open), 1, 0);
def Condition8 = if((Value10 == Lowest(Value10, Lookback) and close > open), 1, 0);
def Condition9 = if((Value11 == Lowest(Value11, Lookback) and close > open), 1, 0);
def Condition10 = if(Value12 == Highest(Value12, lookback), 1, 0);
def Condition11 = if (Use2Bars and (Value13==Lowest(Value13,Lookback) and close > open and Close[1] > Open[1]),1,0);
def Condition12 = if (Use2Bars and (Value14==Highest(Value14,Lookback) and close > open and Close[1] > Open[1]),1,0);
def Condition13 = if (Use2Bars and (Value15==Highest(Value15,Lookback) and close > open and Close[1] < Open[1]),1,0);
def Condition14 = if (Use2Bars and (Value16==Lowest(Value16,Lookback) and close < open and Close[1] < Open[1]),1,0);
def Condition15 = if (Use2Bars and (Value17==Lowest(Value17,Lookback) and close < open and Close[1] < Open[1]),1,0);
def Condition16 = if (Use2Bars and (Value18==Lowest(Value18,Lookback) and close < open and Close[1] < Open[1]),1,0);
def Condition17 = if (Use2Bars and (Value19==Lowest(Value19,Lookback) and close > open and Close[1] < Open[1]),1,0);
def Condition18 = if (Use2Bars and (Value20==Lowest(Value20,Lookback) and close > open and Close[1] > Open[1]),1,0);
def Condition19 = if (Use2Bars and (Value21==Lowest(Value21,Lookback) and close > open and Close[1] > Open[1]),1,0);
def Condition20 = if (Use2Bars and (Value22==Lowest(Value22,Lookback)), 1,0);
 
Last edited by a moderator:

Bigbagofspam

New member
Code:
declare On_Volume;

# START User defined inputs.
    input UnusualVolumePercent = 100;
    input ShowCurrentBar = no;
    input ShowPercentOf30BarAvg = yes;
    input ShowShortVolumePercent = yes;
# END User defined inputs.

# START Define high, low, open, close, volume, Long & Short.
    def H = high;
    def L = low;
    def O = open;
    def C = close;
    def V = volume;
    def Long = V*(C-L)/(H-L);
    def Short = V*(H-C)/(H-L);
# END Define high, low, open, close, volume, Long & Short.

# START Plot short volume.
    Plot ShortVol = Short;
         ShortVol.setPaintingStrategy(PaintingStrategy.Histogram);
         ShortVol.SetDefaultColor(Color.Red);
         ShortVol.HideTitle();
         ShortVol.HideBubble();
         ShortVol.SetLineWeight(5);
# END Plot short volume.

# START Plot long volume.
    Plot LongVol =  volume;
         LongVol.setPaintingStrategy(PaintingStrategy.Histogram);
         LongVol.SetDefaultColor(Color.Dark_Green);
         LongVol.HideTitle();
         LongVol.HideBubble();
         LongVol.SetLineWeight(5);
# END Plot long volume.

# START Define average volume of 30 bars.
def avg30Bars = (volume[1] + volume[2] + volume[3] + volume[4]
              + volume[5] + volume[6] + volume[7] + volume[8]
              + volume[9] + volume[10] + volume[11] + volume[12]
              + volume[13] + volume[14] + volume[15] + volume[16]
              + volume[17] + volume[18] + volume[19] + volume[20]
              + volume[21] + volume[22] + volume[23] + volume[24]
              + volume[25] + volume[26] + volume[27] + volume[28]
              + volume[29] + volume[30])
              / 30;

    def curVolume
        = volume;
    def percentOf30Bar
        = Round((curVolume / avg30Bars)
        * 100, 0);
    def ShortVolPercent
        = Round((Short / Volume)
        * 100, 0);

     AddLabel(ShowCurrentBar,
             "Cur Bar: " + curVolume,
            (if percentOf30Bar >= UnusualVolumePercent then Color.RED else
             if PercentOf30Bar >= 100 then Color.GREEN else
             Color.LIGHT_GRAY));


    AddLabel(ShowCurrentBar,
             "Cur Bar: " + curVolume,
            (if percentOf30Bar >= UnusualVolumePercent then Color.RED else
             if PercentOf30Bar >= 100 then Color.GREEN else
             Color.LIGHT_GRAY));

    AddLabel(ShowPercentOf30BarAvg,
             PercentOf30Bar + "% of avg",
            (if PercentOf30Bar >= UnusualVolumePercent then Color.GREEN else
             if PercentOf30Bar >= 100 then Color.ORANGE else Color.WHITE) );

    AddLabel(ShowShortVolumePercent,
             "Cur Bar Sell %: " + ShortVolPercent,
            (if ShortVolPercent > 51 then Color.RED else
             if ShortVolPercent < 49 then Color.GREEN else
             Color.ORANGE));


def agg = AggregationPeriod.FIFTEEN_MIN;
input length = 50;
plot VolAvg = Average(volume, length);
plot VolAvgTwoHundredPercent = 2 * Volavg;

VolAvg.SetDefaultColor(GetColor(3));
VolAvgTwoHundredPercent.SetDefaultColor(GetColor(10));

Alert(volume >VolAvgTwoHundredPercent, "Volume is greater than 250%. Current value is" + (Volume * 100 / VolAvg), alert.ONCE, Sound.Ring);
 
Last edited by a moderator:

Bigbagofspam

New member
BBoS_Volume_Sentiment_1_6 is the name I gave it. The #s are just for non executable comments. Here is code with the name and stuff i trimmed in the first post.
Code:
# BBoS_Volume_Sentiment_1_6
# 2019-07-19


declare On_Volume;

# START User defined inputs.
    input UnusualVolumePercent = 100;
    input ShowCurrentBar = no;
    input ShowPercentOf30BarAvg = yes;
    input ShowShortVolumePercent = yes;
# END User defined inputs.

# START Define high, low, open, close, volume, Long & Short.
    def H = high;
    def L = low;
    def O = open;
    def C = close;
    def V = volume;
    def Long = V*(C-L)/(H-L);
    def Short = V*(H-C)/(H-L);
# END Define high, low, open, close, volume, Long & Short.

# START Plot short volume.
    Plot ShortVol = Short;
         ShortVol.setPaintingStrategy(PaintingStrategy.Histogram);
         ShortVol.SetDefaultColor(Color.Red);
         ShortVol.HideTitle();
         ShortVol.HideBubble();
         ShortVol.SetLineWeight(5);
# END Plot short volume.

# START Plot long volume.
    Plot LongVol =  volume;
         LongVol.setPaintingStrategy(PaintingStrategy.Histogram);
         LongVol.SetDefaultColor(Color.Dark_Green);
         LongVol.HideTitle();
         LongVol.HideBubble();
         LongVol.SetLineWeight(5);
# END Plot long volume.

# START Define average volume of 30 bars.
def avg30Bars = (volume[1] + volume[2] + volume[3] + volume[4]
              + volume[5] + volume[6] + volume[7] + volume[8]
              + volume[9] + volume[10] + volume[11] + volume[12]
              + volume[13] + volume[14] + volume[15] + volume[16]
              + volume[17] + volume[18] + volume[19] + volume[20]
              + volume[21] + volume[22] + volume[23] + volume[24]
              + volume[25] + volume[26] + volume[27] + volume[28]
              + volume[29] + volume[30])
              / 30;

    def curVolume
        = volume;
    def percentOf30Bar
        = Round((curVolume / avg30Bars)
        * 100, 0);
    def ShortVolPercent
        = Round((Short / Volume)
        * 100, 0);

     AddLabel(ShowCurrentBar,
             "Cur Bar: " + curVolume,
            (if percentOf30Bar >= UnusualVolumePercent then Color.RED else
             if PercentOf30Bar >= 100 then Color.GREEN else
             Color.LIGHT_GRAY));


    AddLabel(ShowCurrentBar,
             "Cur Bar: " + curVolume,
            (if percentOf30Bar >= UnusualVolumePercent then Color.RED else
             if PercentOf30Bar >= 100 then Color.GREEN else
             Color.LIGHT_GRAY));

    AddLabel(ShowPercentOf30BarAvg,
             PercentOf30Bar + "% of avg",
            (if PercentOf30Bar >= UnusualVolumePercent then Color.GREEN else
             if PercentOf30Bar >= 100 then Color.ORANGE else Color.WHITE) );

    AddLabel(ShowShortVolumePercent,
             "Cur Bar Sell %: " + ShortVolPercent,
            (if ShortVolPercent > 51 then Color.RED else
             if ShortVolPercent < 49 then Color.GREEN else
             Color.ORANGE));


def agg = AggregationPeriod.FIFTEEN_MIN;
input length = 50;
plot VolAvg = Average(volume, length);
 
Last edited by a moderator:

wtf_dude

Active member
Oh I know, I was just saying might as well go ahead and put a title and description of what it does IN the code since there are several versions ie what's different on this one, etc. Just a thought

edit: BBOS, just messed around with this. Like it alot, good work man
 
Last edited:

lrc11239

Member
Is there any way to just display better volume on the volume bars instead of the candles?? Many thanks...
 

wtf_dude

Active member
Is there any way to just display better volume on the volume bars instead of the candles?? Many thanks...
Go to the chart settings gear, on the lower left of the menu there's a box to check that says overlap volume. Switch it off.
 

onsom001

New member
VIP
Better Volume PaintBar - EasyLanguage - Version 19 August 2012

Code:
Inputs:  LowVol(True), ClimaxUp(True), ClimaxDown(True), Churn(True), ClimaxChurn(False), LowVolColor(Yellow), ClimaxUpColor(Red), ClimaxDownColor(White), ChurnColor(Blue), ClimaxChurnColor(Magenta), Color(Green), UseUpTicks(True), Use2Bars(True);
Variables:  BarColor(Green), Lookback(20);

BarColor = Color;

If BarType > 1 then begin
    If C > O and Range <> 0 then Value1 = (Range/(2*Range+O-C))*V;
    If C < O and Range <> 0 then Value1 = ((Range+C-O)/(2*Range+C-O))*V;
    If C = O then Value1 = 0.5*V;
    Value2 = V-Value1;
End;
If BarType <= 1 and UseUpTicks = False then begin
    If C > O and Range <> 0 then Value1 = (Range/(2*Range+O-C))*Ticks;
    If C < O and Range <> 0 then Value1 = ((Range+C-O)/(2*Range+C-O))*Ticks;
    If C = O then Value1 = 0.5*Ticks;
    Value2 = Ticks-Value1;
End;
If BarType <= 1 and UseUpTicks then begin
    Value1 = UpTicks;
    Value2 = DownTicks;
End;

Value3 = AbsValue(Value1+Value2);
Value4 = Value1*Range;
Value5 = (Value1-Value2)*Range;
Value6 = Value2*Range;
Value7 = (Value2-Value1)*Range;
If Range <> 0 then begin
    Value8 = Value1/Range;
    Value9 = (Value1-Value2)/Range;
    Value10 = Value2/Range;
    Value11 = (Value2-Value1)/Range;
    Value12 = Value3/Range;
End;
If Use2Bars then begin
    Value13 = Value3+Value3[1];
    Value14 = (Value1+Value1[1])*(Highest(H,2)-Lowest(L,2));
    Value15 = (Value1+Value1[1]-Value2-Value2[1])*(Highest(H,2)-Lowest(L,2));
    Value16 = (Value2+Value2[1])*(Highest(H,2)-Lowest(L,2));
    Value17 = (Value2+Value2[1]-Value1-Value1[1])*(Highest(H,2)-Lowest(L,2));
    If Highest(H,2) <> Lowest(L,2) then begin
        Value18 = (Value1+Value1[1])/(Highest(H,2)-Lowest(L,2));
        Value19 = (Value1+Value1[1]-Value2-Value2[1])/(Highest(H,2)-Lowest(L,2));
        Value20 = (Value2+Value2[1])/(Highest(H,2)-Lowest(L,2));
        Value21 = (Value2+Value2[1]-Value1-Value1[1])/(Highest(H,2)-Lowest(L,2));
        Value22 = Value13/(Highest(H,2)-Lowest(L,2));
    End;
End;

Condition1 = Value3 = Lowest(Value3,Lookback);
Condition2 = Value4 = Highest(Value4,Lookback) and C > O;
Condition3 = Value5 = Highest(Value5,Lookback) and C > O;
Condition4 = Value6 = Highest(Value6,Lookback) and C < O;
Condition5 = Value7 = Highest(Value7,Lookback) and C < O;
Condition6 = Value8 = Lowest(Value8,Lookback) and C < O;
Condition7 = Value9 = Lowest(Value9,Lookback) and C < O;
Condition8 = Value10 = Lowest(Value10,Lookback) and C > O;
Condition9 = Value11 = Lowest(Value11,Lookback) and C > O;
Condition10 = Value12 = Highest(Value12,Lookback);
If Use2Bars then begin
    Condition11 = Value13 = Lowest(Value13,Lookback);
    Condition12 = Value14 = Highest(Value14,Lookback) and C > O and C[1] > O[1];
    Condition13 = Value15 = Highest(Value15,Lookback) and C > O and C[1] > O[1];
    Condition14 = Value16 = Highest(Value16,Lookback) and C < O and C[1] < O[1];
    Condition15 = Value17 = Highest(Value17,Lookback) and C < O and C[1] < O[1];
    Condition16 = Value18 = Lowest(Value18,Lookback) and C < O and C[1] < O[1];
    Condition17 = Value19 = Lowest(Value19,Lookback) and C < O and C[1] < O[1];
    Condition18 = Value20 = Lowest(Value20,Lookback) and C > O and C[1] > O[1];
    Condition19 = Value21 = Lowest(Value21,Lookback) and C > O and C[1] > O[1];
    Condition20 = Value22 = Highest(Value22,Lookback);
End;

If BarType > 1 then begin
    If LowVol and (Condition1 or Condition11) then BarColor = LowVolColor;
    If ClimaxUp and (Condition2 or Condition3 or Condition8 or Condition9 or Condition12 or Condition13 or Condition18 or Condition19) then BarColor = ClimaxUpColor;
    If ClimaxDown and (Condition4 or Condition5 or Condition6 or Condition7 or Condition14 or Condition15 or Condition16 or Condition17) then BarColor = ClimaxDownColor;
    If Churn and (Condition10 or Condition20) then BarColor = ChurnColor;
    If ClimaxChurn and (Condition10 or Condition20) and (Condition2 or Condition3 or Condition4 or Condition5 or Condition6 or Condition7 or Condition8 or Condition9 or
        Condition12 or Condition13 or Condition14 or Condition15 or Condition16 or Condition17 or Condition18 or Condition19) then BarColor = ClimaxChurnColor;
End;

If BarType <= 1 then begin
    If LowVol and (Condition1 or (Condition11 and D=D[1])) then BarColor = LowVolColor;
    If ClimaxUp and (Condition2 or Condition3 or Condition8 or Condition9 or ((Condition12 or Condition13 or Condition18 or Condition19) and D=D[1])) then BarColor = ClimaxUpColor;
    If ClimaxDown and (Condition4 or Condition5 or Condition6 or Condition7 or ((Condition14 or Condition15 or Condition16 or Condition17) and D=D[1])) then BarColor = ClimaxDownColor;
    If Churn and (Condition10 or (Condition20 and D=D[1])) then BarColor = ChurnColor;
    If ClimaxChurn and (Condition10 or (Condition20 and D=D[1])) and (Condition2 or Condition3 or Condition4 or Condition5 or Condition6 or Condition7 or Condition8 or Condition9 or
        ((Condition12 or Condition13 or Condition14 or Condition15 or Condition16 or Condition17 or Condition18 or Condition19) and D=D[1])) then BarColor = ClimaxChurnColor;
End;

If BarColor <> Color then PlotPaintBar(H,L,O,C,"BetterVol",BarColor);

{ Change Log: }
{23 November 2007 - Added LowChurn colored volume bars                      }
{28 March 2008 - Added ability to turn on and off different colored bars    }
{28 March 2008 - Got rid of redundant code calculations                     }
{19 April 2008 - Got rid of LowChurn and replaced with ClimaxDown           }
{19 April 2008 - Added open & close conditions with ClimaxUp and ClimaxDown }
{19 April 2008 - Added different calculations for tick/intra-day charts     }
{13 July 2008 - Added 2 bar climax, churn and low volume conditions         }
{4 September 2008 - Changed daily bars calculation to match tick/intra-day  }
{25 January 2009 - Added condition total volume (Value3) could not be -ve   }
{3 July 2009 - Allowed the default bar coloring to be changed               }
{19 August 2012 - Changed calculation for Intra-day + UseUpTicks = False    }
 

Ronin13

Member
VIP
i know that i could simply uncheck show plot in the plots panel below but i don't want to have to do this each time i apply the indicator...

thanks so much!
 

MerryDay

Administrative
Staff member
Staff
VIP
To change the defaults of TOS built-in studies and custom studies.
  1. Click on the gear next to the study in your chart.
  2. Making all changes that you want as your personal defaults.
  3. Click on the Save as Default button at the top of the box.
YgOhwM0.png

@Ronin13 HTH
 

Ronin13

Member
VIP
Go to the chart settings gear, on the lower left of the menu there's a box to check that says overlap volume. Switch it off.
hi all,

for better volume, i unchecked 'overlap volume' to switch off painting of my candles to use the histogram only.

however, i still see my candles repainting. is there another setting that i am missing?

if it is relevant, the symbol is /ES

thanks so much
 

MerryDay

Administrative
Staff member
Staff
VIP
i still see my candles repainting. is there another setting that i am missing?
You have to comment out the Assign statement that is painting the bars. Find this code:
AssignPriceColor
(
if iShowLowVol and (vCondition1 or vCondition11) then pBetterVolume.Color("LowVol")
else if iShowClimaxUp and (vCondition2 or vCondition3 or vCondition8 or vCondition9 or vCondition12
or vCondition13 or vCondition18 or vCondition19)
then pBetterVolume.Color("ClimaxUp")
else if iShowClimaxDown and (vCondition4 or vCondition5 or vCondition6 or vCondition7 or vCondition14
or vCondition15 or vCondition16 or vCondition17)
then pBetterVolume.Color("ClimaxDown")
else if iShowChurn and (vCondition10 or vCondition20) then pBetterVolume.Color("Churn")
else if iShowClimaxChurn and (vCondition10 or vCondition20)
and (vCondition2 or vCondition3 or vCondition4 or vCondition5 or vCondition6
or vCondition7 or vCondition8 or vCondition9 or vCondition12
or vCondition13 or vCondition14 or vCondition15 or vCondition16
or vCondition17 or vCondition18 or vCondition19)
then pBetterVolume.Color("ClimaxChurn")
else pBetterVolume.Color("Default")
);
And comment it out by putting an # in front of each line, like so:
# AssignPriceColor
# (
# if iShowLowVol and (vCondition1 or vCondition11) then pBetterVolume.Color("LowVol")
# else if iShowClimaxUp and (vCondition2 or vCondition3 or vCondition8 or vCondition9 or vCondition12
# or vCondition13 or vCondition18 or vCondition19)
# then pBetterVolume.Color("ClimaxUp")
# else if iShowClimaxDown and (vCondition4 or vCondition5 or vCondition6 or vCondition7 or vCondition14
# or vCondition15 or vCondition16 or vCondition17)
# then pBetterVolume.Color("ClimaxDown")
# else if iShowChurn and (vCondition10 or vCondition20) then pBetterVolume.Color("Churn")
# else if iShowClimaxChurn and (vCondition10 or vCondition20)
# and (vCondition2 or vCondition3 or vCondition4 or vCondition5 or vCondition6
# or vCondition7 or vCondition8 or vCondition9 or vCondition12
# or vCondition13 or vCondition14 or vCondition15 or vCondition16
# or vCondition17 or vCondition18 or vCondition19)
# then pBetterVolume.Color("ClimaxChurn")
# else pBetterVolume.Color("Default")
# );
 

Ronin13

Member
VIP
i tried to add an alert to the Better_Volume indicator, to get an alert on certain bar types when they complete, like so:

Ruby:
# Sound alerts on Climax Bars
Alert(vCondition2 or vCondition3 or vCondition8 or vCondition9 or vCondition12 or vCondition13 or vCondition18 or vCondition19, "Time TO Buy", Alert.BAR, Sound.Ring);
Alert(vCondition4 or vCondition5 or vCondition6 or vCondition7 or vCondition14 or vCondition15 or vCondition16 or vCondition17, "Time TO Sell", Alert.BAR, Sound.Ring);


when that didn't work (alerts were not sounding when red or white bars were completing), i amended the code as follows:

Code:
Alert(vCondition2, "Climax Up Alert", Alert.BAR, Sound.Ring);
Alert(vCondition3, "Climax Up Alert", Alert.BAR, Sound.Ring);
Alert(vCondition8, "Climax Up Alert", Alert.BAR, Sound.Ring);
Alert(vCondition9, "Climax Up Alert", Alert.BAR, Sound.Ring);
Alert(vCondition12, "Climax Up Alert", Alert.BAR, Sound.Ring);
Alert(vCondition13, "Climax Up Alert", Alert.BAR, Sound.Ring);
Alert(vCondition18, "Climax Up Alert", Alert.BAR, Sound.Ring);
Alert(vCondition19, "Climax Up Alert", Alert.BAR, Sound.Ring);

Alert(vCondition4, "Climax Down Alert", Alert.BAR, Sound.Ring);
Alert(vCondition5, "Climax Down Alert", Alert.BAR, Sound.Ring);
Alert(vCondition6, "Climax Down Alert", Alert.BAR, Sound.Ring);
Alert(vCondition7, "Climax Down Alert", Alert.BAR, Sound.Ring);
Alert(vCondition14, "Climax Down Alert", Alert.BAR, Sound.Ring);
Alert(vCondition15, "Climax Down Alert", Alert.BAR, Sound.Ring);
Alert(vCondition16, "Climax Down Alert", Alert.BAR, Sound.Ring);
Alert(vCondition17, "Climax Down Alert", Alert.BAR, Sound.Ring);

however, the above didn't work either - alerts are now sounding, but seemingly at random times, but not on completion of red or white bars.

can anyone see what i might be doing wrong? any help would be appreciated!
 

Ronin13

Member
VIP
Refusing to give up, I tried the following code... still no luck... :cry:

Ruby:
#Sound alerts on Red and White bars:

def ClimaxUp = vCondition2 or vCondition3 or vCondition8 or vCondition9 or vCondition12
                                  or vCondition13 or vCondition18 or vCondition19;

def ClimaxDown = vCondition4 or vCondition5 or vCondition6 or vCondition7 or vCondition14
                                  or vCondition15 or vCondition16 or vCondition17;

Alert(ClimaxUp, "Red Bar", Alert.BAR,Sound.Ring);
Alert(ClimaxDown, "White Bar", Alert.BAR,Sound.Ring);

think the alert definitions i'm attempting to use are sounding off once while the bar is still painting if the conditions are met rather than at the end of the bar...

grateful if someone can figure what's the solution...
 
Last edited:

MerryDay

Administrative
Staff member
Staff
VIP
Refusing to give up, I tried the following code... still no luck... :cry:

Ruby:
#Sound alerts on Red and White bars:

def ClimaxUp = vCondition2 or vCondition3 or vCondition8 or vCondition9 or vCondition12
                                  or vCondition13 or vCondition18 or vCondition19;

def ClimaxDown = vCondition4 or vCondition5 or vCondition6 or vCondition7 or vCondition14
                                  or vCondition15 or vCondition16 or vCondition17;

Alert(ClimaxUp, "Red Bar", Alert.BAR,Sound.Ring);
Alert(ClimaxDown, "White Bar", Alert.BAR,Sound.Ring);

think the alert definitions i'm attempting to use are sounding off once while the bar is still painting if the conditions are met rather than at the end of the bar...

grateful if someone can figure what's the solution...
After much research, I conclude there is no syntax that will give CONSISTENT results when creating alerts.
The recursive definitions of high/lows will result in random albeit occasionally true results.
 

Ronin13

Member
VIP
After much research, I conclude there is no syntax that will give CONSISTENT results when creating alerts.
The recursive definitions of high/lows will result in random albeit occasionally true results.
that's quite the pity, because this is a really good indicator when it comes to identifying trend reversals and support / resistance breakouts in real time... but thanks for checking (y)

as an afterthought though, i can't quite wrap my head around why we should not be able to successfully create an alert on this though, since this indicator does not repaint - i.e. once the candle is completed, the signal is locked in...
 
Last edited:

datechie

New member
# TS_BetterVolume_Indicator
# A better volume indicator with color coded histogram plot that shows 4 different colors depending on price action and volume.
# Yellow - Low volume for the size of the bar - Amateurs at work
# White - Climax down
# Blue -Climax up
# Red - Churn - Pros buying at lows or unloading at highs
# Magenta - Climax Churn - Pros taking profits at highs or lows
# Gray - Normal (default) Bar

vNHOUnE.png


thinkScript Code

Rich (BB code):
#
#Better Volume for Thinkorswim
#
#
#hint: Verbatim translation of the TradeStation code from http://emini-watch.com/free-stuff/volume-indicator/
#==========================================================================

#DECLARATIONS
#==========================================================================
declare on_volume;
declare real_size;

#INPUTS
#==========================================================================
input iShowLowVol      = YES;
input iShowClimaxUp    = YES;
input iShowClimaxDown  = YES;
input iShowChurn       = YES;
input iShowClimaxChurn = YES;

input iUseTwoBars = {default "YES", "NO"};
input iLookback   = 20;

#VARS
#==========================================================================
def vValue1;
def vValue2;
def vValue3;
def vValue4;
def vValue5;
def vValue6;
def vValue7;
def vValue8;
def vValue9;
def vValue10;
def vValue11;
def vValue12;
def vValue13;
def vValue14;
def vValue15;
def vValue16;
def vValue17;
def vValue18;
def vValue19;
def vValue20;
def vValue21;
def vValue22;

def vCondition1;
def vCondition2;
def vCondition3;
def vCondition4;
def vCondition5;
def vCondition6;
def vCondition7;
def vCondition8;
def vCondition9;
def vCondition10;
def vCondition11;
def vCondition12;
def vCondition13;
def vCondition14;
def vCondition15;
def vCondition16;
def vCondition17;
def vCondition18;
def vCondition19;
def vCondition20;

def vRange;

#LOGIC
#==========================================================================
vRange = high - low;

if close > open and vRange <> 0
    then {vValue1 = (vRange/(2*vRange + open - close))*volume;
          vValue2 = volume - vValue1;}
else if close < open and vRange <> 0
    then {vValue1 = ((vRange + close - open)/(2*vRange + close - open))*volume;
          vValue2 = volume - vValue1;}
else if close == open
    then {vValue1 = 0.5*volume;
          vValue2 = volume - vValue1;}
    else {vValue1 = 0;
          vValue2 = 0;}

vValue3 = AbsValue(vValue1 + vValue2);
vValue4 = vValue1*vRange;
vValue5 = (vValue1 - vValue2)*vRange;
vValue6 = vValue2*vRange;
vValue7 = (vValue2 - vValue1)*vRange;

if vRange <> 0
    then {vValue8  = vValue1/vRange;
          vValue9  = (vValue1 - vValue2)/vRange;
          vValue10 = vValue2/vRange;
          vValue11 = (vValue2 - vValue1)/vRange;
          vValue12 = vValue3/vRange;}
    else {vValue8  = 0;
          vValue9  = 0;
          vValue10 = 0;
          vValue11 = 0;
          vValue12 = 0;}

switch(iUseTwoBars)
{
    case "YES":
        vValue13 = vValue3 + vValue3[1];
        vValue14 = (vValue1 + vValue1[1])*(Highest(high,2) - Lowest(low,2));
        vValue15 = (vValue1 + vValue1[1] - vValue2 - vValue2[1])*(Highest(high,2) - Lowest(low,2));
        vValue16 = (vValue2 + vValue2[1])*(Highest(high,2) - Lowest(low,2));
        vValue17 = (vValue2 + vValue2[1] - vValue1 - vValue1[1])*(Highest(high,2) - Lowest(low,2));
 
        if Highest(high,2) <> Lowest(low,2)
            then {vValue18 = (vValue1 + vValue1[1])/(Highest(high,2) - Lowest(low,2));
                  vValue19 = (vValue1 + vValue1[1] - vValue2 - vValue2[1])/(Highest(high,2) - Lowest(low,2));
                  vValue20 = (vValue2 + vValue2[1])/(Highest(high,2) - Lowest(low,2));
                  vValue21 = (vValue2 + vValue2[1] - vValue1 - vValue1[1])/(Highest(high,2) - Lowest(low,2));
                  vValue22 = vValue13/(Highest(high,2) - Lowest(low,2));}
            else {vValue18 = 0;
                  vValue19 = 0;
                  vValue20 = 0;
                  vValue21 = 0;
                  vValue22 = 0;}
 
        vCondition1  = 0;
        vCondition2  = 0;
        vCondition3  = 0;
        vCondition4  = 0;
        vCondition5  = 0;
        vCondition6  = 0;
        vCondition7  = 0;
        vCondition8  = 0;
        vCondition9  = 0;
        vCondition10 = 0;
        vCondition11 = vValue13 == Lowest(vValue13, iLookback);
        vCondition12 = vValue14 == Highest(vValue14, iLookback) and close > open and close[1] > open[1];
        vCondition13 = vValue15 == Highest(vValue15, iLookback) and close > open and close[1] > open[1];
        vCondition14 = vValue16 == Highest(vValue16, iLookback) and close < open and close[1] < open[1];
        vCondition15 = vValue17 == Highest(vValue17, iLookback) and close < open and close[1] < open[1];
        vCondition16 = vValue18 == Lowest(vValue18, iLookback)  and close < open and close[1] < open[1];
        vCondition17 = vValue19 == Lowest(vValue19, iLookback)  and close < open and close[1] < open[1];
        vCondition18 = vValue20 == Lowest(vValue20, iLookback)  and close > open and close[1] > open[1];
        vCondition19 = vValue21 == Lowest(vValue21, iLookback)  and close > open and close[1] > open[1];
        vCondition20 = vValue22 == Highest(vValue22, iLookback);
 
    case "NO":
        vValue13 = 0;
        vValue14 = 0;
        vValue15 = 0;
        vValue16 = 0;
        vValue17 = 0;
        vValue18 = 0;
        vValue19 = 0;
        vValue20 = 0;
        vValue21 = 0;
        vValue22 = 0;
 
        vCondition1  = vValue3  == Lowest(vValue3, iLookback);
        vCondition2  = vValue4  == Highest(vValue4, iLookback) and close > open;
        vCondition3  = vValue5  == Highest(vValue5, iLookback) and close > open;
        vCondition4  = vValue6  == Highest(vValue6, iLookback) and close < open;
        vCondition5  = vValue7  == Highest(vValue7, iLookback) and close < open;
        vCondition6  = vValue8  == Lowest(vValue8, iLookback)  and close < open;
        vCondition7  = vValue9  == Lowest(vValue9, iLookback)  and close < open;
        vCondition8  = vValue10 == Lowest(vValue10, iLookback) and close > open;
        vCondition9  = vValue11 == Lowest(vValue11, iLookback) and close > open;
        vCondition10 = vValue12 == Highest(vValue12, iLookback);
        vCondition11 = 0;
        vCondition12 = 0;
        vCondition13 = 0;
        vCondition14 = 0;
        vCondition15 = 0;
        vCondition16 = 0;
        vCondition17 = 0;
        vCondition18 = 0;
        vCondition19 = 0;
        vCondition20 = 0;
}

#PLOTS
#==========================================================================
plot pBetterVolume = volume;

#PLOT STYLES & SETTINGS
#==========================================================================
pBetterVolume.DefineColor("LowVol",      Color.YELLOW);
pBetterVolume.DefineColor("ClimaxUp",    Color.RED);
pBetterVolume.DefineColor("ClimaxDown",  Color.WHITE);
pBetterVolume.DefineColor("Churn",       Color.BLUE);
pBetterVolume.DefineColor("ClimaxChurn", Color.MAGENTA);
pBetterVolume.DefineColor("Default",     Color.CYAN);

pBetterVolume.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);

pBetterVolume.AssignValueColor
(
         if iShowLowVol      and (vCondition1 or vCondition11)  then pBetterVolume.Color("LowVol")
    else if iShowClimaxUp    and (vCondition2 or vCondition3 or vCondition8 or vCondition9 or vCondition12
                                  or vCondition13 or vCondition18 or vCondition19)
                                                                  then pBetterVolume.Color("ClimaxUp")
    else if iShowClimaxDown  and (vCondition4 or vCondition5 or vCondition6 or vCondition7 or vCondition14
                                  or vCondition15 or vCondition16 or vCondition17)
                                                                  then pBetterVolume.Color("ClimaxDown")
    else if iShowChurn       and (vCondition10 or vCondition20) then pBetterVolume.Color("Churn")
    else if iShowClimaxChurn and (vCondition10 or vCondition20)
                             and (vCondition2 or vCondition3 or vCondition4 or vCondition5 or vCondition6
                                  or vCondition7 or vCondition8 or vCondition9 or vCondition12
                                  or vCondition13 or vCondition14 or vCondition15 or vCondition16
                                  or vCondition17 or vCondition18 or vCondition19)
                                                                  then pBetterVolume.Color("ClimaxChurn")
    else pBetterVolume.Color("Default")
);

AssignPriceColor
(
         if iShowLowVol      and (vCondition1 or vCondition11)  then pBetterVolume.Color("LowVol")
    else if iShowClimaxUp    and (vCondition2 or vCondition3 or vCondition8 or vCondition9 or vCondition12
                                  or vCondition13 or vCondition18 or vCondition19)
                                                                  then pBetterVolume.Color("ClimaxUp")
    else if iShowClimaxDown  and (vCondition4 or vCondition5 or vCondition6 or vCondition7 or vCondition14
                                  or vCondition15 or vCondition16 or vCondition17)
                                                                  then pBetterVolume.Color("ClimaxDown")
    else if iShowChurn       and (vCondition10 or vCondition20) then pBetterVolume.Color("Churn")
    else if iShowClimaxChurn and (vCondition10 or vCondition20)
                             and (vCondition2 or vCondition3 or vCondition4 or vCondition5 or vCondition6
                                  or vCondition7 or vCondition8 or vCondition9 or vCondition12
                                  or vCondition13 or vCondition14 or vCondition15 or vCondition16
                                  or vCondition17 or vCondition18 or vCondition19)
                                                                  then pBetterVolume.Color("ClimaxChurn")
    else pBetterVolume.Color("Default")
);

Colors can be configured in the study customization window:

tV8OOgk.png


Shareable Link

https://tos.mx/PDkQYF

Code:
Source: https://thinkscripter.com/

Credit: Fil @ analyticsfortraders.com

More Info: https://emini-watch.com/free-stuff/volume-indicator/

Better Volume_v3 by Mobius

Code:
#Hint: BetterVolume_v3 \n Shows volume and dbl average as well as Vol_Buzz \n VolBuzz is current bar volume vs the average volume for a relatively longer period = VolAvgPeriod \n  The directional volume is the Net of Buy vs Sell avg vol for N = Length bars \n v3 adds  informative labels with dynamic coloring & options in visualization - in V3 we switch to Barry Taylor's algo for directional volume calc \n RedK @ Live . com  ---  Mayl 2013

declare lower;
#declare zerobase;

input Length = 7;
input VolAvgPeriod = 50;
input Volume_Bias_Based_on = { default "Close_Price" , "Trend" }; ## this makes a difference only in few bars.. it's not used in any calc
input VolPlotMode= { default "Both", "Classic" , "Pressure" };
input ShowLabels = yes;
Input VxNetSmooth = 3;

def VolState;
switch (Volume_Bias_Based_on) {
case Trend:
    VolState = if close > close[1] then 1 else if close == close [1] then 0 else -1;
default :
    VolState = if close > open then 1 else if close == open then 0 else  -1;
}

plot Vol = volume;
Vol.sethiding( VolPlotMode == VolPlotMode.Pressure);
plot VolSlowAvg = Average(volume, VolAvgPeriod);
plot VolFastAvg = WMA(volume, Length);

Vol.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
Vol.SetLineWeight(3);
Vol.DefineColor("Up", Color.UPTICK);
Vol.DefineColor("Down", Color.DOWNTICK);
Vol.DefineColor("Doji", GetColor(8));

Vol.AssignValueColor(if VolState == 1 then Vol.Color("Up") else if VolState == -1 then Vol.Color("Down") else Vol.Color("Doji"));
VolSlowAvg.SetDefaultColor(color.blue);
VolFastAvg.SetDefaultColor(Color.orange); VolFastAvg.setStyle (curve.SHORT_DASH);
VolFastAvg.SetLineWeight(1);

def VolBuzz = Round((volume / VolSlowAvg * 100), 1);
def FastVRatio = Round((VolFastAvg / VolSlowAvg * 100), 1);
AddLabel(ShowLabels, "Vol_Buzz: " + VolBuzz + "%", if VolBuzz < 80 then Color.dark_orange else if VolBuzz > 120 then Color.GREEN else Color.Yellow) ;

## adding a volume Dx (Directional Index) calc .. similar to Elder's calc, but uses all volume compared to Avg Volume during Fast Length
# in V3, we change to use the algo in BetterVolume study originally developed by Barry Taylor at EminiWatch for TradeStation
# this algo is OK (though i believe not the best) , and signal is better than using the whole volume bar as up or down.
## v3.a - add a PressureCalc option to see either WMA or SUM of directional volume
input VolPressureCalc= { default "WAverage", "Sum" };

def Vx =  if VolPressureCalc == VolPressureCalc.SUM then sum(volume,Length) else WMA(volume, Length) ;
def C = close; def O = Open; Def Range = High - low;
Def VolUp = If C > O and Range <> 0 then (Range/(2*Range+O-C))*Volume
else If C < O and Range <> 0 then ((Range+C-O)/(2*Range+C-O))*Volume
else 0.5*Volume;

def VolDn = Volume - VolUp;

def VxPlus = if VolPressureCalc == VolPressureCalc.SUM then sum (VolUp, Length) else WMA (VolUp, Length);
def VxMinus = if VolPressureCalc == VolPressureCalc.SUM then sum (VolDn, Length) else WMA (VolDn, Length);

def VxNetRaw = VXPlus-VXMinus ;

## Smooth with a very short zero-lag to eliminate outliers - Color the result
plot VxNet = 2 * WMA(VxNetRaw, VxNetSmooth) - WMA(WMA(VxNetRaw, VxNetSmooth),VxNetSmooth);
VxNet.DefineColor("PosUp", Color.GREEN);
VxNet.DefineColor("PosDn", Color.DARK_GREEN);
VxNet.DefineColor("NegDn", Color.RED);
VxNet.DefineColor("NegUp", Color.DARK_RED);
VxNet.AssignValueColor(if VxNet >= 0 then if VxNet > VxNet[1] then VxNet.color("PosUp") else VxNet.color("PosDn") else if VxNet < VxNet[1] then VxNet.color("NegDn") else VxNet.color("NegUp"));
VXNet.setlineWeight (3);
VxNet.sethiding(VolPlotMode == VolPlotMode.Classic);

## add volume pressure shade and the labels
def VxRatio = round(100 * VxNetRaw/VX,1);
def VxCloud = if VolPlotMode != VolPlotMode.Classic then VxNet else double.NaN ;
addcloud(VXCloud, 0);
AddLabel(ShowLabels, "FastVol: " + FastVRatio + "%", if FastVRatio > 100 then if VxRatio < 0 then Color.light_red else Color.GREEN else Color.orange) ;
AddLabel (ShowLabels ,"VxPlus: "+ round(VxPlus/VX*100,1)+"%", color.light_green);
AddLabel (ShowLabels , "VxMinus: "+ round(VxMinus/VX*100,1)+"%", color.Light_red);
AddLabel (ShowLabels , "VxNet: " + VxRatio + "%", if between(VxRatio, -10, 10) then color.yellow else if VxRatio >= 10 then color.green else color.dark_orange);

This is really cool. One question, does the magenta color ever print? I scrolled through many stocks but have yet to find any magenta colored candles.
 

Similar threads

Top