OPEN-SOURCE SCRIPT

Volume Ratio [MIT]

206
Core Logic:
This indicator splits each bar's volume into "Buy Volume" and "Sell Volume" based on the relationship between close and open price, then calculates the rolling ratio of cumulative buy volume to sell volume over the past n bars, helping traders gauge short-term buying vs. selling pressure.
Volume Split Rules:
  1. Bull bar (close > open): All volume assigned to Buy
  2. Bear bar (close < open): All volume assigned to Sell
  3. Flat bar (close == open): Handled by the "Flat bar volume" setting:
  4. Split 50/50 (default): 50% Buy + 50% Sell
  5. Ignore: Volume discarded (0 Buy, 0 Sell)
  6. All to Buy: All volume to Buy
  7. All to Sell: All volume to Sell

Calculation:

  1. buySum = rolling sum of buy volume over last n bars
  2. sellSum = rolling sum of sell volume over last n bars
  3. Ratio = buySum / sellSum (na when sellSum = 0)
  4. Ratio > 1: Buying pressure dominates (red line)
  5. Ratio < 1: Selling pressure dominates (green line)


Visual Elements:

  1. Green line: Rolling Buy Volume (n bars) – optional
  2. Red line: Rolling Sell Volume (n bars) – optional
  3. Colored line: Buy/Sell Ratio (red when >1, green when <1)
  4. Horizontal line at 1.0: Neutral balance level


Typical Trading Use Cases:

  1. Trend Confirmation: Ratio persistently > 1.2–1.5 while price rises → strong bullish confirmation
  2. Divergence: Price makes higher high but ratio declines → potential top divergence
  3. Breakout Filter: Breakout with rapidly rising ratio → higher probability breakout
  4. Range Market Avoidance: Ratio oscillating between 0.8–1.2 → avoid choppy entries
  5. Crypto Day/Swing Trading: Commonly used on 5m–1h charts, combined with price action or order flow


核心逻辑:
该指标基于K线的收盘价与开盘价的关系,将每根K线的成交量(volume)拆分为“买入量”(Buy Volume)和“卖出量”(Sell Volume),然后计算过去n根K线的累计买入量与卖出量的比率(Buy/Sell Ratio),用来判断短期内买卖力量的相对强弱。
成交量拆分规则:

  1. 阳线(close > open):全部成交量计入买入量
  2. 阴线(close < open):全部成交量计入卖出量
  3. 平线(close == open):根据“Flat bar volume”参数处理:
  4. Split 50/50(默认):平分50%买入 + 50%卖出
  5. Ignore:忽略该K线(都不计)
  6. All to Buy:全部算买入
  7. All to Sell:全部算卖出



计算方式:

  1. 滚动窗口n根K线内的累计买入量(buySum)和卖出量(sellSum)
  2. 比率 = buySum / sellSum(当sellSum=0时显示na)
  3. 比率 > 1:买入力量占优(红色)
  4. 比率 < 1:卖出力量占优(绿色)


图表显示:

  1. 绿色柱线:过去n根的累计买入量(可选显示)
  2. 红色柱线:过去n根的累计卖出量(可选显示)
  3. 彩色折线:买入/卖出比率(>1红色,<1绿色)
  4. 水平线1.0:平衡线(比率=1)


典型使用场景:

  1. 趋势确认:比率持续 > 1.2~1.5 且价格上涨 → 强势多头确认
  2. 背离信号:价格创新高但比率持续下降 → 潜在顶部背离
  3. 放量突破:突破关键位时比率同步快速拉升 → 突破有效性更高
  4. 震荡市过滤:比率在0.8~1.2区间反复震荡 → 避免频繁交易
  5. 币圈短线:常用于5分钟~1小时图,配合价格结构或订单流使用



Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.