Big Player Manipulation Radar PRO v1.0

samc30 · study · 217 行 · 点赞 29 · TradingView 原页

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

Pine Script

//@version=6
indicator("Big Player Manipulation Radar PRO v1.0", shorttitle="BPM Radar PRO", overlay=true, max_lines_count=200, max_boxes_count=100, max_labels_count=100)
 
// === 1. LIQUIDITY LEVELS ===
gLiquidity = "1. Liquidity Levels"
pivotLeft   = input.int(5, "Pivot left bars", minval=2, maxval=30, group=gLiquidity)
pivotRight  = input.int(5, "Pivot right bars", minval=2, maxval=30, group=gLiquidity)
maxLevels   = input.int(15, "Levels per side", minval=3, maxval=50, group=gLiquidity)
minSweepATR = input.float(0.03, "Min penetration (ATR)", minval=0.0, maxval=2.0, step=0.01, group=gLiquidity)
minWickATR  = input.float(0.10, "Min rejection wick (ATR)", minval=0.0, maxval=2.0, step=0.05, group=gLiquidity)
 
// === 2. CONFIRMATION FILTERS ===
gConfirm = "2. Confirmation Filters"
structureBars = input.int(8, "MSS structure lookback", minval=2, maxval=50, group=gConfirm)
confirmBars   = input.int(8, "Max bars after sweep for MSS", minval=1, maxval=40, group=gConfirm)
useVolume     = input.bool(false, "Require relative volume on sweep", group=gConfirm)
volumeLen     = input.int(20, "Average volume length", minval=2, maxval=200, group=gConfirm)
minRelVolume  = input.float(1.5, "Minimum relative volume", minval=0.1, maxval=10.0, step=0.1, group=gConfirm)
useTrend      = input.bool(false, "Require EMA trend alignment", group=gConfirm)
fastLen       = input.int(50, "Fast EMA", minval=2, maxval=500, group=gConfirm)
slowLen       = input.int(200, "Slow EMA", minval=3, maxval=500, group=gConfirm)
requireFVG    = input.bool(false, "Require 3-candle FVG on MSS bar", group=gConfirm)
 
// === 3. RISK AND DISPLAY ===
gVisual = "3. Trade Levels and Display"
atrLen         = input.int(14, "ATR length", minval=2, maxval=100, group=gVisual)
stopPadATR     = input.float(0.15, "Stop padding (ATR)", minval=0.0, maxval=2.0, step=0.05, group=gVisual)
rewardRisk     = input.float(2.0, "Target reward:risk", minval=0.5, maxval=10.0, step=0.25, group=gVisual)
projectionBars = input.int(25, "Trade line length (bars)", minval=5, maxval=100, group=gVisual)
zoneBars       = input.int(12, "Manipulation zone length (bars)", minval=1, maxval=100, group=gVisual)
showEMAs       = input.bool(false, "Show trend EMAs", group=gVisual)
showDashboard  = input.bool(true, "Show dashboard", group=gVisual)
 
// All series-based calculations run on every bar.
atr = ta.atr(atrLen)
emaFast = ta.ema(close, fastLen)
emaSlow = ta.ema(close, slowLen)
volumeAverage = ta.sma(volume, volumeLen)
relativeVolume = not na(volumeAverage) and volumeAverage > 0 ? volume / volumeAverage : na
volumeOK = not useVolume or (not na(relativeVolume) and relativeVolume >= minRelVolume)
penetration = atr * minSweepATR
lowerWick = math.min(open, close) - low
upperWick = high - math.max(open, close)
priorStructureHigh = ta.highest(high, structureBars)[1]
priorStructureLow = ta.lowest(low, structureBars)[1]
bullFVG = bar_index >= 2 and low > high[2]
bearFVG = bar_index >= 2 and high < low[2]
 
// Active, confirmed swing levels. Consumed or broken levels are removed.
var array<float> bslPrices = array.new_float()
var array<line> bslLines = array.new_line()
var array<float> sslPrices = array.new_float()
var array<line> sslLines = array.new_line()
 
bool bullishSweep = false
bool bearishSweep = false
float bullishLevel = na
float bearishLevel = na
 
// Check established BSL levels (above swing highs).
if array.size(bslPrices) > 0
    for i = array.size(bslPrices) - 1 to 0
        float level = array.get(bslPrices, i)
        line levelLine = array.get(bslLines, i)
        line.set_x2(levelLine, bar_index)
        bool swept = barstate.isconfirmed and not na(atr) and high > level + penetration and close < level and upperWick >= atr * minWickATR and volumeOK
        bool broken = barstate.isconfirmed and close > level
        if swept or broken
            if swept and not bearishSweep
                bearishSweep := true
                bearishLevel := level
            line.delete(levelLine)
            array.remove(bslLines, i)
            array.remove(bslPrices, i)
 
