Time Segmented Volume for ThinkorSwim

SolidChiken

New member
2019 Donor
Last edited:
Solution
I attempted to replicate this with the following code:

# Time Segmented Value (TSV)
Declare lower;
input length = 1;

#TSV=(Sum( IIf( C > Ref(C,-1), V * ( C-Ref(C,-1) ),
# IIf( C < Ref(C,-1),-V * ( C-Ref(C,-1) ), 0 ) ) ,18));

def x = (if close > close[1] then volume *(close - close[1]) else 0);

def y = (if close < close[1] then -volume * (close-close[1]) else 0);


plot TSV = sum(x+y, length);

#Plot TSVAvg = Average( TSV,5);
TSV.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);





I cannot for the life of me figure out why it is plotting so wrong. It looks nothing like the tradingview version, but to my knowledge, the code I used is the same.

Here is the tradingview version of the code, and it looks great on that...

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

After watching it for a few days I think it is correct. I tried changing it to (-1) but that just plotted everything above 0.
Yeah I think so too.... It's just slightly different from on balance volume I guess. I played with it that way a well... When you think about it, it doesn't make sense to make volume have a negative multiplier when close - close[1] would already be negative if close < close[1]. I guess it just wasn't well thought through despite receiving some kind of award for this proprietary indicator
 
Try this.

iM6dWik.jpg

Ruby:
## Time_Segmented_Volume
##
##
## CREDITS
## Requested by @squatsandstonks from orignal source https://www.tradingview.com/chart/BTCUSD/TG3DTxTR-INDICATOR-TIME-SEGMENTED-VOLUME/
##
##
## Removing the header Credit credits and description is not permitted, any modification needs to be shared.
##
##
## V 1.0 :    @cos251 - Initial release per request from usethinkscript forum.  All logic has not been ported, only base idea
##       :  

declare lower;

input tsvLength = 13;
input maLength = 7;

def t = Sum(if close > close[1] then (volume * (close-close[1])) else if close < close[1] then (volume *(close-close[1])) else 0,tsvLength);
def m = MovingAverage(AverageType.SIMPLE,t,maLength);

def PAL = (t > m) and (t > 0);
def PAL_Fail = (t < m) and (t > 0);
def PAS = (t <m) and (t < 0);
def PAS_Fail = (t > m) and (t < 0);

plot TSV = t;
TSV.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
TSV.AssignValueColor(if TSV > 0 then Color.MAGENTA else Color.CYAN);
TSV.SetLineWeight(4);
plot TSV_MA = m;
TSV_MA.SetDefaultColor(Color.GREEN);
plot zero = 0;


plot square = 0;
square.SetPaintingStrategy(PaintingStrategy.SQUARES);
square.SetDefaultColor(Color.DARK_GRAY);
square.AssignValueColor(if PAL then Color.GREEN else if PAL_Fail then Color.RED else if PAS then Color.YELLOW else if PAS_Fail then Color.YELLOW else Color.Current);
square.SetLineWeight(1);
@cos251 Thank you for this indicator.
 
It depends on the timeframe of your single candle. If it matches one of the timeframes supported by the volume profile study, then yes. Look in the time per profile setting of the VolumeProfile study.
 
I'm finding this indicator interesting. I was hoping I could find out what each color of the squares represents. Thanks!
It is the sum being calculated, whether it is greater/less than 0 and greater/less than moving average of the sum.

def PAL = (t > m) and (t > 0);
def PAL_Fail = (t < m) and (t > 0);
def PAS = (t <m) and (t < 0);
def PAS_Fail = (t > m) and (t < 0);
 
Looking to turn this into a scan.
Has anyone tried to make a TSV scan?
Assuming i want to see when the tsv goes >0
Would i use this in the custom scan code
plot TSV = t;
t[-1],0 and t>0
Thoughts?
Has anyone built anything to share.
TIA
 
Last edited:
Looking to turn this into a scan.
Has anyone tried to make a TSV scan?
Assuming i want to see when the tsv goes >0
Would i use this in the custom scan code
plot TSV = t;
t[-1],0 and t>0
Thoughts?
Has anyone built anything to share.
TIA
Here you go. Give it a shot!

Included plots:
  1. TSV_Bull
    1. t > 0 and t[1] < 0 and PAL (bullish MA momentum)
  2. TSV_Weak_Bull
    1. t > 0 and t[1] < 0 and PAL_Fail (no bullish MA momentum)
  3. TSV_Bear
    1. t < 0 and t[1] > 0 and PAS (bearish MA momentum)
  4. TSV_Weak_Bear
    1. t < 0 and t[1] > 0 and PAS_Fail (no bearish MA momentum)

Ruby:
## Time_Segmented_Volume_SCAN
##
##
## CREDITS
## Requested by @squatsandstonks from orignal source
## https://www.tradingview.com/chart/BTCUSD/TG3DTxTR-INDICATOR-TIME-SEGMENTED-VOLUME/
##
##
## Removing the header Credit credits and description is not permitted, any modification needs to be shared.
##
##
## V 1.0 :    @cos251 - Initial release of SCAN for for Time Segmented Volume
##       : 
# --- Inputs
input tsvLength = 13;
input maLength = 7;
# --- End Inputs

# --- Data
def t = Sum(if close > close[1] then (volume * (close-close[1])) else if close < close[1] then (volume *(close-close[1])) else 0,tsvLength);
def m = MovingAverage(AverageType.SIMPLE,t,maLength);

