本页源码来自 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/
// © SchizoQuant
//@version=6
indicator("Auction Range Migration Trend", overlay=true)
// USER INPUTS
string atrTip = "ATR lookback used to normalize candle-range migration across different market volatility levels."
string centerTip = "Controls the influence of whole-candle range migration compared with closing-price movement."
string territoryTip = "Additional directional influence when a candle closes beyond the previous candle's high or low."
string shockTip = "Maximum influence of a single candle's normalized price movement. Prevents extreme candles from dominating the trend model."
string driveTip = "Smoothing period for directional range migration. Lower values respond faster, while higher values emphasize sustained movement."
string persistenceTip = "Lookback used to measure how consistently range migration favors the same direction."
string voteTip = "Minimum normalized price migration required to count as a meaningful bullish or bearish directional observation."
string influenceTip = "Controls how strongly repeated directional observations influence the trend relative to the magnitude of range migration."
string thresholdTip = "Base opposing directional score required to reverse the persistent LONG or SHORT regime."
string overlapTip = "Smoothing period for measuring how extensively consecutive candle ranges overlap."
string protectionTip = "Additional reversal confirmation required when overlapping candle ranges indicate indecisive price behavior."
string pathTip = "Displays an overlap-adjusted auction path for visualizing how trading ranges migrate. It does not independently determine trend direction."
string signalsTip = "Displays confirmed LONG and SHORT triangles when the persistent trend regime reverses."
string barsTip = "Colors price candles according to the confirmed bullish or bearish trend."
string colorTip = "Choose the bullish and bearish colors used for the auction path, signals, and candles."
int atrLength = input.int(title="ATR Length", defval=14, minval=1, group="Range Settings", tooltip=atrTip)
float centerInfluence = input.float(title="Range Center Influence", defval=0.35, minval=0.0, maxval=1.0, step=0.05, group="Range Settings", tooltip=centerTip)
float territoryInfluence = input.float(title="New Territory Influence", defval=0.45, minval=0.0, maxval=2.0, step=0.05, group="Range Settings", tooltip=territoryTip)
float shockLimit = input.float(title="Maximum Candle Impact", defval=2.0, minval=0.5, maxval=5.0, step=0.25, group="Range Settings", tooltip=shockTip)
int driveLength = input.int(title="Migration Smoothing", defval=20, minval=1, group="Trend Settings", tooltip=driveTip)
int persistenceLength = input.int(title="Directional Persistence", defval=13, minval=2, group="Trend Settings", tooltip=persistenceTip)
float minimumMigration = input.float(title="Meaningful Migration (ATR)", defval=0.03, minval=0.0, maxval=1.0, step=0.01, group="Trend Settings", tooltip=voteTip)
float persistenceInfluence = input.float(title="Persistence Influence", defval=0.40, minval=0.0, maxval=1.0, step=0.05, group="Trend Settings", tooltip=influenceTip)
float reversalThreshold = input.float(title="Reversal Threshold", defval=0.19, minval=0.01, maxval=1.0, step=0.01, group="Adaptive Settings", tooltip=thresholdTip)
int overlapLength = input.int(title="Range Overlap Length", defval=2, minval=2, group="Adaptive Settings", tooltip=overlapTip)
float overlapProtection = input.float(title="Overlap Protection", defval=0.25, minval=0.0, maxval=1.0, step=0.05, group="Adaptive Settings", tooltip=protectionTip)
bool showPath = input.bool(title="Show Auction Path", defval=true, group="Visualization", tooltip=pathTip)
bool showSignals = input.bool(title="Show Signals", defval=true, group="Visualization", tooltip=signalsTip)
bool colorBars = input.bool(title="Color Bars", defval=true, group="Visualization", tooltip=barsTip)
color longColor = input.color(title="Bullish Color", defval=color.rgb(57, 255, 20), group="Color Settings", inline="COL1", tooltip=colorTip)
color shortColor = input.color(title="Bearish Color", defval=color.rgb(138, 43, 226), group="Color Settings", inline="COL1", tooltip=colorTip)
// CALCULATIONS
float atrValue = ta.atr(atrLength)
float safeATR = math.max(nz(atrValue, high - low), syminfo.mintick)
float rangeCenter = (high + low) * 0.5
float previousCenter = nz(rangeCenter[1], rangeCenter)
float centerMovement = (rangeCenter - previousCenter) / safeATR
float closingMovement = (close - nz(close[1], close)) / safeATR
float directionalMigration = centerMovement * centerInfluence + closingMovement * (1.0 - centerInfluence)
float previousHigh = nz(high[1], high)
float previousLow = nz(low[1], low)
float overlapHigh = math.min(high, previousHigh)
float overlapLow = math.max(low, previousLow)
float overlapDistance = math.max(overlapHigh - overlapLow, 0.0)
float currentRange = math.max(high - low, syminfo.mintick)
float previousRange = math.max(previousHigh - previousLow, syminfo.mintick)
float overlapRatio = math.min(overlapDistance / math.max(currentRange, previousRange), 1.0)
float rangeExpansion = 1.0 - overlapRatio
float bullishTerritory = close > previousHigh ? math.min((close - previousHigh) / safeATR, 1.0) : 0.0
float bearishTerritory = close < previousLow ? math.min((previousLow - close) / safeATR, 1.0) : 0.0
float acceptedTerritory = bullishTerritory - bearishTerritory
float migrationExpansion = 1.0 + rangeExpansion * 0.50
float rawDrive = directionalMigration * migrationExpansion + acceptedTerritory * territoryInfluence
float auctionDrive = math.max(-shockLimit, math.min(shockLimit, rawDrive))
float migrationPressure = ta.ema(auctionDrive, driveLength)
float directionalVote = auctionDrive > minimumMigration ? 1.0 : auctionDrive < -minimumMigration ? -1.0 : 0.0
float directionalPersistence = ta.ema(directionalVote, persistenceLength)
float trendScore = migrationPressure * (1.0 - persistenceInfluence) + directionalPersistence * persistenceInfluence
float averageOverlap = ta.ema(overlapRatio, overlapLength)
float congestion = math.max(0.0, (averageOverlap - 0.30) / 0.70)
float adaptiveThreshold = reversalThreshold + congestion * overlapProtection
bool bullishEvidence = trendScore > adaptiveThreshold
bool bearishEvidence = trendScore < -adaptiveThreshold
float pathSpeed = 0.12 + 0.38 * rangeExpansion
var float auctionPath = na
auctionPath := na(auctionPath[1]) ? rangeCenter : auctionPath[1] + pathSpeed * (rangeCenter - auctionPath[1])
int warmup = math.max(atrLength, math.max(driveLength, math.max(persistenceLength, overlapLength)))
bool ready = bar_index >= warmup and not na(atrValue) and not na(trendScore)
// SIGNALS
var int SQ = 0
bool longSignal = false
bool shortSignal = false
if barstate.isconfirmed and ready
if SQ == 0
SQ := trendScore >= 0.0 ? 1 : -1
else if SQ == -1 and bullishEvidence
SQ := 1
longSignal := true
else if SQ == 1 and bearishEvidence
SQ := -1
shortSignal := true
// COLORS
color col = SQ == 1 ? longColor : SQ == -1 ? shortColor : color.gray
color colors = colorBars and SQ != 0 ? col : na
color pathColor = color.new(col, 0)
// PLOTS
plot(showPath and ready ? auctionPath : na, title="Auction Migration Path", color=pathColor, linewidth=3)
plot(centerMovement, title="Range Center Movement", display=display.data_window)
plot(closingMovement, title="Closing Price Movement", display=display.data_window)
plot(directionalMigration, title="Directional Range Migration", display=display.data_window)
plot(overlapRatio, title="Current Range Overlap", display=display.data_window)
plot(averageOverlap, title="Average Range Overlap", display=display.data_window)
plot(rangeExpansion, title="Range Expansion", display=display.data_window)
plot(acceptedTerritory, title="New Territory Acceptance", display=display.data_window)
plot(auctionDrive, title="Auction Directional Drive", display=display.data_window)
plot(migrationPressure, title="Migration Pressure", display=display.data_window)
plot(directionalPersistence, title="Directional Persistence", display=display.data_window)
plot(trendScore, title="Auction Trend Score", display=display.data_window)
plot(congestion, title="Market Congestion", display=display.data_window)
plot(adaptiveThreshold, title="Adaptive Reversal Threshold", display=display.data_window)
plot(float(SQ), title="Trend State", display=display.data_window)
plotshape(showSignals and longSignal, title="Long Signal", style=shape.triangleup, location=location.belowbar, size=size.small, color=longColor, text="LONG", textcolor=color.white, force_overlay=true)
plotshape(showSignals and shortSignal, title="Short Signal", style=shape.triangledown, location=location.abovebar, size=size.small, color=shortColor, text="SHORT", textcolor=color.white, force_overlay=true)
barcolor(colors, title = "Color Bars")
plotcandle(open, high, low, close, "Color Bars", colors, colors, bordercolor = colors, force_overlay = true)
// ALERTS
alertcondition(longSignal, title="Long Signal", message="Auction Range Migration Trend LONG on {{ticker}}")
alertcondition(shortSignal, title="Short Signal", message="Auction Range Migration Trend SHORT on {{ticker}}")