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.
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: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: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.
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);
Join useThinkScript to post your question to a community of 21,000+ developers and traders.
Yeah it's not something I use but was trying to provide the best answer to the person asking for the data?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.
Start a new thread and receive assistance from our community.
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.
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.