Price Impact Efficiency [IEF]

IndicatorEliteFlow · study · 71 行 · 点赞 5 · 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/
// © IndicatorEliteFlow
 
//@version=6
indicator("Price Impact Efficiency [IEF]", shorttitle="PIE [IEF]", overlay=false, precision=2)
 
// This indicator measures the magnitude of price response relative to volume participation.
// It describes observable relationships only. It does not identify participant intent,
// predict reversals, or provide entry and exit signals.
 
string groupModel = "Model"
int baselineLength = input.int(30, "Prior baseline length", minval=20, group=groupModel)
int rankLength = input.int(100, "Percentile lookback", minval=30, group=groupModel)
int atrLength = input.int(14, "ATR length", minval=2, group=groupModel)
float volumeFloor = input.float(0.10, "Relative-volume floor", minval=0.01, maxval=1.00, step=0.01, group=groupModel,
     tooltip="Prevents very small volume readings from producing unstable ratios.")
bool confirmOnClose = input.bool(true, "Confirm values only after bar close", group=groupModel)
 
string groupDisplay = "Display"
bool showEnvelope = input.bool(true, "Show prior 10th-90th percentile envelope", group=groupDisplay)
bool showDashboard = input.bool(true, "Show compact readout", group=groupDisplay)
 
// Baselines use completed prior bars. The current observation cannot alter its own reference.
float priorVolumeMean = ta.sma(volume[1], baselineLength)
float priorAtr = ta.atr(atrLength)[1]
float relativeVolume = priorVolumeMean > 0 and volume > 0 ? volume / priorVolumeMean : na
float normalizedMove = priorAtr > 0 ? math.abs(close - close[1]) / priorAtr : na
 
// log(1 + ratio) remains defined at zero price movement without an arbitrary negative spike.
float safeParticipation = math.max(relativeVolume, volumeFloor)
float rawEfficiency = normalizedMove / safeParticipation
float logEfficiency = math.log(1.0 + rawEfficiency)
 
// Standardization also uses only prior observations.
float priorEfficiencyMean = ta.sma(logEfficiency[1], baselineLength)
float priorEfficiencyDev = ta.stdev(logEfficiency[1], baselineLength)
float efficiencyScore = priorEfficiencyDev > 0 ? (logEfficiency - priorEfficiencyMean) / priorEfficiencyDev : not na(priorEfficiencyMean) ? 0.0 : na
float efficiencyPercentile = ta.percentrank(logEfficiency, rankLength)
 
bool enoughHistory = not na(efficiencyScore) and not na(relativeVolume)
bool valueReady = enoughHistory and (not confirmOnClose or barstate.isconfirmed)
float displayedScore = valueReady ? efficiencyScore : na
// The envelope uses prior scores only and describes the historical distribution.
float lowerEnvelope = ta.percentile_nearest_rank(efficiencyScore[1], rankLength, 10)
float upperEnvelope = ta.percentile_nearest_rank(efficiencyScore[1], rankLength, 90)
hline(0, "Baseline center", color=color.new(color.gray, 65), linestyle=hline.style_dotted)
upperPlot = plot(showEnvelope ? upperEnvelope : na, "Prior 90th percentile", color=color.new(color.blue, 55), linewidth=1)
lowerPlot = plot(showEnvelope ? lowerEnvelope : na, "Prior 10th percentile", color=color.new(color.blue, 55), linewidth=1)
fill(upperPlot, lowerPlot, color=color.new(color.blue, 92), title="Historical response envelope")
plot(displayedScore, "Price-impact efficiency z-score", style=plot.style_linebr, color=color.rgb(35, 130, 200), linewidth=2)
plot(valueReady and efficiencyScore > upperEnvelope ? efficiencyScore : na, "Above historical envelope", style=plot.style_circles, color=color.rgb(215, 145, 35), linewidth=3)
plot(valueReady and efficiencyScore < lowerEnvelope ? efficiencyScore : na, "Below historical envelope", style=plot.style_circles, color=color.rgb(150, 85, 185), linewidth=3)
 
bool unusuallyHighResponse = valueReady and efficiencyScore >= 1.5
bool unusuallyLowResponse = valueReady and efficiencyScore <= -1.5
alertcondition(unusuallyHighResponse, "Unusually high price response", "PIE: unusually high price response relative to volume on {{ticker}} {{interval}}")
alertcondition(unusuallyLowResponse, "Unusually low price response", "PIE: unusually low price response relative to volume on {{ticker}} {{interval}}")
 
var table dashboard = table.new(position.top_right, 2, 3, border_width=0)
if barstate.islast
    if showDashboard
        string state = not enoughHistory ? "Building history" : not barstate.isconfirmed and confirmOnClose ? "Developing" : efficiencyScore >= 1.5 ? "High response" : efficiencyScore <= -1.5 ? "Low response" : "Within baseline"
        color stateColor = efficiencyScore >= 1.5 ? color.teal : efficiencyScore <= -1.5 ? color.purple : color.gray
        table.cell(dashboard, 0, 0, "PIE", bgcolor=color.new(color.black, 10), text_color=color.white)
        table.cell(dashboard, 1, 0, state, bgcolor=color.new(stateColor, 15), text_color=color.white)
        table.cell(dashboard, 0, 1, "Efficiency z", text_color=chart.fg_color, bgcolor=chart.bg_color)
        table.cell(dashboard, 1, 1, valueReady ? str.tostring(efficiencyScore, "#.##") : "Pending", text_color=chart.fg_color, bgcolor=chart.bg_color)
        table.cell(dashboard, 0, 2, "Percentile", text_color=chart.fg_color, bgcolor=chart.bg_color)
        table.cell(dashboard, 1, 2, not valueReady ? "Pending" : na(efficiencyPercentile) ? "Building" : str.tostring(efficiencyPercentile, "#") + "%", text_color=chart.fg_color, bgcolor=chart.bg_color)
    else
        table.clear(dashboard, 0, 0, 1, 2)

← 返回列表