Strong Pressure Radar [Thomas]

Thomas-Sterling · study · 388 行 · 点赞 219 · 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/
// © Thomas-Sterling
 
 
 //@version=6
indicator("Strong Pressure Radar [Thomas]", overlay=true, max_lines_count=50, max_labels_count=50, max_boxes_count=20)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 01. INPUT SETTINGS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
gPressure = "Pressure Engine"
lookback = input.int(20, "Pressure Lookback", minval=5, group=gPressure)
volumeLength = input.int(20, "Volume Average", minval=1, group=gPressure)
pressureThreshold = input.float(65, "Minimum Pressure Score", minval=1, maxval=100, group=gPressure)
useVolume = input.bool(true, "Use Volume Confirmation", group=gPressure)
 
gTrend = "Trend & Momentum"
fastLength = input.int(21, "Fast EMA", minval=1, group=gTrend)
slowLength = input.int(50, "Slow EMA", minval=1, group=gTrend)
trendLength = input.int(200, "Main Trend EMA", minval=1, group=gTrend)
rsiLength = input.int(14, "RSI Length", minval=1, group=gTrend)
 
gStructure = "Market Structure"
swingLength = input.int(5, "Swing Length", minval=2, group=gStructure)
showStructure = input.bool(true, "Show BOS / CHoCH", group=gStructure)
showLevels = input.bool(true, "Show Support / Resistance", group=gStructure)
 
gSession = "Session Range"
showSession = input.bool(true, "Show Session High / Low", group=gSession)
sessionTime = input.session("0700-1600", "Session", group=gSession)
sessionTimezone = input.string("Etc/UTC", "Session Timezone", options=["Etc/UTC", "Asia/Karachi", "Europe/London", "America/New_York"], group=gSession)
 
gRisk = "Automatic Trade Levels"
showTargets = input.bool(true, "Show Entry / SL / TP", group=gRisk)
atrLength = input.int(14, "ATR Length", minval=1, group=gRisk)
slMultiplier = input.float(1.5, "Stop Loss ATR", minval=0.1, step=0.1, group=gRisk)
tp1RR = input.float(1.0, "TP1 Risk Reward", minval=0.1, step=0.1, group=gRisk)
tp2RR = input.float(2.0, "TP2 Risk Reward", minval=0.1, step=0.1, group=gRisk)
tp3RR = input.float(3.0, "TP3 Risk Reward", minval=0.1, step=0.1, group=gRisk)
targetBars = input.int(25, "Target Line Length", minval=5, group=gRisk)
 
gSignal = "Signal Controls"
cooldown = input.int(10, "Signal Cooldown", minval=0, group=gSignal)
showSignals = input.bool(true, "Show BUY / SELL", group=gSignal)
showClusters = input.bool(true, "Show Pressure Clusters", group=gSignal)
 
gDisplay = "Dashboard & Display"
showDashboard = input.bool(true, "Show Dashboard", group=gDisplay)
showEMAs = input.bool(true, "Show EMAs", group=gDisplay)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 02. CORE CALCULATIONS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
atr = ta.atr(atrLength)
emaFast = ta.ema(close, fastLength)
emaSlow = ta.ema(close, slowLength)
emaTrend = ta.ema(close, trendLength)
rsiValue = ta.rsi(close, rsiLength)
 
plot(showEMAs ? emaFast : na, "Fast EMA", color=color.aqua)
plot(showEMAs ? emaSlow : na, "Slow EMA", color=color.orange)
plot(showEMAs ? emaTrend : na, "Main Trend EMA", color=color.new(color.blue, 10), linewidth=2)
 
candleRange = math.max(high - low, syminfo.mintick)
body = math.abs(close - open)
bodyRatio = body / candleRange
 
upperWick = high - math.max(open, close)
lowerWick = math.min(open, close) - low
 
bullCandle = close > open
bearCandle = close < open
 
bullRejection = lowerWick / candleRange
bearRejection = upperWick / candleRange
 
volumeAverage = ta.sma(volume, volumeLength)
relativeVolume = not na(volumeAverage) and volumeAverage > 0 ? volume / volumeAverage : 1.0
volumeActive = relativeVolume >= 1.2
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 03. PRESSURE SCORE ENGINE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
// Each component contributes a maximum of 20 points.
 