// Check established SSL levels (below swing lows).
if array.size(sslPrices) > 0
    for i = array.size(sslPrices) - 1 to 0
        float level = array.get(sslPrices, i)
        line levelLine = array.get(sslLines, i)
        line.set_x2(levelLine, bar_index)
        bool swept = barstate.isconfirmed and not na(atr) and low < level - penetration and close > level and lowerWick >= atr * minWickATR and volumeOK
        bool broken = barstate.isconfirmed and close < level
        if swept or broken
            if swept and not bullishSweep
                bullishSweep := true
                bullishLevel := level
            line.delete(levelLine)
            array.remove(sslLines, i)
            array.remove(sslPrices, i)
 
// A single candle that sweeps both sides is ambiguous, so do not signal it.
if bullishSweep and bearishSweep
    bullishSweep := false
    bearishSweep := false
 
// New pivots become tradable levels only after their RIGHT-side confirmation.
confirmedHigh = ta.pivothigh(high, pivotLeft, pivotRight)
confirmedLow = ta.pivotlow(low, pivotLeft, pivotRight)
if barstate.isconfirmed
    if not na(confirmedHigh)
        line newBSL = line.new(bar_index - pivotRight, confirmedHigh, bar_index, confirmedHigh, color=color.new(color.red, 20), style=line.style_dashed, width=1)
        array.push(bslLines, newBSL)
        array.push(bslPrices, confirmedHigh)
        if array.size(bslPrices) > maxLevels
            line.delete(array.shift(bslLines))
            array.shift(bslPrices)
    if not na(confirmedLow)
        line newSSL = line.new(bar_index - pivotRight, confirmedLow, bar_index, confirmedLow, color=color.new(color.lime, 20), style=line.style_dashed, width=1)
        array.push(sslLines, newSSL)
        array.push(sslPrices, confirmedLow)
        if array.size(sslPrices) > maxLevels
            line.delete(array.shift(sslLines))
            array.shift(sslPrices)
 
// The setup is pending until price breaks the PRE-SWEEP structure threshold.
var int pendingDirection = 0
var int sweepBar = na
var float sweepExtreme = na
var float mssThreshold = na
 
if bullishSweep and not na(priorStructureHigh)
    pendingDirection := 1
    sweepBar := bar_index
    sweepExtreme := low
    mssThreshold := priorStructureHigh
    box.new(left=bar_index, top=bullishLevel, right=bar_index + zoneBars, bottom=low, bgcolor=color.new(color.lime, 85), border_color=color.new(color.lime, 35))
else if bearishSweep and not na(priorStructureLow)
    pendingDirection := -1
    sweepBar := bar_index
    sweepExtreme := high
    mssThreshold := priorStructureLow
    box.new(left=bar_index, top=high, right=bar_index + zoneBars, bottom=bearishLevel, bgcolor=color.new(color.red, 85), border_color=color.new(color.red, 35))
 
bool longSignal = false
bool shortSignal = false
 
if barstate.isconfirmed and pendingDirection != 0 and not na(sweepBar)
    int age = bar_index - sweepBar
    bool expired = age > confirmBars
    bool invalid = pendingDirection == 1 ? low < sweepExtreme : high > sweepExtreme
    if expired or invalid
        pendingDirection := 0
    else if age >= 1
        bool trendBullOK = not useTrend or emaFast > emaSlow
        bool trendBearOK = not useTrend or emaFast < emaSlow
        if pendingDirection == 1 and close > mssThreshold and trendBullOK and (not requireFVG or bullFVG)
            longSignal := true
            pendingDirection := 0
        else if pendingDirection == -1 and close < mssThreshold and trendBearOK and (not requireFVG or bearFVG)
            shortSignal := true
            pendingDirection := 0
 
// Most recent confirmed setup: entry at MSS close,
// ATR-padded stop and fixed risk-reward target.
var line entryLine = na
var line stopLine = na
var line targetLine = na
var label entryLabel = na
var label stopLabel = na
var label targetLabel = na
 
