Thinkorswim real time buy/sell volume

Solution
I'm seeking a script that will show real time volume of buy and sell orders on the chart page.
Thank you for any help.
thinkScript can't see actual buy/sell order tags (that data isn't exposed by TOS), so this study builds the best available estimate of buy vs. sell pressure using three layers of logic, from most to least reliable:


  1. Live bid/ask comparison (most accurate, current bar only)
    When real-time quotes are available, it checks where the last trade printed: at/above the ask → counted as buy volume, at/below the bid → counted as sell volume. This is the closest thing to "real" buy/sell classification thinkScript can do, but it only works on the bar that's currently forming — historical bars don't...
I'm seeking a script that will show real time volume of buy and sell orders on the chart page.
Thank you for any help.
thinkScript can't see actual buy/sell order tags (that data isn't exposed by TOS), so this study builds the best available estimate of buy vs. sell pressure using three layers of logic, from most to least reliable:


  1. Live bid/ask comparison (most accurate, current bar only)
    When real-time quotes are available, it checks where the last trade printed: at/above the ask → counted as buy volume, at/below the bid → counted as sell volume. This is the closest thing to "real" buy/sell classification thinkScript can do, but it only works on the bar that's currently forming — historical bars don't retain bid/ask data.
  2. Range-position estimate (used for all historical bars)
    For every other bar, it looks at where the candle closed within its high-low range. Close near the high = mostly buying pressure that bar; close near the low = mostly selling pressure. This is far better than just comparing to the prior close, because it uses the full range of the bar instead of a single point.
  3. Tick-rule fallback (edge case only)
    If a bar has zero range (a flat/doji bar), it falls back to comparing today's close to yesterday's close, splitting volume 50/50 if unchanged.

What the plots mean


  • Green/red histogram (Delta): net buy vs. sell volume estimate for each individual bar.
  • White line (Cumulative Delta): running total of that delta, reset daily/per-session (your choice), showing whether buying or selling pressure has been building over the period.
  • Yellow dashed line: a smoothed version of cumulative delta, filtering noise so you can see the underlying trend in order flow.
  • Red/green dots: divergence flags — price hits a new high/low but cumulative delta doesn't confirm it, which often signals the move is running out of real buying/selling support.

The honest caveat
This is a volume-based proxy, not literal order data. It answers "was there more apparent buying or selling pressure" rather than "here are the actual buy and sell orders." Treat it as a sentiment/pressure gauge to combine with price action — not as ground truth on order flow the way a true Level II/tape-reading tool would give you.

This is an approximation code as explained above:
Code:
declare lower;

input smoothingLength = 5;
input resetPeriod = {default DAILY, SESSION, NONE};
input showDivergence = yes;
input divergenceLookback = 10;

# --- Core Range-Position Volume Estimate ---
def range = high - low;
def clv = if range > 0 then ((close - low) - (high - close)) / range else 0;

def rangeBuyVol = volume * (clv + 1) / 2;
def rangeSellVol = volume * (1 - (clv + 1) / 2);

# --- Tick Rule Fallback (for flat/doji bars where range is 0 or tiny) ---
def isUpTick = close > close[1];
def isDownTick = close < close[1];
def tickBuyVol = if isUpTick then volume else if isDownTick then 0 else volume / 2;
def tickSellVol = if isDownTick then volume else if isUpTick then 0 else volume / 2;

def baseBuyVol = if range > 0 then rangeBuyVol else tickBuyVol;
def baseSellVol = if range > 0 then rangeSellVol else tickSellVol;

# --- Bid/Ask Refinement (only meaningful when real-time quotes exist) ---
def bid = close(PriceType.BID);
def ask = close(PriceType.ASK);

def hasQuotes = !IsNaN(bid) and !IsNaN(ask);
def atAsk = hasQuotes and close >= ask;
def atBid = hasQuotes and close <= bid;

def buyVol = if hasQuotes then
(if atAsk then volume else if atBid then 0 else baseBuyVol)
else baseBuyVol;