bullTrendScore = close > emaTrend and emaFast > emaSlow ? 20.0 : close > emaFast ? 10.0 : 0.0
bearTrendScore = close < emaTrend and emaFast < emaSlow ? 20.0 : close < emaFast ? 10.0 : 0.0
 
bullCandleScore = bullCandle ? bodyRatio * 20 : 0.0
bearCandleScore = bearCandle ? bodyRatio * 20 : 0.0
 
bullVolumeScore = useVolume ? math.min(relativeVolume / 2.0, 1.0) * (bullCandle ? 20 : 0) : (bullCandle ? 10 : 0)
bearVolumeScore = useVolume ? math.min(relativeVolume / 2.0, 1.0) * (bearCandle ? 20 : 0) : (bearCandle ? 10 : 0)
 
bullMomentumScore = rsiValue > 55 ? 20.0 : rsiValue > 50 ? 10.0 : 0.0
bearMomentumScore = rsiValue < 45 ? 20.0 : rsiValue < 50 ? 10.0 : 0.0
 
bullStructureScore = close > ta.highest(high[1], lookback) ? 20.0 : close > emaFast and bullCandle ? 10.0 : 0.0
bearStructureScore = close < ta.lowest(low[1], lookback) ? 20.0 : close < emaFast and bearCandle ? 10.0 : 0.0
 
bullPressure = math.min(100.0, bullTrendScore + bullCandleScore + bullVolumeScore + bullMomentumScore + bullStructureScore)
bearPressure = math.min(100.0, bearTrendScore + bearCandleScore + bearVolumeScore + bearMomentumScore + bearStructureScore)
 
pressureDifference = bullPressure - bearPressure
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 04. MARKET STATE & SIGNALS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
bullBias = bullPressure >= pressureThreshold and bullPressure > bearPressure
bearBias = bearPressure >= pressureThreshold and bearPressure > bullPressure
 
var int lastSignalBar = na
cooldownOK = na(lastSignalBar) or bar_index - lastSignalBar > cooldown
 
buySetup = bullBias and bullCandle and close > emaFast
sellSetup = bearBias and bearCandle and close < emaFast
 
buySignal = barstate.isconfirmed and buySetup and cooldownOK
sellSignal = barstate.isconfirmed and sellSetup and cooldownOK
 
if buySignal or sellSignal
    lastSignalBar := bar_index
 
plotshape(showSignals and buySignal, title="BUY", style=shape.labelup, location=location.belowbar, color=color.rgb(0, 210, 130), text="LONG", textcolor=color.black, size=size.small)
plotshape(showSignals and sellSignal, title="SELL", style=shape.labeldown, location=location.abovebar, color=color.rgb(235, 65, 75), text="SHORT", textcolor=color.white, size=size.small)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 05. PRESSURE CLUSTERS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
bullCluster = bullPressure >= pressureThreshold and bullPressure > bearPressure
bearCluster = bearPressure >= pressureThreshold and bearPressure > bullPressure
 
plotshape(showClusters and bullCluster and not buySignal, title="Bull Pressure Cluster", style=shape.circle, location=location.belowbar, color=color.new(color.lime, 55), size=size.tiny)
plotshape(showClusters and bearCluster and not sellSignal, title="Bear Pressure Cluster", style=shape.circle, location=location.abovebar, color=color.new(color.red, 55), size=size.tiny)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 06. MARKET STRUCTURE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
pivotHigh = ta.pivothigh(high, swingLength, swingLength)
pivotLow = ta.pivotlow(low, swingLength, swingLength)
 
var float lastHigh = na
var float lastLow = na
var int lastHighBar = na
var int lastLowBar = na
var bool highBroken = false
var bool lowBroken = false
var int structureTrend = 0
 
if not na(pivotHigh)
    lastHigh := pivotHigh
    lastHighBar := bar_index - swingLength
    highBroken := false
 
if not na(pivotLow)
    lastLow := pivotLow
    lastLowBar := bar_index - swingLength
    lowBroken := false
 