if longSignal or shortSignal
    if not na(entryLine)
        line.delete(entryLine)
        line.delete(stopLine)
        line.delete(targetLine)
        label.delete(entryLabel)
        label.delete(stopLabel)
        label.delete(targetLabel)
 
    float entryPrice = close
    float stopPrice = longSignal ? sweepExtreme - atr * stopPadATR : sweepExtreme + atr * stopPadATR
    float risk = math.abs(entryPrice - stopPrice)
    float targetPrice = longSignal ? entryPrice + risk * rewardRisk : entryPrice - risk * rewardRisk
 
    entryLine := line.new(bar_index, entryPrice, bar_index + projectionBars, entryPrice, color=color.yellow, width=2)
    stopLine := line.new(bar_index, stopPrice, bar_index + projectionBars, stopPrice, color=color.red, style=line.style_dotted, width=2)
    targetLine := line.new(bar_index, targetPrice, bar_index + projectionBars, targetPrice, color=color.lime, style=line.style_dotted, width=2)
 
    entryLabel := label.new(bar_index + projectionBars, entryPrice, "ENTRY " + str.tostring(entryPrice, format.mintick), color=color.yellow, textcolor=color.black, style=label.style_label_left, size=size.tiny)
    stopLabel := label.new(bar_index + projectionBars, stopPrice, "SL " + str.tostring(stopPrice, format.mintick), color=color.red, textcolor=color.white, style=label.style_label_left, size=size.tiny)
    targetLabel := label.new(bar_index + projectionBars, targetPrice, "TP " + str.tostring(targetPrice, format.mintick), color=color.lime, textcolor=color.black, style=label.style_label_left, size=size.tiny)
 
// On-chart event markers.
plotshape(bullishSweep, title="Bullish SSL Sweep", style=shape.labelup, location=location.belowbar, color=color.lime, text="SSL\nSWEEP", textcolor=color.black, size=size.tiny)
plotshape(bearishSweep, title="Bearish BSL Sweep", style=shape.labeldown, location=location.abovebar, color=color.red, text="BSL\nSWEEP", textcolor=color.white, size=size.tiny)
plotshape(longSignal, title="Bullish MSS Confirmed", style=shape.triangleup, location=location.belowbar, color=color.aqua, text="MSS LONG", textcolor=color.aqua, size=size.small)
plotshape(shortSignal, title="Bearish MSS Confirmed", style=shape.triangledown, location=location.abovebar, color=color.orange, text="MSS SHORT", textcolor=color.orange, size=size.small)
 
plot(showEMAs ? emaFast : na, title="Fast EMA", color=color.teal)
plot(showEMAs ? emaSlow : na, title="Slow EMA", color=color.purple)
 
// Dashboard
var table dashboard = table.new(position.top_right, 2, 5, bgcolor=color.new(color.black, 15), border_width=1)
 
if barstate.islast and showDashboard
    string bias = emaFast > emaSlow ? "Bullish" : emaFast < emaSlow ? "Bearish" : "Neutral"
    string status = pendingDirection == 1 ? "Awaiting bullish MSS" : pendingDirection == -1 ? "Awaiting bearish MSS" : "No pending setup"
    string volText = na(relativeVolume) ? "N/A" : str.tostring(relativeVolume, "#.##") + "x"
 
    table.cell(dashboard, 0, 0, "BPM RADAR PRO", text_color=color.white, bgcolor=color.new(color.blue, 55))
    table.cell(dashboard, 1, 0, "v1.0", text_color=color.white, bgcolor=color.new(color.blue, 55))
    table.cell(dashboard, 0, 1, "EMA bias", text_color=color.silver)
    table.cell(dashboard, 1, 1, bias, text_color=emaFast > emaSlow ? color.lime : emaFast < emaSlow ? color.red : color.silver)
    table.cell(dashboard, 0, 2, "Status", text_color=color.silver)
    table.cell(dashboard, 1, 2, status, text_color=color.white)
    table.cell(dashboard, 0, 3, "Relative volume", text_color=color.silver)
    table.cell(dashboard, 1, 3, volText, text_color=color.white)
    table.cell(dashboard, 0, 4, "Active BSL / SSL", text_color=color.silver)
    table.cell(dashboard, 1, 4, str.tostring(array.size(bslPrices)) + " / " + str.tostring(array.size(sslPrices)), text_color=color.white)
 
// TradingView Alerts
alertcondition(bullishSweep, title="BPM: Bullish Liquidity Sweep", message="Bullish SSL sweep on {{ticker}} ({{interval}}). Candle close: {{close}}")
alertcondition(bearishSweep, title="BPM: Bearish Liquidity Sweep", message="Bearish BSL sweep on {{ticker}} ({{interval}}). Candle close: {{close}}")
alertcondition(longSignal, title="BPM: Confirmed LONG", message="Bullish MSS after SSL sweep on {{ticker}} ({{interval}}). MSS close / planned entry: {{close}}")
alertcondition(shortSignal, title="BPM: Confirmed SHORT", message="Bearish MSS after BSL sweep on {{ticker}} ({{interval}}). MSS close / planned entry: {{close}}")

← 返回列表