本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// 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("MMC - Liquidity Hunt Area [JPT]", shorttitle="MMC Hunt [JPT]", overlay=true, max_boxes_count=100, max_labels_count=100)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SETTINGS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
groupLiquidity = "Liquidity Hunt Settings"
pivotLength = input.int(25, "Pivot Length", minval=2, group=groupLiquidity)
atrLength = input.int(14, "ATR Length", minval=1, group=groupLiquidity)
zoneAtrMult = input.float(0.25, "Zone Thickness (ATR)", minval=0.05, step=0.05, group=groupLiquidity)
showBuySide = input.bool(true, "Show Buy-Side Liquidity", group=groupLiquidity)
showSellSide = input.bool(true, "Show Sell-Side Liquidity", group=groupLiquidity)
extendZones = input.bool(false, "Extend Active Zones", group=groupLiquidity)
maxZones = input.int(10, "Maximum Zones Per Side", minval=1, maxval=30, group=groupLiquidity)
groupStyle = "Style"
buyColor = input.color( color.red, "Buy-Side Liquidity", group=groupStyle)
sellColor = input.color(color.lime, "Sell-Side Liquidity", group=groupStyle)
zoneTransp = input.int(85, "Zone Transparency", minval=0, maxval=100, group=groupStyle)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// CALCULATIONS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
atr = ta.atr(atrLength)
zoneSize = atr * zoneAtrMult
pivotHigh = ta.pivothigh(high, pivotLength, pivotLength)
pivotLow = ta.pivotlow(low, pivotLength, pivotLength)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// LIQUIDITY STORAGE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var highLevels = array.new_float()
var lowLevels = array.new_float()
var highBoxes = array.new_box()
var lowBoxes = array.new_box()
var highActive = array.new_bool()
var lowActive = array.new_bool()
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// REGISTER BUY-SIDE LIQUIDITY
// Previous swing highs = potential buy stops
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
if not na(pivotHigh)
level = pivotHigh
array.push(highLevels, level)
array.push(highActive, true)
if showBuySide
bx = box.new(left=bar_index - pivotLength, top=level + zoneSize[pivotLength], right=bar_index, bottom=level - zoneSize[pivotLength], xloc=xloc.bar_index, extend=extendZones ? extend.right : extend.none, border_color=color.new(buyColor, 35), bgcolor=color.new(buyColor, zoneTransp))
array.push(highBoxes, bx)
if array.size(highLevels) > maxZones
array.shift(highLevels)
array.shift(highActive)
if array.size(highBoxes) > 0
oldBox = array.shift(highBoxes)
box.delete(oldBox)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// REGISTER SELL-SIDE LIQUIDITY
// Previous swing lows = potential sell stops
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
if not na(pivotLow)
level = pivotLow
array.push(lowLevels, level)
array.push(lowActive, true)
if showSellSide
bx = box.new(left=bar_index - pivotLength, top=level + zoneSize[pivotLength], right=bar_index, bottom=level - zoneSize[pivotLength], xloc=xloc.bar_index, extend=extendZones ? extend.right : extend.none, border_color=color.new(sellColor, 35), bgcolor=color.new(sellColor, zoneTransp))
array.push(lowBoxes, bx)
if array.size(lowLevels) > maxZones
array.shift(lowLevels)
array.shift(lowActive)
if array.size(lowBoxes) > 0
oldBox = array.shift(lowBoxes)
box.delete(oldBox)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// LIQUIDITY HUNT DETECTION
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
bool buySideHunt = false
bool sellSideHunt = false
if array.size(highLevels) > 0
for i = 0 to array.size(highLevels) - 1
level = array.get(highLevels, i)
active = array.get(highActive, i)
// Price sweeps above a swing high and closes back below
if active and high > level and close < level
buySideHunt := true
array.set(highActive, i, false)
if array.size(highBoxes) > i
bx = array.get(highBoxes, i)
box.set_extend(bx, extend.none)
box.set_right(bx, bar_index)
box.set_border_color(bx, buyColor)
box.set_bgcolor(bx, color.new(buyColor, 75))
if showBuySide
label.new(bar_index, high, "MMC BUY-SIDE HUNT", style=label.style_label_down, color=buyColor, textcolor=color.white, size=size.tiny)
if array.size(lowLevels) > 0
for i = 0 to array.size(lowLevels) - 1
level = array.get(lowLevels, i)
active = array.get(lowActive, i)
// Price sweeps below a swing low and closes back above
if active and low < level and close > level
sellSideHunt := true
array.set(lowActive, i, false)
if array.size(lowBoxes) > i
bx = array.get(lowBoxes, i)
box.set_extend(bx, extend.none)
box.set_right(bx, bar_index)
box.set_border_color(bx, sellColor)
box.set_bgcolor(bx, color.new(sellColor, 75))
if showSellSide
label.new(bar_index, low, "MMC SELL-SIDE HUNT", style=label.style_label_up, color=sellColor, textcolor=color.black, size=size.tiny)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ALERTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
alertcondition(buySideHunt, title="MMC Buy-Side Liquidity Hunt", message="MMC: Price swept a previous swing high and closed back below it.")
alertcondition(sellSideHunt, title="MMC Sell-Side Liquidity Hunt", message="MMC: Price swept a previous swing low and closed back above it.")