bullBreak = not na(lastHigh) and close > lastHigh and not highBroken
bearBreak = not na(lastLow) and close < lastLow and not lowBroken
 
bullCHoCH = bullBreak and structureTrend == -1
bearCHoCH = bearBreak and structureTrend == 1
 
bullBOS = bullBreak and structureTrend != -1
bearBOS = bearBreak and structureTrend != 1
 
if bullBreak
    if showStructure
        line.new(lastHighBar, lastHigh, bar_index, lastHigh, color=bullCHoCH ? color.aqua : color.lime, width=2)
        label.new(bar_index, lastHigh, bullCHoCH ? "CHoCH" : "BOS", style=label.style_label_down, color=bullCHoCH ? color.aqua : color.lime, textcolor=color.black, size=size.tiny)
    structureTrend := 1
    highBroken := true
 
if bearBreak
    if showStructure
        line.new(lastLowBar, lastLow, bar_index, lastLow, color=bearCHoCH ? color.orange : color.red, width=2)
        label.new(bar_index, lastLow, bearCHoCH ? "CHoCH" : "BOS", style=label.style_label_up, color=bearCHoCH ? color.orange : color.red, textcolor=color.white, size=size.tiny)
    structureTrend := -1
    lowBroken := true
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 07. SUPPORT & RESISTANCE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
var line supportLine = na
var line resistanceLine = na
 
if showLevels and not na(pivotLow)
    if not na(supportLine)
        line.delete(supportLine)
    supportLine := line.new(bar_index - swingLength, pivotLow, bar_index + 20, pivotLow, color=color.new(color.lime, 25), width=2)
 
if showLevels and not na(pivotHigh)
    if not na(resistanceLine)
        line.delete(resistanceLine)
    resistanceLine := line.new(bar_index - swingLength, pivotHigh, bar_index + 20, pivotHigh, color=color.new(color.red, 25), width=2)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 08. SESSION RANGE
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
inSession = not na(time(timeframe.period, sessionTime, sessionTimezone))
sessionStart = inSession and not inSession[1]
sessionEnd = not inSession and inSession[1]
 
var float sessionHigh = na
var float sessionLow = na
var float previousSessionHigh = na
var float previousSessionLow = na
 
if sessionStart
    sessionHigh := high
    sessionLow := low
 
if inSession
    sessionHigh := na(sessionHigh) ? high : math.max(sessionHigh, high)
    sessionLow := na(sessionLow) ? low : math.min(sessionLow, low)
 
if sessionEnd
    previousSessionHigh := sessionHigh
    previousSessionLow := sessionLow
 
plot(showSession ? previousSessionHigh : na, "Previous Session High", color=color.new(color.fuchsia, 25), style=plot.style_linebr)
plot(showSession ? previousSessionLow : na, "Previous Session Low", color=color.new(color.teal, 25), style=plot.style_linebr)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 09. LIVE SETUP QUALITY
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
setupQuality = math.max(bullPressure, bearPressure)
setupDirection = bullPressure > bearPressure ? 1 : bearPressure > bullPressure ? -1 : 0
 
extensionATR = atr > 0 ? math.abs(close - emaFast) / atr : 0.0
exhaustion = rsiValue > 70 or rsiValue < 30
rejectionPercent = math.max(bullRejection, bearRejection) * 100
 
calmRegime = atr < ta.sma(atr, 20) * 0.8
rangeValue = not na(previousSessionHigh) and not na(previousSessionLow) ? previousSessionHigh - previousSessionLow : na
 
statusText = buySignal ? "LONG" : sellSignal ? "SHORT" : bullBias ? "BULLISH BIAS" : bearBias ? "BEARISH BIAS" : "WAIT"
burstText = extensionATR > 1.5 ? "EXTENDED" : volumeActive ? "ACTIVE" : "NORMAL"
trendText = close > emaTrend ? "BULLISH" : close < emaTrend ? "BEARISH" : "NEUTRAL"
pressureText = bullPressure > bearPressure ? "BUYERS" : bearPressure > bullPressure ? "SELLERS" : "BALANCED"
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 10. AUTOMATIC ENTRY & TARGETS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
var line entryLine = na
var line stopLine = na
var line target1Line = na
var line target2Line = na
var line target3Line = na
 
