Advanced Volume Indicator for ThinkorSwim

Status
Not open for further replies.
How to split After-hours and Pre-market volumes separately? The following gives both the volumes combined.. the logic is a bit cryptic.. Can someone help? Thanks!

def conf = SecondsFromTime(0930) >= 0 and SecondsFromTime(1600) <= 0;
def ExtVol = if !conf and conf[1] then volume else if !conf then CompoundValue(1, ExtVol[1] + volume, volume) else ExtVol[1];

try this
Code:
input showAftermarket = yes;
input showPremarket = yes;

input rthStart = 0930;
input rthEnd = 1609;
input pmStart = 0400;
input amEnd= 1959;

def NA = Double.NaN;
def amConf = SecondsFromTime(rthEnd) >= 0 and SecondsFromTime(amEnd) <= 0;
def pmConf = SecondsFromTime(pmStart) >= 0 and SecondsFromTime(rthStart - 1) <= 0;

def amVol = if amConf and !amConf[1] and showAftermarket then volume else if amConf and showAftermarket then CompoundValue(1, amVol[1] + volume, volume) else NA;
def pmVol = if pmConf and !pmConf[1] and showPremarket then volume else if pmConf and showPremarket then CompoundValue(1, pmVol[1] + volume, volume) else NA;

plot amV = amVol;
plot pmV = pmVol;

amV.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
pmV.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
amV.AssignValueColor(if close > open then Color.GREEN else Color.RED);
pmV.AssignValueColor(if close > open then Color.GREEN else Color.RED);
 

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

@Welkin I want to actually ask about the VSA addon again. I was wondering if it would be possible to make the VSA lines coming from the bars to have the shaded transparent background (Kind of like the Supply Demand zones on the AMM 2.0)
I've tried adding clouds to the indicator, ends up making the chart nearly unreadable at times IMO, that is why I left them out.

You know, I just had another good idea for this. The triangles indicating an increasing in volume is awesome, and it makes me wonder if you can create another similar addition that places a triangle (or any boolean) on a volume bar that meets the condition of a long top or bottom wick, and the volume is less than the previous two volumes (for testing supply and demand)

@Welkin Also, I was wondering if you could perhaps provide some sort of guide at interpreting the indicator and the VSA addon?
I put this together according to your criteria, I find that current volume greater volume than the prior 2 bars shows some better signals when rejecting a level with a large top or bottom wick as these bars are usually above the volume average. but of course what is happening in higher time frames or the current trending environment will also determine if you see exhaustion or increase in volume. There is a switch for either option. color is determined by if it is the top wick (red) or bottom wick (green) is largest. wickThreshold is set to 100%, so if the wick is greater than the body + top or bottom wick combined then it will signal. adjust and play around with it, change the colors. apply the indicator twice with both modes active and see what it is able to tell you.
Code:
declare on_volume;

input wickThreshold = 100;
input prevVolMode = {default GreaterThan, LessThan};
def NA = Double.NaN;
def o = open;
def h = high;
def l = low;
def c = close;
def range = h-l;
def topwick = if c > o then h - c else h - o;
def botwick = if c > o then o - l else c - l;
def body = Max(o,c) - Min(o,c);

def topwtest = if topwick > (body + botwick) and (topwick/(body + botwick))*100 > wickThreshold then 1 else 0;
def botwtest = if botwick > (body + topwick) and (botwick/(body + topwick))*100 > wickThreshold then 1 else 0;

def VolTest;

switch(prevVolMode){
case GreaterThan:
VolTest = volume > volume[1] and volume > volume[2];
case LessThan:
VolTest = volume < volume[1] and volume < volume[2];
}

plot topwsig = if topwtest and VolTest then volume else NA;
plot botwsig = if botwtest and voltest then volume else NA;

topwsig.SetPaintingStrategy(PaintingStrategy.SQUARES);
botwsig.SetPaintingStrategy(PaintingStrategy.SQUARES);
topwsig.SetDefaultColor(Color.RED);
botwsig.SetDefaultColor(Color.GREEN);
topwsig.SetLineWeight(3);
botwsig.SetLineWeight(3);

As for interpreting volume and VSA, there are plenty of resources for this. In response to nicks post above:

Trading with VSA and volume in general is a big topic. I suggest searching and learning about Wyckoff Volume Spread Analysis and methodology as well as Dow Theory of Volume confirmation. This video should act as a good starting point:

There are tons of free resources online, just try looking around on youtube and google. Hope this helps.
 
Last edited:
@Welkin you seem code savvy. Would there be a way to make the current volume bar a projection of the close, depending on the aggregation this could be done differently but for example on 1 min if the current volume is 1 million 10 seconds into the bar then 60/10 = 6 so projected volume is 1 million * 6 = 6 million. This would be difficult on higher aggregations because of increased volume at certain points in a day but on lower aggregations it would work well.
 
I created a watchlist column to show relative to average vol as well as relative vol to previous bar, the background will also paint accordingly if volume is below/above averages on at the set aggregation.
PlCQiam.png


Code:
#[email protected]
#Advanced Volume Watchlist Column
#Add-on to https://tos.mx/jIx0x2n
#Relative to Avg Vol / Relative to Previous Volume bar

input VolAverageType = AverageType.SIMPLE;
input AvgVolLength = 20;
input RelativetoPrevVolTolerance = 1.25;

