Coding Help for Welkin's Advanced Volume Indicator.

fungus12

Member
Hi I have a question on how to code something in Welkin's AVI. Here is the link to the thread for the script https://usethinkscript.com/threads/advanced-volume-indicator-for-thinkorswim.1665/

My question is about the buy/sell str for the second aggregation. First off let me just present two images so you know what I'm talking about.

Here is the indicator with the second aggregation turned off:

D6Z3iet.png


And here is the indicator with the second aggregation turned on:

tQjiaPG.png


My question is, is it possible to have some kind of percentage present in the second image that indicates the percentage of buy vs sell shown in the clouds? For example in that image from 6:30 - 7:00 it would show something like "95% buy/5% sell", then at 7:01 it would show "60% buy/40% sell". Something like that. I would prefer this also be favorable to backtesting. In other words, have the percentages present not only at the most current data but historical data as well.

Also along similar lines, I also would like to change the watchlist column in Welkin's post to show the buy/str for an aggregate (15m, for example) instead of just current bars. Here is the code in the thread for the watchlist:
Code:
#Buy/Sell Strength Column
def o = open;
def h = high;
def l = low;
def c = close;
def PR = h - l;
def BuyStr = ((c - l) / PR) * 100;

AddLabel(1,Round(BuyStr,1)+" | " + Round(100-BuyStr,1)+"%", Color.BLACK);

AssignBackgroundColor(if BuyStr >= 70 then Color.Green else if BuyStr > 50 then Color.DARK_GREEN else if BuyStr <= 30 then Color.RED else if BuyStr < 50 then Color.DARK_RED else Color.GRAY);

I wish Welkin was around to answer these questions but he's been inactive for several months now. If anyone knows how to code these things, please let me know. Thanks in advance.
 
Hey everyone, I'm looking for help modifying the code below. Basically I want to
plot the a cumulative line of the buy sell percentage indicator shown in the top
left of the screen by indicator below. For example on a 1 minute
chart the 1st bar is 60% buy and 40% sell = ( 20% buy ) and the next bar is 70% buy
and 30% sell = ( 40% buy ) I would like the plot to show 60% Buy. Looking for
each bar to add or subtract from total of the day. Also would like to be able to choose
RTH or ETH if possible. Have done some coding but cant figure out how to do
cumulative data. Any help would be appreciated.

Here is the code:

#Advanced Volume Study
#[email protected]
#v5.22.2020
declare upper;
input ShowVolumeAsCandlesticks = no;
input ShowBuySellStrengthOnVolumeBars = yes;
input ShowBuySellStrength2ndAgg = no;
input AvgDayVolLength = 5;
input AvgVolLength = 20;
input ShowDayVolLabel = yes;
input ShowBarVolLabel = yes;
input ShowEthTotalVol = no;
input ShowBuySellStrength = yes;


input VolAverageType = AverageType.SIMPLE;


def NA = Double.NaN;
def PriceRange = high - low;


#Current Candle Buy and Sell Strength
def BuyStr = ((close - low) / PriceRange) * 100;
def SellStr = ((high - close) / PriceRange) * 100;

def AlertUp = BuyStr >= 90 ;
def AlertDn = Sellstr >= 90 ;

def AlertRangeUp = BuyStr <= 90 ;
def AlertRangeDn = Sellstr <= 90 ;

def AlertChoppyUp = BuyStr <= 60 ;
def AlertChoppyDn = Sellstr <= 60 ;



#current candle Buy/Sell strength labels
AddLabel(if ShowBuySellStrength then 1 else 0, " ", Color.BLACK);
AddLabel(if ShowBuySellStrength then 1 else 0, "1", Color.black);
AddLabel(if ShowBuySellStrength then 1 else 0, "Sell " + Round(SellStr, 2) + "%", if SellStr > BuyStr then Color.RED else Color.RED);
AddLabel(if ShowBuySellStrength then 1 else 0, "Buy " + Round(BuyStr, 2) + "%", if BuyStr > SellStr then CREATEcolor(0,102,255) else CREATEcolor(0,102,255));
 

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