var label entryLabel = na
var label stopLabel = na
var label target1Label = na
var label target2Label = na
var label target3Label = na
 
var float activeEntry = na
var float activeStop = na
var float activeTP1 = na
var float activeTP2 = na
var float activeTP3 = na
var string activeDirection = "—"
 
if (buySignal or sellSignal) and showTargets
    if not na(entryLine)
        line.delete(entryLine)
        line.delete(stopLine)
        line.delete(target1Line)
        line.delete(target2Line)
        line.delete(target3Line)
        label.delete(entryLabel)
        label.delete(stopLabel)
        label.delete(target1Label)
        label.delete(target2Label)
        label.delete(target3Label)
 
    isLong = buySignal
    activeEntry := close
    risk = math.max(atr * slMultiplier, syminfo.mintick)
 
    activeStop := isLong ? activeEntry - risk : activeEntry + risk
    activeTP1 := isLong ? activeEntry + risk * tp1RR : activeEntry - risk * tp1RR
    activeTP2 := isLong ? activeEntry + risk * tp2RR : activeEntry - risk * tp2RR
    activeTP3 := isLong ? activeEntry + risk * tp3RR : activeEntry - risk * tp3RR
    activeDirection := isLong ? "LONG" : "SHORT"
 
    entryLine := line.new(bar_index, activeEntry, bar_index + targetBars, activeEntry, color=color.blue, width=2)
    stopLine := line.new(bar_index, activeStop, bar_index + targetBars, activeStop, color=color.red, width=2)
    target1Line := line.new(bar_index, activeTP1, bar_index + targetBars, activeTP1, color=color.lime, width=2)
    target2Line := line.new(bar_index, activeTP2, bar_index + targetBars, activeTP2, color=color.lime, width=2)
    target3Line := line.new(bar_index, activeTP3, bar_index + targetBars, activeTP3, color=color.lime, width=2)
 
    entryLabel := label.new(bar_index + targetBars, activeEntry, "ENTRY " + str.tostring(activeEntry, format.mintick), style=label.style_label_left, color=color.blue, textcolor=color.white)
    stopLabel := label.new(bar_index + targetBars, activeStop, "SL " + str.tostring(activeStop, format.mintick), style=label.style_label_left, color=color.red, textcolor=color.white)
    target1Label := label.new(bar_index + targetBars, activeTP1, "TP1 " + str.tostring(activeTP1, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.white)
    target2Label := label.new(bar_index + targetBars, activeTP2, "TP2 " + str.tostring(activeTP2, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.white)
    target3Label := label.new(bar_index + targetBars, activeTP3, "TP3 " + str.tostring(activeTP3, format.mintick), style=label.style_label_left, color=color.green, textcolor=color.white)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 11. DASHBOARD
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
var table dash = table.new(position.top_right, 3, 15, border_width=1)
 
if barstate.islast and showDashboard
    table.cell(dash, 0, 0, "THOMAS", bgcolor=color.rgb(20, 25, 35), text_color=color.white)
    table.cell(dash, 1, 0, "STRONG PRESSURE", bgcolor=color.rgb(20, 25, 35), text_color=color.aqua)
    table.cell(dash, 2, 0, syminfo.ticker, bgcolor=color.rgb(20, 25, 35), text_color=color.white)
 
    table.cell(dash, 0, 1, "STATUS", text_color=color.white)
    table.cell(dash, 1, 1, statusText, text_color=buySignal ? color.lime : sellSignal ? color.red : color.yellow)
    table.cell(dash, 2, 1, activeDirection, text_color=color.white)
 
    table.cell(dash, 0, 2, "BURST STATE", text_color=color.white)
    table.cell(dash, 1, 2, burstText, text_color=color.yellow)
    table.cell(dash, 2, 2, str.tostring(extensionATR, "#.##") + " ATR", text_color=color.white)
 
    table.cell(dash, 0, 3, "LAST SIGNAL", text_color=color.white)
    table.cell(dash, 1, 3, activeDirection, text_color=color.aqua)
    table.cell(dash, 2, 3, str.tostring(setupQuality, "#") + "/100", text_color=color.white)
 
    table.cell(dash, 0, 4, "PRESSURE", bgcolor=color.rgb(30, 35, 45), text_color=color.white)
    table.cell(dash, 1, 4, pressureText, bgcolor=color.rgb(30, 35, 45), text_color=color.aqua)
    table.cell(dash, 2, 4, str.tostring(pressureDifference, "#.0"), bgcolor=color.rgb(30, 35, 45), text_color=color.white)
 
    table.cell(dash, 0, 5, "BUY PRESSURE", text_color=color.white)
    table.cell(dash, 1, 5, str.tostring(bullPressure, "#") + "%", text_color=color.lime)
    table.cell(dash, 2, 5, "SCORE", text_color=color.gray)
 
    table.cell(dash, 0, 6, "SELL PRESSURE", text_color=color.white)
    table.cell(dash, 1, 6, str.tostring(bearPressure, "#") + "%", text_color=color.red)
    table.cell(dash, 2, 6, "SCORE", text_color=color.gray)
 
    table.cell(dash, 0, 7, "TREND FIT", text_color=color.white)
    table.cell(dash, 1, 7, trendText, text_color=color.yellow)
    table.cell(dash, 2, 7, str.tostring(rsiValue, "#.0") + " RSI", text_color=color.white)
 
    table.cell(dash, 0, 8, "EXHAUSTION", text_color=color.white)
    table.cell(dash, 1, 8, exhaustion ? "HIGH" : "NORMAL", text_color=exhaustion ? color.orange : color.lime)
    table.cell(dash, 2, 8, str.tostring(rsiValue, "#.0"), text_color=color.white)
 
    table.cell(dash, 0, 9, "REJECTION", text_color=color.white)
    table.cell(dash, 1, 9, str.tostring(rejectionPercent, "#.0") + "%", text_color=color.orange)
    table.cell(dash, 2, 9, "WICK", text_color=color.gray)
 
    table.cell(dash, 0, 10, "CALM REGIME", text_color=color.white)
    table.cell(dash, 1, 10, calmRegime ? "YES" : "NO", text_color=calmRegime ? color.orange : color.lime)
    table.cell(dash, 2, 10, str.tostring(atr, format.mintick), text_color=color.white)
 
    table.cell(dash, 0, 11, "SESSION RANGE", text_color=color.white)
    table.cell(dash, 1, 11, na(rangeValue) ? "NOT SET" : "READY", text_color=color.aqua)
    table.cell(dash, 2, 11, na(rangeValue) ? "—" : str.tostring(rangeValue, format.mintick), text_color=color.white)
 
    table.cell(dash, 0, 12, "ACTIVE ENTRY", text_color=color.white)
    table.cell(dash, 1, 12, na(activeEntry) ? "—" : str.tostring(activeEntry, format.mintick), text_color=color.aqua)
    table.cell(dash, 2, 12, activeDirection, text_color=color.white)
 
    table.cell(dash, 0, 13, "STOP LOSS", text_color=color.white)
    table.cell(dash, 1, 13, na(activeStop) ? "—" : str.tostring(activeStop, format.mintick), text_color=color.red)
    table.cell(dash, 2, 13, "ATR", text_color=color.gray)
 
    table.cell(dash, 0, 14, "SETUP SCORE", text_color=color.white)
    table.cell(dash, 1, 14, str.tostring(setupQuality, "#.0") + "/100", text_color=color.yellow)
    table.cell(dash, 2, 14, "ESTIMATE", text_color=color.gray)
 
if barstate.islast and not showDashboard
    table.clear(dash, 0, 0, 2, 14)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
// 12. ALERTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
 
alertcondition(buySignal, title="Thomas Long Signal", message="Strong Pressure Radar LONG | {{ticker}} | {{close}}")
alertcondition(sellSignal, title="Thomas Short Signal", message="Strong Pressure Radar SHORT | {{ticker}} | {{close}}")
alertcondition(bullBreak, title="Bullish Structure Break", message="Bullish BOS or CHoCH on {{ticker}}")
alertcondition(bearBreak, title="Bearish Structure Break", message="Bearish BOS or CHoCH on {{ticker}}")

← 返回列表