def Vol = volume;
def Num_Dev1 = 2.0;
def Num_Dev2 = 3.0;
def averageType = AverageType.SIMPLE;
def sDev = StDev(data = Vol, length = AvgVolLength);
def VolAvg = MovingAverage(VolAverageType, volume, AvgVolLength);
def VolSigma2 = VolAvg + Num_Dev1 * sDev;
def VolSigma3 = VolAvg + Num_Dev2 * sDev;
def RelVol = Vol / VolAvg[1];
def RelPrevVol = volume / volume[1];
AssignBackgroundColor(if Vol > VolSigma3 then Color.MAGENTA else if Vol > VolSigma2 then Color.DARK_ORANGE else if Vol > VolAvg then CreateColor(0, 100, 200) else if RelPrevVol >= RelativetoPrevVolTolerance then Color.YELLOW else Color.GRAY);

AddLabel(1, Round(RelVol, 2) + "x / " + Round(RelPrevVol, 2) +"x", Color.BLACK);

And here is a strength column
fvTij7O.png


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);
what time frame this can be used? i do intraday trading . Can i use in 3, 5 or 15 minutes time frame? Not clear about color codes. can you be more descriptive please. I am noob. Thanks.
 
what time frame this can be used? i do intraday trading . Can i use in 3, 5 or 15 minutes time frame? Not clear about color codes. can you be more descriptive please. I am noob. Thanks.
any time framecan be used though I recommend just using daily, and read the main post to understand the color coordination as that is what the custom column is based on...
 
Last edited:
I'm almost embarrassed to ask this question, it feels really basic but here we go...
I trade forex and have tried to add this and many other volume studies to my charts but not a single one actually displays.
I have enabled / disabled the "show volume subgraph" in the settings but that does not help either.
Thank you
 
I'm almost embarrassed to ask this question, it feels really basic but here we go...
I trade forex and have tried to add this and many other volume studies to my charts but not a single one actually displays.
I have enabled / disabled the "show volume subgraph" in the settings but that does not help either.
Thank you
volume subgraph needs to be on and make sure that there are enough bars for the study to calculate. I forget what the default is but that number is the length it uses. don't have the chart show less then 100 bars to be safe.
 
I'm almost embarrassed to ask this question, it feels really basic but here we go...
I trade forex and have tried to add this and many other volume studies to my charts but not a single one actually displays.
I have enabled / disabled the "show volume subgraph" in the settings but that does not help either.
Thank you
this is because forex isn't traded on a centralized exchange so you need to use tick count in place of volume.
try the following for the advanced volume indicator:
https://tos.mx/AjzK48r
for the VSA component:
https://tos.mx/rEI8t6Z

if you want to make another volume indicator compatible with forex charts replace volume with tick_count in the script
 
@Welkin I'm inexperienced with using time in code, if I wanted to make a tool that gives the projected volume for the bar that simply uses this equation (60/seconds out of current minute) * volume so far on unclosed bar. How would I do this.
 
You will get some type of volume in forex.
just go to settings, forex, Display: Price type: change to " Last".
Check " show volume subgraph"
 
@Welkin I'm inexperienced with using time in code, if I wanted to make a tool that gives the projected volume for the bar that simply uses this equation (60/seconds out of current minute) * volume so far on unclosed bar. How would I do this.
This is interesting, honestly not sure, I think it might be possible for projecting for higher time frames, not sure about 1 min aggregations. if there was a GetMin() function I think I could probably come up with something, I'll have to contemplate it for a bit. Are you familiar with another indicator that does this or something similar?

edit: i feel like I was close to something but am only able to use constant variables in the SecondsFromTime() and SecondsTillTime() functions

Roughly, my idea was to get the barnumber and multiply by GetAggregationPeriod() to work out a bar start time and add GetAggregationPeriod() on top of that to get an end time, then from this you could probably work out a multiplier to use with volume before close.... I'll tinker with it some more and see if I can get something working over the next couple days.
 
Last edited:
Okay I appreciate it, also is there any way to get the cumulative volume from 9:30 to 10:30?
Code:
declare lower;
def T1Start = 0930;
def T1End = 1029;

def NA = Double.NaN;
def conf = SecondsFromTime(T1Start) >= 0 and SecondsFromTime(T1End) <= 0;

def cvolT1 = if conf and !conf[1] then volume else if conf then cvolT1[1] + volume else cvolT1[1];

plot cvol = if conf then cvolT1 else NA;

cvol.SetDefaultColor(Color.YELLOW);
cvol.SetPaintingStrategy(PaintingStrategy.SQUARED_HISTOGRAM);
 
this is because forex isn't traded on a centralized exchange so you need to use tick count in place of volume.
try the following for the advanced volume indicator:
https://tos.mx/AjzK48r
for the VSA component:
https://tos.mx/rEI8t6Z

if you want to make another volume indicator compatible with forex charts replace volume with tick_count in the script
Thank you very much @Welkin - I really appreciate you getting back to me on this, I'm going to give it a try shortly.
 
@Welkin If I wanted to use just the ETH TVOL, on a column, what would i take out, can't seem to figure, any help will be good. This is really good. Thank you
 
@Welkin If I wanted to use just the ETH TVOL, on a column, what would i take out, can't seem to figure, any help will be good. This is really good. Thank you
try this https://tos.mx/bd5tvYX
Code:
def rthStart = 0930;
def rthEnd = 1600;
def conf = SecondsFromTime(rthStart) >= 0 and SecondsFromTime(rthEnd) <= 0;
def ETH_VOL = if !conf and conf[1] then volume else if !conf then CompoundValue(1, ETH_VOL[1] + volume, volume) else ETH_VOL[1];

plot ETHvol = ETH_VOL;
 
Status
Not open for further replies.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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