Aura Mean Reversion Envelopes [Pineify]

Pineify · study · 109 行 · 点赞 453 · 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/
// © Pineify
 
//@version=6
indicator("Aura Mean Reversion Envelopes [Pineify]", "Aura MRE [Pineify]", overlay=true, max_labels_count=500)
 
// ---------------------------------------------------------------------------------------------------------------------
// CONSTANTS & INPUTS
// ---------------------------------------------------------------------------------------------------------------------
// Group labels for the settings panel
var string G_CORE = "Core Settings"
var string G_BANDS = "Envelope Multipliers"
var string G_STYLE = "Aesthetics & Colors"
 
// Core parameters
// `length` — lookback window for the Hull Moving Average (HMA), which forms the central mean line.
//   Shorter values make the mean more responsive; longer values produce a smoother baseline.
length = input.int(34, "Mean Tracking Period", minval=1, group=G_CORE, tooltip="Length of the central moving average")
// `atrLen` — lookback window for the ATR calculation that measures market volatility.
//   This volatility value is used to dynamically size the envelope bands.
atrLen = input.int(21, "Volatility (ATR) Period", minval=1, group=G_CORE)
 
// Band Multipliers
// `innerMult` — ATR multiplier for the inner bands. Price within the inner bands is considered
//   "normal" territory. The default 1.618 (golden ratio) provides a statistically meaningful threshold.
innerMult = input.float(1.618, "Inner Band Multiplier", step=0.1, group=G_BANDS)
// `outerMult` — ATR multiplier for the outer (exhaustion) bands. Price reaching these levels
//   indicates extreme deviation from the mean, where reversals are more likely.
outerMult = input.float(3.0, "Outer Band (Exhaustion) Multiplier", step=0.1, group=G_BANDS)
 
// Colors
bullColor = input.color(#089981, "Bullish Reversal", group=G_STYLE)
bearColor = input.color(#F23645, "Bearish Reversal", group=G_STYLE)
meanColor = input.color(#2962FF, "Mean Baseline", group=G_STYLE)
// When enabled, candles that close beyond the inner bands are tinted to highlight extreme price action.
colorCandles = input.bool(true, "Color Candles at Extremes", group=G_STYLE)
 
 
// ---------------------------------------------------------------------------------------------------------------------
// CALCULATIONS
// ---------------------------------------------------------------------------------------------------------------------
// Central baseline: Hull Moving Average (HMA) — chosen for its superior smoothness and minimal lag
// compared to SMA/EMA, making it ideal for identifying the "fair value" mean.
mean = ta.hma(close, length)
 
// Volatility measure: Average True Range (ATR) — captures the average bar range over `atrLen` bars,
// providing a dynamic, adaptive measure of how far price typically moves.
volatility = ta.atr(atrLen)
 
// Envelope construction: four bands are built symmetrically around the mean.
// Outer bands = mean ± ATR × outerMult  → exhaustion / extreme zones
// Inner bands = mean ± ATR × innerMult  → normal deviation boundary
upperOuter = mean + volatility * outerMult
upperInner = mean + volatility * innerMult
lowerInner = mean - volatility * innerMult
lowerOuter = mean - volatility * outerMult
 
// ---------------------------------------------------------------------------------------------------------------------
// MEAN REVERSION SIGNALS
// ---------------------------------------------------------------------------------------------------------------------
// Bullish reversal: the bar's low pierces below the lower outer band (exhaustion zone),
// but the candle closes bullishly (close > open) AND above the outer band — a wick rejection pattern
// suggesting sellers failed to hold price at the extreme.
bullishReversal = low < lowerOuter and close > open and close > lowerOuter
 
// Bearish reversal: the bar's high pierces above the upper outer band,
// but the candle closes bearishly (close < open) AND below the outer band — a wick rejection pattern
// suggesting buyers failed to sustain the breakout.
bearishReversal = high > upperOuter and close < open and close < upperOuter
 
// ---------------------------------------------------------------------------------------------------------------------
// PLOTTING & VISUALS
// ---------------------------------------------------------------------------------------------------------------------
// Central mean line — the "fair value" reference that price tends to revert toward
p_mean = plot(mean, "Central Mean", color=meanColor, linewidth=2)
 
// Upper envelope lines: outer (solid) marks the exhaustion zone, inner (dashed) marks the normal boundary
p_upOut = plot(upperOuter, "Upper Outer Band", color=color.new(bearColor, 50), linestyle=plot.linestyle_solid)
p_upInn = plot(upperInner, "Upper Inner Band", color=color.new(bearColor, 50), linestyle=plot.linestyle_dashed)
 
// Lower envelope lines: same logic mirrored below the mean
p_lowInn = plot(lowerInner, "Lower Inner Band", color=color.new(bullColor, 50), linestyle=plot.linestyle_dashed)
p_lowOut = plot(lowerOuter, "Lower Outer Band", color=color.new(bullColor, 50), linestyle=plot.linestyle_solid)
 
// Cloud fills between bands to create visual "zones":
// - Outer-to-inner fills highlight the overbought/oversold exhaustion zones
// - Inner-to-mean fills show the neutral mean-reversion corridor
fill(p_upOut, p_upInn, color=color.new(bearColor, 85), title="Overbought / Sell Zone")
fill(p_lowOut, p_lowInn, color=color.new(bullColor, 85), title="Oversold / Buy Zone")
fill(p_upInn, p_mean, color=color.new(meanColor, 95), title="Upper Mean Zone")
fill(p_mean, p_lowInn, color=color.new(meanColor, 95), title="Lower Mean Zone")
 
// Triangle markers at reversal points: up-triangle below bar for bullish, down-triangle above bar for bearish
plotshape(bullishReversal, title="Buy Signal", style=shape.triangleup, location=location.belowbar, color=bullColor, size=size.small, text="BUY", textcolor=bullColor)
plotshape(bearishReversal, title="Sell Signal", style=shape.triangledown, location=location.abovebar, color=bearColor, size=size.small, text="SELL", textcolor=bearColor)
 
// Candle coloring: when enabled, candles closing above the upper inner band turn bearColor (overbought),
// and candles closing below the lower inner band turn bullColor (oversold), providing an at-a-glance
// visual cue for extreme price positioning relative to the envelopes.
barColor = colorCandles and close > upperInner ? bearColor : colorCandles and close < lowerInner ? bullColor : na
barcolor(barColor, title="Extreme Candle Colors")
 
// ---------------------------------------------------------------------------------------------------------------------
// ALERTS
// ---------------------------------------------------------------------------------------------------------------------
// Configurable alerts that fire when a reversal signal is detected, allowing traders to receive
// notifications without watching the chart.
alertcondition(bullishReversal, title="Bullish Mean Reversion", message="Price rejected the lower exhaustion band. Potential LONG entry.")
alertcondition(bearishReversal, title="Bearish Mean Reversion", message="Price rejected the upper exhaustion band. Potential SHORT entry.")

← 返回列表