Volume Imbalance Matrix [JPT]

Jos-ProTrader · study · 197 行 · 点赞 330 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Jos-ProTrader
 
//@version=6
indicator("Volume Imbalance Matrix [JPT]", shorttitle="VIM [JPT]", overlay=true, max_boxes_count=200, max_labels_count=200)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SETTINGS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
groupVol = "Volume Imbalance Settings"
volLength = input.int(20, "Volume Average Length", minval=1, group=groupVol)
imbalanceThreshold = input.float(60, "Imbalance Threshold (%)", minval=50, maxval=95, step=1, group=groupVol)
spikeMultiplier = input.float(1.8, "Volume Spike Multiplier", minval=1, step=0.1, group=groupVol)
 
groupTrend = "Trend Filter"
useEMA = input.bool(false, "Enable EMA Filter", group=groupTrend)
emaFastLen = input.int(50, "Fast EMA", group=groupTrend)
emaSlowLen = input.int(200, "Slow EMA", group=groupTrend)
showEMA = input.bool(false, "Show EMAs", group=groupTrend)
 
groupZones = "Imbalance Zones"
showZones = input.bool(true, "Show Imbalance Zones", group=groupZones)
zoneLength = input.int(25, "Zone Extension", minval=5, maxval=200, group=groupZones)
maxZones = input.int(15, "Maximum Zones", minval=1, maxval=50, group=groupZones)
 
groupSignals = "Signal Settings"
showSignals = input.bool(true, "Show BUY / SELL Signals", group=groupSignals)
showAbsorption = input.bool(true, "Show Absorption Signals", group=groupSignals)
showSpike = input.bool(true, "Highlight Volume Spikes", group=groupSignals)
 
groupDisplay = "Dashboard"
showDashboard = input.bool(true, "Show Volume Matrix", group=groupDisplay)
dashboardPosition = input.string("Top Right", "Dashboard Position", options=["Top Right", "Top Left", "Bottom Right", "Bottom Left"], group=groupDisplay)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// TREND CALCULATION
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
emaFast = ta.ema(close, emaFastLen)
emaSlow = ta.ema(close, emaSlowLen)
 
bullTrend = emaFast > emaSlow
bearTrend = emaFast < emaSlow
 
plot(showEMA ? emaFast : na, "EMA 50", color=color.aqua, linewidth=2)
plot(showEMA ? emaSlow : na, "EMA 200", color=color.orange, linewidth=2)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// BUY / SELL VOLUME ESTIMATION
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
// Candle-direction volume approximation.
// This is not exchange-provided bid/ask delta.
 
buyVolume = close > open ? volume : close == open ? volume * 0.5 : 0.0
sellVolume = close < open ? volume : close == open ? volume * 0.5 : 0.0
 
totalVolume = buyVolume + sellVolume
 
buyPercent = totalVolume > 0 ? buyVolume / totalVolume * 100 : 0
sellPercent = totalVolume > 0 ? sellVolume / totalVolume * 100 : 0
 
volumeDelta = buyVolume - sellVolume
deltaPercent = totalVolume > 0 ? volumeDelta / totalVolume * 100 : 0
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// VOLUME IMBALANCE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
bullImbalance = buyPercent >= imbalanceThreshold
bearImbalance = sellPercent >= imbalanceThreshold
 
averageVolume = ta.sma(volume, volLength)
volumeSpike = not na(averageVolume) and volume > averageVolume * spikeMultiplier
 
bullStrong = bullImbalance and volumeSpike
bearStrong = bearImbalance and volumeSpike
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ABSORPTION DETECTION
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
candleRange = high - low
upperWick = high - math.max(open, close)
lowerWick = math.min(open, close) - low
 
upperWickPercent = candleRange > 0 ? upperWick / candleRange * 100 : 0
lowerWickPercent = candleRange > 0 ? lowerWick / candleRange * 100 : 0
 
bullAbsorption = volumeSpike and lowerWickPercent >= 50 and close > low + candleRange * 0.5
bearAbsorption = volumeSpike and upperWickPercent >= 50 and close < high - candleRange * 0.5
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SIGNAL ENGINE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
bullTrendFilter = not useEMA or bullTrend
bearTrendFilter = not useEMA or bearTrend
 
buySignal = bullStrong and bullTrendFilter and close > open and barstate.isconfirmed
sellSignal = bearStrong and bearTrendFilter and close < open and barstate.isconfirmed
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// IMBALANCE ZONES
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
var box[] bullZones = array.new_box()
var box[] bearZones = array.new_box()
 
if showZones and bullStrong and barstate.isconfirmed
    newBullZone = box.new(bar_index, high, bar_index + zoneLength, low, bgcolor=color.new(color.lime, 87), border_color=color.new(color.lime, 40))
    array.push(bullZones, newBullZone)
 
    if array.size(bullZones) > maxZones
        box.delete(array.shift(bullZones))
 