def PAL = (t > m) and (t > 0);
def PAL_Fail = (t < m) and (t > 0);
def PAS = (t <m) and (t < 0);
def PAS_Fail = (t > m) and (t < 0);
# --- End Data

# --- Plots
plot TSV_Bull = if (t > 0 and t[1] < 0) and PAL then 1 else Double.NaN;
plot TSV_Weak_Bull = if (t > 0 and t[1] < 0) and PAL_Fail then 1 else Double.NaN;
plot TSV_Bear = if (t < 0 and t[1] > 0) and PAS then 1 else Double.NaN;
plot TSV_Weak_Bear = if (t < 0 and t[1] > 0) and PAS_Fail then 1 else Double.NaN;
# --- End Plots
 
Try this.

iM6dWik.jpg

Ruby:
## Time_Segmented_Volume
##
##
## CREDITS
## Requested by @squatsandstonks from orignal source https://www.tradingview.com/chart/BTCUSD/TG3DTxTR-INDICATOR-TIME-SEGMENTED-VOLUME/
##
##
## Removing the header Credit credits and description is not permitted, any modification needs to be shared.
##
##
## V 1.0 :    @cos251 - Initial release per request from usethinkscript forum.  All logic has not been ported, only base idea
##       : 

declare lower;

input tsvLength = 13;
input maLength = 7;

def t = Sum(if close > close[1] then (volume * (close-close[1])) else if close < close[1] then (volume *(close-close[1])) else 0,tsvLength);
def m = MovingAverage(AverageType.SIMPLE,t,maLength);

def PAL = (t > m) and (t > 0);
def PAL_Fail = (t < m) and (t > 0);
def PAS = (t <m) and (t < 0);
def PAS_Fail = (t > m) and (t < 0);

plot TSV = t;
TSV.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
TSV.AssignValueColor(if TSV > 0 then Color.MAGENTA else Color.CYAN);
TSV.SetLineWeight(4);
plot TSV_MA = m;
TSV_MA.SetDefaultColor(Color.GREEN);
plot zero = 0;


plot square = 0;
square.SetPaintingStrategy(PaintingStrategy.SQUARES);
square.SetDefaultColor(Color.DARK_GRAY);
square.AssignValueColor(if PAL then Color.GREEN else if PAL_Fail then Color.RED else if PAS then Color.YELLOW else if PAS_Fail then Color.YELLOW else Color.Current);
square.SetLineWeight(1);
Hi and thank you for sharing this. I was wondering if there is anyway for me to change the colors of the histogram. As I mainly use the blue color on my charts for up ticks and I use the Pink color to replace the red bars for down ticks.
 
Hi and thank you for sharing this. I was wondering if there is anyway for me to change the colors of the histogram. As I mainly use the blue color on my charts for up ticks and I use the Pink color to replace the red bars for down ticks.
Change this line:

Ruby:
TSV.AssignValueColor(if TSV > 0 then Color.MAGENTA else Color.CYAN);

To this:


Ruby:
TSV.AssignValueColor(if TSV > 0 then Color.BLUE else Color.PINK);
 
I found this;

https://futures.io/thinkorswim/10957-time-segmented-volume-worden-telecharts.html


# Time Segmented Value (TSV)

input length = 18;
input avgLength = 10;

# TSV=(Sum( IIf( C > Ref(C,-1), V * ( C-Ref(C,-1) ),
# IIf( C < Ref(C,-1),-V * ( C-Ref(C,-1) ), 0 ) ) ,18));

plot TSV = sum( if close > close[1] then volume * (close - close[1]) else if close < close[1] then -1* volume *(close - close[1]) else 0, length);

Plot TSVAvg = Average(TSV, avglength);
 
Here it is with Red upper and Green lower for potential buy sell and buy setups. I have it set at 14. Back test w diff numbers. Let me know if there is something missing.

https://tos.mx/PoV4RcZ

# Volume_TSV

declare lower;

input length = 14;

def VP = ExpAverage(Sign(close - close[1]) * volume, length);
def TV = ExpAverage(volume, length);

plot VZO = 100 * VP / TV;
plot "+60" = 60;
plot "+40" = 40;
plot "-40" = -40;
plot "-60" = -60;
plot ZeroLine = 0;

VZO.SetDefaultColor(GetColor(1));
"+60".SetDefaultColor(GetColor(5));
"+40".SetDefaultColor(GetColor(5));
"-40".SetDefaultColor(GetColor(6));
"-60".SetDefaultColor(GetColor(6));
ZeroLine.SetDefaultColor(GetColor(4));
 
Here it is with Red upper and Green lower for potential buy sell and buy setups. I have it set at 14. Back test w diff numbers. Let me know if there is something missing.

https://tos.mx/PoV4RcZ

# Volume_TSV

declare lower;

input length = 14;

def VP = ExpAverage(Sign(close - close[1]) * volume, length);
def TV = ExpAverage(volume, length);

plot VZO = 100 * VP / TV;
plot "+60" = 60;
plot "+40" = 40;
plot "-40" = -40;
plot "-60" = -60;
plot ZeroLine = 0;

VZO.SetDefaultColor(GetColor(1));
"+60".SetDefaultColor(GetColor(5));
"+40".SetDefaultColor(GetColor(5));
"-40".SetDefaultColor(GetColor(6));
"-60".SetDefaultColor(GetColor(6));
ZeroLine.SetDefaultColor(GetColor(4));
zero I'm assuming is the consolidation area. What are the buy/sell zones on the indicator?
 
I am liking this indicator. Thank you for creating. Gives a nice edge when trying to figure out if consolidation is accumulation vs distribution. And does show nice divergences.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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