本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Pineify
//======================================================================//
// ____ _ _ __ //
// | _ \(_)_ __ ___(_)/ _|_ _ //
// | |_) | | '_ \ / _ \ | |_| | | | //
// | __/| | | | | __/ | _| |_| | //
// |_| |_|_| |_|\___|_|_| \__, | //
// |___/ //
//======================================================================//
//
// Luminous Mean Reversion Channels
// ---------------------------------
// A volatility-stepped mean reversion overlay inspired by Predictive
// Ranges. The center line only moves when price has displaced by a full
// ATR-based threshold, so small fluctuations are ignored while larger
// range shifts recalibrate the channel.
//
// Three practical states are highlighted:
// 1. Upper stretch — price is near or crossing back from the overbought band
// 2. Mean zone — price is rotating around the stepped central level
// 3. Lower stretch — price is near or crossing back from the oversold band
//@version=6
indicator("Luminous Mean Reversion Channels [Pineify]", shorttitle="Luminous MRC [Pineify]", overlay=true)
//---------------------------------------------------------------------------------------------------------------------}
// INPUT SETTINGS
//---------------------------------------------------------------------------------------------------------------------{
grp_channel = "Channel Settings"
length = input.int(200, "Volatility Length", minval=2, group=grp_channel, tooltip="ATR lookback used to size the displacement threshold. Higher values smooth the channel response; lower values react faster.")
mult = input.float(6.0, "Channel Width Factor", minval=0, step=0.5, group=grp_channel, tooltip="ATR multiplier that controls how far price must move before the mean level recalibrates. Higher values create wider channels and fewer signals.")
src = input.source(close, "Source", group=grp_channel, tooltip="Price series used for the stepped mean calculation and band-crossing signals.")
//---------------------------------------------------------------------------------------------------------------------}
// CORE LOGIC: VOLATILITY-STEPPED MEAN REVERSION CHANNEL
//---------------------------------------------------------------------------------------------------------------------{
var float avg_line = src
var float hold_atr = 0.0
// The ATR threshold defines what counts as a meaningful displacement.
// Small moves inside this threshold leave the central level unchanged.
atr_val = nz(ta.atr(length)) * mult
// [Source: Predictive Ranges concept]
// The central level advances in fixed volatility steps instead of tracking
// every candle. This makes the range less reactive to ordinary market noise.
avg_line := src - avg_line > atr_val ? avg_line + atr_val : avg_line - src > atr_val ? avg_line - atr_val : avg_line
// Capture the active width only when the center line changes. This keeps the
// displayed channel tied to the volatility regime that caused the recalibration.
hold_atr := avg_line != avg_line[1] ? atr_val / 2 : hold_atr
upper_band = avg_line + hold_atr * 2
lower_band = avg_line - hold_atr * 2
//---------------------------------------------------------------------------------------------------------------------}
// PLOTTING & AESTHETICS
//---------------------------------------------------------------------------------------------------------------------{
up_plot = plot(upper_band, color=color.new(#f23645, 0), title="Overbought Band", linewidth=2)
mid_plot = plot(avg_line, color=color.new(#787b86, 50), title="Mean Reversion Level", style=plot.style_line, linewidth=1)
dn_plot = plot(lower_band, color=color.new(#089981, 0), title="Oversold Band", linewidth=2)
// Fills emphasize where price is stretched relative to the stepped mean:
// red above the center for upside extension, green below for downside extension.
fill(up_plot, mid_plot, top_color=color.new(#f23645, 85), bottom_color=color.new(#f23645, 100), title="Bearish Reversal Aura")
fill(dn_plot, mid_plot, top_color=color.new(#089981, 100), bottom_color=color.new(#089981, 85), title="Bullish Reversal Aura")
//---------------------------------------------------------------------------------------------------------------------}
// SIGNALS
//---------------------------------------------------------------------------------------------------------------------{
// Reversal labels fire when price crosses back through an outer band. The
// condition looks for re-entry from an extended area, not a trend-following break.
buy_signal = ta.crossover(src, lower_band)
sell_signal = ta.crossunder(src, upper_band)
plotshape(buy_signal, title="Buy Signal", style=shape.labelup, location=location.belowbar, color=color.new(#089981, 0), text="BUY", textcolor=color.white, size=size.small)
plotshape(sell_signal, title="Sell Signal", style=shape.labeldown, location=location.abovebar, color=color.new(#f23645, 0), text="SELL", textcolor=color.white, size=size.small)
alertcondition(buy_signal, title="Bullish Mean Reversion", message="Price crossed back above the lower mean reversion band.")
alertcondition(sell_signal, title="Bearish Mean Reversion", message="Price crossed back below the upper mean reversion band.")