if showZones and bearStrong and barstate.isconfirmed
    newBearZone = box.new(bar_index, high, bar_index + zoneLength, low, bgcolor=color.new(color.red, 87), border_color=color.new(color.red, 40))
    array.push(bearZones, newBearZone)
 
    if array.size(bearZones) > maxZones
        box.delete(array.shift(bearZones))
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// BUY / SELL SIGNAL DISPLAY
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
plotshape(showSignals and buySignal, title="BUY", style=shape.labelup, location=location.belowbar, color=color.lime, text="BUY", textcolor=color.black, size=size.small)
 
plotshape(showSignals and sellSignal, title="SELL", style=shape.labeldown, location=location.abovebar, color=color.red, text="SELL", textcolor=color.white, size=size.small)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ABSORPTION LABELS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
plotshape(showAbsorption and bullAbsorption and barstate.isconfirmed, title="Bullish Absorption", style=shape.diamond, location=location.belowbar, color=color.aqua, text="ABS", textcolor=color.aqua, size=size.tiny)
 
plotshape(showAbsorption and bearAbsorption and barstate.isconfirmed, title="Bearish Absorption", style=shape.diamond, location=location.abovebar, color=color.orange, text="ABS", textcolor=color.orange, size=size.tiny)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// VOLUME SPIKE DISPLAY
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
barcolor(showSpike and volumeSpike ? bullImbalance ? color.lime : bearImbalance ? color.red : color.orange : na)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// VOLUME MATRIX DASHBOARD
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
dashboardPos = dashboardPosition == "Top Right" ? position.top_right :
     dashboardPosition == "Top Left" ? position.top_left :
     dashboardPosition == "Bottom Right" ? position.bottom_right :
     position.bottom_left
 
var table matrix = table.new(dashboardPos, 2, 9, border_width=1)
 
if barstate.islast and showDashboard
 
    table.cell(matrix, 0, 0, "JPT VOLUME MATRIX", bgcolor=color.rgb(15, 25, 45), text_color=color.white)
    table.cell(matrix, 1, 0, "LIVE DATA", bgcolor=color.rgb(15, 25, 45), text_color=color.aqua)
 
    table.cell(matrix, 0, 1, "BUY VOLUME")
    table.cell(matrix, 1, 1, str.tostring(buyPercent, "#.0") + "%", bgcolor=color.new(color.green, 35), text_color=color.white)
 
    table.cell(matrix, 0, 2, "SELL VOLUME")
    table.cell(matrix, 1, 2, str.tostring(sellPercent, "#.0") + "%", bgcolor=color.new(color.red, 35), text_color=color.white)
 
    table.cell(matrix, 0, 3, "VOLUME DELTA")
    table.cell(matrix, 1, 3, str.tostring(deltaPercent, "#.0") + "%", bgcolor=volumeDelta >= 0 ? color.green : color.red, text_color=color.white)
 
    table.cell(matrix, 0, 4, "IMBALANCE")
    table.cell(matrix, 1, 4, bullImbalance ? "BUY PRESSURE" : bearImbalance ? "SELL PRESSURE" : "BALANCED", bgcolor=bullImbalance ? color.green : bearImbalance ? color.red : color.gray, text_color=color.white)
 
    table.cell(matrix, 0, 5, "VOLUME STATUS")
    table.cell(matrix, 1, 5, volumeSpike ? "HIGH VOLUME" : "NORMAL", bgcolor=volumeSpike ? color.orange : color.gray, text_color=color.white)
 
    table.cell(matrix, 0, 6, "EMA TREND")
    table.cell(matrix, 1, 6, bullTrend ? "BULLISH" : bearTrend ? "BEARISH" : "NEUTRAL", bgcolor=bullTrend ? color.green : bearTrend ? color.red : color.gray, text_color=color.white)
 
    table.cell(matrix, 0, 7, "ABSORPTION")
    table.cell(matrix, 1, 7, bullAbsorption ? "BULLISH" : bearAbsorption ? "BEARISH" : "NONE", bgcolor=bullAbsorption ? color.green : bearAbsorption ? color.red : color.gray, text_color=color.white)
 
    table.cell(matrix, 0, 8, "MARKET BIAS")
    table.cell(matrix, 1, 8, buySignal ? "BUY" : sellSignal ? "SELL" : "WAIT", bgcolor=buySignal ? color.green : sellSignal ? color.red : color.gray, text_color=color.white)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ALERT CONDITIONS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
alertcondition(buySignal, "JPT Bullish Volume Imbalance", "Bullish Volume Imbalance detected")
alertcondition(sellSignal, "JPT Bearish Volume Imbalance", "Bearish Volume Imbalance detected")
 
alertcondition(bullAbsorption and barstate.isconfirmed, "JPT Bullish Absorption", "Potential Bullish Absorption detected")
alertcondition(bearAbsorption and barstate.isconfirmed, "JPT Bearish Absorption", "Potential Bearish Absorption detected")
 
alertcondition(volumeSpike and barstate.isconfirmed, "JPT Volume Spike", "Unusual Volume Spike detected")

← 返回列表