Better Volume for Thinkorswim

N

netarchitech

New member


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:



Shareable Link
http://tos.mx/PDkQYF

Source: https://thinkscripter.com/

Credit: Fil @ analyticsfortraders.com

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

 
Last edited:

Top