def sellVol = if hasQuotes then
(if atBid then volume else if atAsk then 0 else baseSellVol)
else baseSellVol;

# --- Delta ---
def delta = buyVol - sellVol;

# --- Reset Logic for Cumulative Delta ---
def newPeriod =
if resetPeriod == resetPeriod.DAILY then GetDay() != GetDay()[1]
else if resetPeriod == resetPeriod.SESSION then GetYYYYMMDD() != GetYYYYMMDD()[1] or SecondsFromTime(0930) == 0
else 0;

def cumDelta = CompoundValue(1, if newPeriod then delta else cumDelta[1] + delta, delta);

# --- Smoothed Delta ---
def smoothedDelta = ExpAverage(cumDelta, smoothingLength);

# --- Plots ---
plot DeltaPlot = delta;
plot CumulativeDelta = cumDelta;
plot SmoothedCumDelta = smoothedDelta;

DeltaPlot.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
DeltaPlot.AssignValueColor(if delta >= 0 then Color.GREEN else Color.RED);

CumulativeDelta.SetPaintingStrategy(PaintingStrategy.LINE);
CumulativeDelta.SetLineWeight(2);
CumulativeDelta.SetDefaultColor(Color.WHITE);

SmoothedCumDelta.SetPaintingStrategy(PaintingStrategy.LINE);
SmoothedCumDelta.SetLineWeight(1);
SmoothedCumDelta.SetDefaultColor(Color.YELLOW);
SmoothedCumDelta.SetStyle(Curve.SHORT_DASH);

plot ZeroLine = 0;
ZeroLine.SetDefaultColor(Color.GRAY);
ZeroLine.SetStyle(Curve.SHORT_DASH);

# --- Divergence Detection ---
def priceHigh = Highest(high, divergenceLookback);
def priceLow = Lowest(low, divergenceLookback);
def deltaHigh = Highest(cumDelta, divergenceLookback);
def deltaLow = Lowest(cumDelta, divergenceLookback);

def bearishDiv = showDivergence and high >= priceHigh and cumDelta < deltaHigh;
def bullishDiv = showDivergence and low <= priceLow and cumDelta > deltaLow;

plot BearDivMarker = if bearishDiv then cumDelta else Double.NaN;
BearDivMarker.SetPaintingStrategy(PaintingStrategy.POINTS);
BearDivMarker.SetDefaultColor(Color.RED);
BearDivMarker.SetLineWeight(4);

plot BullDivMarker = if bullishDiv then cumDelta else Double.NaN;
BullDivMarker.SetPaintingStrategy(PaintingStrategy.POINTS);
BullDivMarker.SetDefaultColor(Color.GREEN);
BullDivMarker.SetLineWeight(4);

# --- Label ---
AddLabel(yes, "Delta: " + Round(delta, 0) + " | CumDelta: " + Round(cumDelta, 0),
if delta >= 0 then Color.GREEN else Color.RED);

# --- Alerts ---
Alert(bearishDiv, "Bearish Delta Divergence", Alert.BAR, Sound.Ring);
Alert(bullishDiv, "Bullish Delta Divergence", Alert.BAR, Sound.Ring);
 
Last edited by a moderator:
Solution

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

If it's any consolation, that type of data, where it is truly available, just renders in duplication of price action. It moves along with price, at same time, and at the exact same pace. It doesn't really lead, or provide any advanced warning.

Whether it's volume hitting the bid, volume on upticks, or whatever else, one order here and there is meaningless. The data needs time to accumulate. By the time it's noticeable, or distinguishable from noise and jitters, the candle has already made its move.
 
If it's any consolation, that type of data, where it is truly available, just renders in duplication of price action. It moves along with price, at same time, and at the exact same pace. It doesn't really lead, or provide any advanced warning.

Whether it's volume hitting the bid, volume on upticks, or whatever else, one order here and there is meaningless. The data needs time to accumulate. By the time it's noticeable, or distinguishable from noise and jitters, the candle has already made its move.
Yeah it's not something I use but was trying to provide the best answer to the person asking for the data?
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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