本页源码来自 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/
// © Thomas-Sterling
//@version=6
indicator("Pressure Flow Pro [Thomas]", overlay=true, max_lines_count=20, max_labels_count=30)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SETTINGS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
fastLen = input.int(21, "Fast EMA", minval=1)
slowLen = input.int(50, "Slow EMA", minval=2)
swingLen = input.int(20, "Liquidity Lookback", minval=5)
volLen = input.int(20, "Volume Average", minval=1)
volMult = input.float(1.0, "Relative Volume Filter", minval=0.1, step=0.1)
atrLen = input.int(14, "ATR Length", minval=1)
minBody = input.float(0.45, "Minimum Candle Body Ratio", minval=0.1, maxval=1.0, step=0.05)
cooldown = input.int(8, "Signal Cooldown (bars)", minval=0)
rr1 = input.float(1.0, "Target 1 (R)", minval=0.25, step=0.25)
rr2 = input.float(2.0, "Target 2 (R)", minval=0.5, step=0.25)
extendBars = input.int(20, "Level Label Distance", minval=5, maxval=100)
showEMAs = input.bool(true, "Show Trend EMAs")
showSweeps = input.bool(true, "Mark Liquidity Sweeps")
showPanel = input.bool(true, "Show Dashboard")
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// CORE CALCULATIONS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
fastEMA = ta.ema(close, fastLen)
slowEMA = ta.ema(close, slowLen)
atr = ta.atr(atrLen)
volAvg = ta.sma(volume, volLen)
barRange = math.max(high - low, syminfo.mintick)
bodyRatio = math.abs(close - open) / barRange
bullTrend = fastEMA > slowEMA and close > fastEMA
bearTrend = fastEMA < slowEMA and close < fastEMA
volumeOK = na(volume) or na(volAvg) or volume >= volAvg * volMult
bullPressure = close > open and bodyRatio >= minBody
bearPressure = close < open and bodyRatio >= minBody
priorHigh = ta.highest(high[1], swingLen)
priorLow = ta.lowest(low[1], swingLen)
sweepLow = low < priorLow and close > priorLow
sweepHigh = high > priorHigh and close < priorHigh
breakUp = close > priorHigh
breakDown = close < priorLow
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// SELECTIVE SIGNAL LOGIC
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
longSetup = (breakUp or sweepLow) and bullTrend and bullPressure and volumeOK
shortSetup = (breakDown or sweepHigh) and bearTrend and bearPressure and volumeOK
var int lastSignalBar = na
cooldownOK = na(lastSignalBar) or bar_index - lastSignalBar > cooldown
buySignal = barstate.isconfirmed and longSetup and cooldownOK
sellSignal = barstate.isconfirmed and shortSetup and cooldownOK
if buySignal or sellSignal
lastSignalBar := bar_index
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// CHART VISUALS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
color bullColor = color.rgb(0, 220, 170)
color bearColor = color.rgb(220, 70, 120)
color fastColor = color.rgb(65, 170, 255)
color slowColor = color.rgb(175, 110, 255)
plot(showEMAs ? fastEMA : na, "Fast EMA", color=fastColor, linewidth=2)
plot(showEMAs ? slowEMA : na, "Slow EMA", color=slowColor, linewidth=2)
plotshape(buySignal, title="BUY Signal", style=shape.labelup,
location=location.belowbar, color=bullColor, text="BUY",
textcolor=color.black, size=size.small)
plotshape(sellSignal, title="SELL Signal", style=shape.labeldown,
location=location.abovebar, color=bearColor, text="SELL",
textcolor=color.white, size=size.small)
plotshape(showSweeps and sweepLow and barstate.isconfirmed,
title="Low Liquidity Sweep", style=shape.circle,
location=location.belowbar, color=color.aqua, size=size.tiny)
plotshape(showSweeps and sweepHigh and barstate.isconfirmed,
title="High Liquidity Sweep", style=shape.circle,
location=location.abovebar, color=color.fuchsia, size=size.tiny)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ENTRY AND TARGET LEVELS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var line entryLine = na
var line stopLine = na
var line tp1Line = na
var line tp2Line = na
var label entryLabel = na
var label stopLabel = na
var label tp1Label = na
var label tp2Label = na
if buySignal or sellSignal
if not na(entryLine)
line.delete(entryLine)
if not na(stopLine)
line.delete(stopLine)
if not na(tp1Line)
line.delete(tp1Line)
if not na(tp2Line)
line.delete(tp2Line)
if not na(entryLabel)
label.delete(entryLabel)
if not na(stopLabel)
label.delete(stopLabel)
if not na(tp1Label)
label.delete(tp1Label)
if not na(tp2Label)
label.delete(tp2Label)
float entryPrice = close
float stopPrice = buySignal ? math.min(low, close - atr * 1.2) : math.max(high, close + atr * 1.2)
float riskSize = math.max(math.abs(entryPrice - stopPrice), syminfo.mintick)
float tp1Price = buySignal ? entryPrice + riskSize * rr1 : entryPrice - riskSize * rr1
float tp2Price = buySignal ? entryPrice + riskSize * rr2 : entryPrice - riskSize * rr2
int endBar = bar_index + extendBars
color signalColor = buySignal ? bullColor : bearColor
entryLine := line.new(bar_index, entryPrice, endBar, entryPrice, color=color.white, width=2)
stopLine := line.new(bar_index, stopPrice, endBar, stopPrice, color=color.orange, width=2, style=line.style_dashed)
tp1Line := line.new(bar_index, tp1Price, endBar, tp1Price, color=signalColor, width=2)
tp2Line := line.new(bar_index, tp2Price, endBar, tp2Price, color=signalColor, width=2, style=line.style_dashed)
entryLabel := label.new(endBar, entryPrice, "ENTRY " + str.tostring(entryPrice, format.mintick), style=label.style_label_left, color=color.gray, textcolor=color.white)
stopLabel := label.new(endBar, stopPrice, "SL " + str.tostring(stopPrice, format.mintick), style=label.style_label_left, color=color.orange, textcolor=color.black)
tp1Label := label.new(endBar, tp1Price, "TP1 " + str.tostring(tp1Price, format.mintick), style=label.style_label_left, color=signalColor, textcolor=color.black)
tp2Label := label.new(endBar, tp2Price, "TP2 " + str.tostring(tp2Price, format.mintick), style=label.style_label_left, color=signalColor, textcolor=color.black)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// LIVE DASHBOARD
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var table panel = table.new(position.top_right, 2, 5, border_width=1, frame_color=color.new(color.gray, 55))
if barstate.islast and showPanel
string trendText = bullTrend ? "BULLISH" : bearTrend ? "BEARISH" : "NEUTRAL"
color trendColor = bullTrend ? bullColor : bearTrend ? bearColor : color.gray
string pressureText = bullPressure ? "BUY PRESSURE" : bearPressure ? "SELL PRESSURE" : "BALANCED"
string volumeText = volumeOK ? "PASS" : "LOW"
string liquidityText = sweepLow ? "LOW SWEEP" : sweepHigh ? "HIGH SWEEP" : "NONE"
string signalText = buySignal ? "BUY" : sellSignal ? "SELL" : "WAIT"
table.cell(panel, 0, 0, "THOMAS | PRESSURE FLOW", bgcolor=color.rgb(35, 35, 55), text_color=color.white)
table.cell(panel, 1, 0, "PRO", bgcolor=color.rgb(35, 35, 55), text_color=color.aqua)
table.cell(panel, 0, 1, "TREND", text_color=color.white, bgcolor=color.new(color.gray, 80))
table.cell(panel, 1, 1, trendText, text_color=trendColor)
table.cell(panel, 0, 2, "CANDLE PRESSURE", text_color=color.white, bgcolor=color.new(color.gray, 80))
table.cell(panel, 1, 2, pressureText, text_color=bullPressure ? bullColor : bearPressure ? bearColor : color.gray)
table.cell(panel, 0, 3, "VOLUME FILTER", text_color=color.white, bgcolor=color.new(color.gray, 80))
table.cell(panel, 1, 3, volumeText, text_color=volumeOK ? bullColor : bearColor)
table.cell(panel, 0, 4, "SWEEP / SIGNAL", text_color=color.white, bgcolor=color.new(color.gray, 80))
table.cell(panel, 1, 4, liquidityText + " / " + signalText, text_color=color.white)
if barstate.islast and not showPanel
table.clear(panel, 0, 0, 1, 4)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// ALERTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
alertcondition(buySignal, title="Pressure Flow BUY", message="Thomas Pressure Flow Pro: BUY signal on {{ticker}} at {{close}}")
alertcondition(sellSignal, title="Pressure Flow SELL", message="Thomas Pressure Flow Pro: SELL signal on {{ticker}} at {{close}}")
alertcondition(showSweeps and sweepLow and barstate.isconfirmed, title="Low Liquidity Sweep", message="Potential low-side liquidity sweep on {{ticker}}")
alertcondition(showSweeps and sweepHigh and barstate.isconfirmed, title="High Liquidity Sweep", message="Potential high-side liquidity sweep on {{ticker}}")