I'm intrigued by Welkin's MTF Volume Strength Oscillator (https://tos.mx/UVAhSKz) ,called out in this thread (https://usethinkscript.com/threads/advanced-volume-indicator-for-thinkorswim.1665/#post-22856).

This is the study parameters
6Ophszp.png


Just so I am interpreting this study correctly, the BSDiff plots the difference (Buy-Sell) for the current chart aggregation , BS2Siff plots the difference between cumulative Buy & Sell for the aggregation2 period and BS3Diff plots the difference between cumulative Buy & Sell for aggregation3 periods.

If thats the case, when I turn off the plots for Bs2Diff and BS3Diff and only plot the BSDiff , I get this plot
LbHzH1e.png


Dont understand the additional plots(pointed in the screenshot).. a Single BSDiff plot should have either a Green(Buy greater than Sell) or RED(Sell greater than Buy) at a given point in time .,not both, right?. I see two plots here.

EDIT: Infact, I turned off all the plots on the study and it still plotted , as shown above. Looks like the study is hard coded to plot two of the aggregations.
Can someone pls look into the code and fix it, so it only plots the BSDiffs, as configured in the inputs.


Thanks
 
Last edited:
I'm intrigued by Welkin's MTF Volume Strength Oscillator (https://tos.mx/UVAhSKz) ,called out in this thread (https://usethinkscript.com/threads/advanced-volume-indicator-for-thinkorswim.1665/#post-22856).

This is the study parameters
6Ophszp.png


Just so I am interpreting this study correctly, the BSDiff plots the difference (Buy-Sell) for the current chart aggregation , BS2Siff plots the difference between cumulative Buy & Sell for the aggregation2 period and BS3Diff plots the difference between cumulative Buy & Sell for aggregation3 periods.

If thats the case, when I turn off the plots for Bs2Diff and BS3Diff and only plot the BSDiff , I get this plot
LbHzH1e.png


Dont understand the additional plots(pointed in the screenshot).. a Single BSDiff plot should have either a Green(Buy greater than Sell) or RED(Sell greater than Buy) at a given point in time .,not both, right?. I see two plots here.

EDIT: Infact, I turned off all the plots on the study and it still plotted , as shown above. Looks like the study is hard coded to plot two of the aggregations.
Can someone pls look into the code and fix it, so it only plots the BSDiffs, as configured in the inputs.


Thanks
Any assistance pls?
 
Any assistance pls?

Check/Uncheck the plots you want at the input screen as you indicated.

The colored areas are clouds through the addcloud() function. There are 2 in the code. Comment (#) out the one you do not want as follows for the aggregation you do not want. For example, the higher aggregation:

Code:
#AddCloud(BS2Diff, zeroline, Color.GREEN, Color.RED, no);
 
Any ideas pls?

When I click on the Volume scale on the right and drag, the whole study compresses and does move the bars/plot below the labels, as shown below..,but it changes the scaling on all the studies & main chart(including price chart scaling reset to manual). Also the zero line moves up to middle of the study and compresses the bars/plots which is not desirable.
g2cV0pm.png


Chatted with TOS support, but no use. They suggested the script needs to be fixed..,as I dont have this scaling issue with any other study.

Thanks

Found a solution myself.. the issue seems to show up when this study is plotted in the Volume sub-graph. Moved it down as a proper lower study and the vertical scaling issue seems to have been resolved..
 
Found a solution myself.. the issue seems to show up when this study is plotted in the Volume sub-graph. Moved it down as a proper lower study and the vertical scaling issue seems to have been resolved..
Another thought,
Partition Labels into another frame.
I think you can potentially reorganize your charts by separating labels from the graphs.


Interesting chat, could you share the link when ready? Also, how do you use it ? In combination with which indicators?
 
Last edited by a moderator:
Another thought,
Partition Labels into another frame.
I think you can potentially reorganize your charts by separating labels from the graphs.
Thanks for the idea, will try.

Interesting chat, could you share the link when ready? Also, how do you use it ? In combination with which indicators?
yes, in combination with few things(S/R levels,Pivots,Orderbook imbalance,Momentum,Higher timeframe alignment).
 
Wondering if someone can help adding a treshold level for the Sigma 3 volume filter. So i would like to hide bars that meets the Sigma 3 condition IF they are below the treshold level. And the treshold level is x amount of shares traded on the current bar.

Thanks in advance
 
In case anyone was interested, I made a Mobile version that will show pretty much everything in the standard indicator just obviously due to the extreme limitations of the mobile app, it won't be as pretty.
You'll have to manually change the plot settings (volrel, Avgvol, volsig2 and volsig3) to triangles and color them accordingly.
I did change these lines because of my location
Code:
def Start = 0830;
def End = 1500;

Code:
#Advanced Volume Study
#[email protected]
#v5.22.2020
#
#
####----24.01.17---@jefepollo   --Removed everything that doesn't work on Mobile App
#                               --Added in Triangle and buy/sell total plots
#                               --You can view buy/sell strength "buystr"/"sellstr" and actual total of shares "buying"/"selling"
#                               --Recommend setting the buying/selling to plot as lines width of 2 and turning the buyStr/sellstr to off. The Percent buystr/sellstr can still be viewed in the title of the indicator
#                               --I did add in a "Sigma1" level as I consider BIG volume important
declare lower;




input AvgVolLength = 20;
input VolAverageType = AverageType.SIMPLE;
input RelativetoPrevVolTolerance = 1.25; #if volume is 1.25x greater than previous bar it will paint even if it is still below the average/sigma2/sigma3

def O = open;
def H = high;
def C = close;
def L = low;
def V = volume;
def NA = Double.NaN;
def PriceRange = H - L;
def Start = 0830;
def End = 1500;
def conf = SecondsFromTime(Start) >= 0 and SecondsFromTime(End) <= 0;


DefineGlobalColor("Bullish", Color.GREEN);
DefineGlobalColor("Bearish", Color.RED);
DefineGlobalColor("VolAvg", CreateColor(0, 100, 200));
DefineGlobalColor("VolSigma2", Color.DARK_ORANGE);
DefineGlobalColor("VolSigma3", Color.MAGENTA);
DefineGlobalColor("Relative to Prev", Color.YELLOW);
DefineGlobalColor("Below Average", Color.GRAY);


##############################################################################
####----Current Candle Buy and Sell Strength and Total buy/sell orders----####
##############################################################################
def BuyStrPer = ((close - low) / PriceRange) * 100;
def SellStrPer = ((high - close) / PriceRange) * 100;


plot buying = V*(C-L)/(H-L);
Buying.SetDefaultColor(GlobalColor("Bullish"));

plot selling = V*(H-C)/(H-L);
Selling.SetDefaultColor(GlobalColor("Bearish"));

plot BuyStr = BuyStrPer;
#plot BuyStr = (BuyStrPer/100)*V;
BuyStr.SetDefaultColor(GlobalColor("Bullish"));

plot SellStr = SellStrPer;
#plot SellStr = (SellStrPer/100)*V;
SellStr.SetDefaultColor(GlobalColor("Bearish"));

plot Vol = V;
Vol.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
Vol.SetLineWeight(1);

plot VolAvg = MovingAverage(VolAverageType, V, AvgVolLength);
VolAvg.SetDefaultColor(GlobalColor("VolAvg"));
VolAvg.SetLineWeight(2);

############################################
####---2Sigma and 3Sigma Vol Filter----#####
############################################
def Num_Dev1 = 1.0;
def Num_Dev2 = 2.0;
def Num_Dev3 = 3.0;
def averageType = AverageType.SIMPLE;
def sDev = StDev(data = V, length = AvgVolLength);

plot VolSigma1 = VolAvg + Num_Dev1 * sDev;
VolSigma1.SetDefaultColor(GlobalColor("VolSigma1"));
plot VolSigma2 = VolAvg + Num_Dev2 * sDev;
VolSigma2.SetDefaultColor(GlobalColor("VolSigma2"));
plot VolSigma3 = VolAvg + Num_Dev3 * sDev;
VolSigma3.SetDefaultColor(GlobalColor("VolSigma3"));


def RelVol = V / VolAvg[1];
def RelPrevVol = V / V[1];


#########################################
#####----Triangle Vol Signals----########
#########################################

plot volrel = if RelPrevVol >= RelativetoPrevVolTolerance and V < VolAvg then V else Na;
plot Avgvol = if V >= VolAvg and V < VolSigma2 then V else NA;
plot volsig2 = if V >= VolSigma2 and V < VolSigma3 then V else NA;
plot volsig3 = if V >= VolSigma3 then V else NA;

Volrel.SetDefaultColor(Color.YELLOW);
Avgvol.SetDefaultColor(CreateColor(0, 125, 225));
Volsig2.SetDefaultColor(Color.DARK_ORANGE);
Volsig3.SetDefaultColor(Color.MAGENTA);



##--END OF CODE--##

And here is the companion upper study
Code:
#Companion indicator to the Advanced Volume Study for Volume Spread Analysis
#[email protected]
#
#
#        24.01.18---@jefepollo       --Removed everything that doesn't function on mobile
#                                    --Last 4 plots are my replacement for assignPriceColor: I set them to draw as points
#                                   
#
#
#
declare upper;
input AvgVolLength = 20;
input VolAverageType = AverageType.SIMPLE;
input RelativetoPrevVolTolerance = 1.25; #if volume is 1.25x greater than previous bar it will paint even if it is still below the average/sigma2/sigma3

def NA = Double.NaN;
def Start = 0830;
def End = 1500;
def conf = SecondsFromTime(Start) >= 0 and SecondsFromTime(End) <= 0;


def Vol = volume;

def VolAvg = MovingAverage(VolAverageType, volume, AvgVolLength);

#2Sigma and 3Sigma Vol Filter
def Num_Dev2 = 2.0;
def Num_Dev3 = 3.0;
def averageType = AverageType.SIMPLE;
def sDev = StDev(data = Vol, length = AvgVolLength);


def VolSigma2 = VolAvg + Num_Dev2 * sDev;
def VolSigma3 = VolAvg + Num_Dev3 * sDev;

#####
#VSA start test
#####
def VSig3H = if volume >= VolSigma3 then high else VSig3H[1];
def VSig2H = if volume >= VolSigma2 and volume < VolSigma3 then high else VSig2H[1];
def VSigAH = if volume >= VolAvg and volume < VolSigma2 then high else VSigAH[1];
def VSig3L = if volume >= VolSigma3 then low else VSig3L[1];
def VSig2L = if volume >= VolSigma2 and volume < VolSigma3 then low else VSig2L[1];
def VSigAL = if volume >= VolAvg and volume < VolSigma2 then low else VSigAL[1];

###--your HORIZONTAL lines
plot VSig3Hc = VSig3H;
plot VSig2Hc = VSig2H;
plot VSigAHc = VSigAH;
plot VSig3Lc = VSig3L;
plot VSig2Lc = VSig2L;
plot VSigALc = VSigAL;


VSig3Hc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VSig2Hc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VSigAHc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

VSig3Lc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VSig2Lc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
VSigALc.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

VSig3Hc.SetDefaultColor(Color.MAGENTA);
VSig2Hc.SetDefaultColor(Color.DARK_ORANGE);
VSigAHc.SetDefaultColor(CreateColor(0, 125, 225));

VSig3Lc.SetDefaultColor(Color.MAGENTA);
VSig2Lc.SetDefaultColor(Color.DARK_ORANGE);
VSigALc.SetDefaultColor(CreateColor(0, 125, 225));

#####
def RelVol = Vol / VolAvg[1];
def RelPrevVol = volume / volume[1];

###---Points below Candles
plot volrel = if RelPrevVol >= RelativetoPrevVolTolerance and volume < VolAvg then low - (5*ticksize()) else NA;
plot Avgvol = if volume >= VolAvg and volume < VolSigma2 then low - (5*ticksize()) else NA;
plot volsig2 = if volume >= VolSigma2 and volume < VolSigma3 then low - (5*ticksize()) else NA;
plot volsig3 = if volume >= VolSigma3 then low - (5*ticksize()) else NA;

Volrel.SetDefaultColor(Color.YELLOW);
Avgvol.SetDefaultColor(CreateColor(0, 125, 225));
Volsig2.SetDefaultColor(Color.DARK_ORANGE);
Volsig3.SetDefaultColor(Color.MAGENTA);



####----END of CODE----####
The "VSigX" plots in companion study need to be changed to 'HORIZONTAL' in settings to display correctly. In the below screenshots I turned volume off to highlight how the total buy/sell trades display.
Screenshot_20240119_164123_thinkorswim.jpgScreenshot_20240119_164817_thinkorswim.jpgScreenshot_20240119_164921_thinkorswim.jpg

And below is the scanner for volume sigma levels and buy/sell strength
Code:
###---Simple scanner


input AvgVolLength = 20;


def averageType = AverageType.SIMPLE;
def VolAvg = MovingAverage(AverageType, volume, AvgVolLength);
def Num_Dev1 = 1.0;
def Num_Dev2 = 2.0;
def Num_Dev3 = 3.0;
def sDev = StDev(data = volume, length = AvgVolLength);
def PriceRange = high - low;
def BuyStr = ((close - low) / PriceRange) * 100;
def SellStr = ((high - close) / PriceRange) * 100;


plot VolSigma1 = VolAvg + Num_Dev1 * sDev;
plot VolSigma2 = VolAvg + Num_Dev2 * sDev;
plot VolSigma3 = VolAvg + Num_Dev3 * sDev;
plot Buy = BuyStr;
plot Sell = SellStr;


####----END of CODE----####
 
Last edited:

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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