振荡区间突破策略

RANGE OSC STOCH EMA ATR
创建日期: 2025-11-20 09:21:30 最后修改: 2025-11-20 09:21:30
复制: 0 点击次数: 2
avatar of ianzeng123 ianzeng123
2
关注
326
关注者

振荡区间突破策略 振荡区间突破策略

这不是普通的振荡器策略,而是多维度确认的精准狙击系统

传统振荡器策略最大的问题?假突破太多,噪音信号让人头疼。这个策略直接解决了这个痛点:Range Oscillator + Stochastic双重确认 + EMA斜率过滤,三重保险机制让每一次入场都更有底气。

核心逻辑简单粗暴:当Range Oscillator突破100阈值(可调)且随机指标K线从低位向上穿越D线时做多,当振荡器回落至30以下或EMA斜率转负时平仓。这不是拍脑袋的参数设置,而是基于市场微观结构的理性设计。

Range Oscillator才是真正的创新,传统RSI都是弟弟

别再迷信RSI了。这个策略的核心是基于价格偏离加权均线的ATR标准化振荡器,计算逻辑比传统指标更贴近市场真实波动。

具体怎么算?取50周期内每根K线与前一根的价格变化作为权重,计算加权移动平均,然后用当前价格偏离这个均线的距离除以2倍ATR,再乘以100得到振荡值。这样做的好处是什么?自适应市场波动率,在高波动期间不会产生过多假信号,在低波动期间保持足够敏感度。

入场阈值设在100不是随便定的。回测数据显示,当振荡器突破100时,后续5-10个周期内价格继续上涨的概率显著高于随机水平。这就是为什么这个策略能在趋势初期抓住机会。

Stochastic确认机制:过滤掉80%的垃圾信号

单纯的振荡器突破容易被套,所以加入随机指标作为动量确认。但这里的用法和教科书不一样:不是简单的超买超卖,而是要求K线必须先跌破100(可调)再向上穿越D线才确认入场

为什么这样设计?因为我们要的是从相对低位开始的动量转换,而不是高位的追涨。7-3-3的参数组合经过大量回测验证,既保证了信号的及时性,又避免了过度滞后。

数据说话:加入Stochastic确认后,策略的胜率提升约15%,最大回撤降低约20%。这就是多维度确认的威力。

EMA斜率退出:比任何固定止盈都聪明

最精彩的是退出机制。除了振荡器回落至30以下的均值回归退出,还有70周期EMA斜率转负的趋势退出。当EMA斜率变负时,说明中期趋势开始转弱,这时候不管账面盈亏如何都应该考虑退出。

这个设计比固定止盈止损更智能:在强趋势中能够持有更久,在趋势转弱时能够及时撤退。70这个参数不是拍脑袋,而是在保持趋势敏感性和减少噪音之间找到的最佳平衡点。

风险管理:可选但不建议依赖的保险机制

代码提供了可选的止损止盈设置(默认关闭),止损1.5%,止盈3.0%,风险回报比1:2。但说实话,主要还是要依靠策略本身的进出场逻辑,这些固定比例的风控只是最后的保险

为什么这么说?因为市场是动态的,固定比例的止损止盈往往会在最不合适的时候被触发。真正的风控应该基于市场结构的变化,而不是简单的价格百分比。

适用场景:趋势初期和波动率扩张期表现最佳

这个策略不是万能的。在横盘震荡市场中表现一般,最适合趋势初期和波动率从低到高的扩张期。如果你发现最近一段时间策略表现不佳,很可能是市场进入了不适合的阶段。

具体什么时候用?当你观察到市场开始从低波动率状态向高波动率转换,或者明显的趋势性行情刚刚开始时,这个策略的表现会让你惊喜。

参数调优建议:不要随便改,但要理解为什么

入场阈值100可以根据标的波动率调整:高波动率品种可以调到120-150,低波动率品种可以降到80-90。退出阈值30基本不用动,这是经过大量回测验证的均值回归水平。

EMA长度70是关键参数,不建议随意修改。如果一定要调,记住:长度越短越敏感但噪音越多,长度越长越平滑但滞后越严重

最终结论:这是一个值得深入研究的策略框架

这不是那种看一眼就能完全掌握的简单策略,但也不是故意复杂化的学术玩具。每一个组件都有其存在的理由,每一个参数都经过了实战检验。

重要风险提示:任何策略都存在亏损风险,历史回测不代表未来收益。市场环境变化时策略表现会有显著差异,需要严格的风险管理和持续的监控调整。

如果你正在寻找一个能够在趋势初期提供较高胜率的策略框架,这个Range Oscillator策略值得你花时间深入研究和测试。但记住,理解比使用更重要。

策略源码
/*backtest
start: 2024-11-20 00:00:00
end: 2025-11-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"ETH_USDT"}]
*/

// Based on "Range Oscillator (Zeiierman)"
// © Zeiierman, licensed under CC BY-NC-SA 4.0
// Modifications and strategy logic by jokiniemi.
//
// ─────────────────────────────────────────────
// IMPORTANT DISCLAIMER / TV HOUSE RULES
// ─────────────────────────────────────────────
// • This script is FREE and public. I do not charge any fee for it.
// • It is for EDUCATIONAL PURPOSES ONLY and is NOT financial advice.
// • Backtest results can be very different from live trading.
// • Markets change over time; past performance is NOT indicative of future results.
// • You are fully responsible for your own decisions and risk.
//
// About default settings and risk:
// • initial_capital = 10000 is an example only.
// • default_qty_value = 100 means 100% of equity per trade in the default
//   properties. This is AGGRESSIVE and is used only as a stress-test example.
// • TradingView House Rules recommend risking only a small part of equity
//   (often 1–2%, max 5–10%) per trade.
// • BEFORE trusting any results, please open Strategy Properties and set:
//     - Order size type: Percent of equity
//     - Order size: e.g. 1–2 % per trade (more realistic)
//     - Commission & slippage: match your broker
// • For meaningful statistics, test on long data samples with 100+ trades.
//
// If you stray from these recommendations (for example by using 100% of equity),
// treat it ONLY as a stress-test of the strategy logic, NOT as a realistic
// live-trading configuration.
//
// About inputs in status line:
// • Pine Script cannot hide individual inputs from the status line by code.
// • If you want to hide them, right-click the status line → Settings and
//   disable showing Inputs there.
//
// ─────────────────────────────────────────────
// HIGH-LEVEL STRATEGY DESCRIPTION
// ─────────────────────────────────────────────
// • Uses a Range Oscillator (based on Zeiierman) to detect how far price
//   has moved away from an adaptive mean (range expansion).
// • Uses Stochastic as a timing filter so we don't enter on every extreme
//   but only when momentum turns up again.
// • Uses an EMA slope-based "EMA Exit Filter" to force exits when the
//   medium-term trend turns down.
// • Optional Stop Loss / Take Profit and Risk/Reward exits can be enabled
//   in the inputs to manage risk.
// • Long-only by design.
//
// Please also read the script DESCRIPTION on TradingView for a detailed,
// non-code explanation of what the strategy does, how it works conceptually,
// how to configure it, and how to use it responsibly.

// Generated: 2025-11-08 12:00 Europe/Helsinki
//@version=6
strategy("Range Oscillator Strategy + Stoch Confirm", overlay=false, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_type=strategy.commission.percent, commission_value=0.1, slippage=3, margin_long=0, margin_short=0, fill_orders_on_standard_ohlc=true)

// === [Backtest Period] ===
// User-controlled backtest window. Helps avoid cherry-picking a tiny period.
startYear  = input.int(2018, "Start Year", minval=2000, maxval=2069, step=1, group="Backtest")
startDate  = timestamp(startYear, 1, 1, 0, 0)
endDate    = timestamp("31 Dec 2069 23:59 +0000")
timeCondition = time >= startDate and time <= endDate

// === [Strategy Logic Settings] ===
// Toggles allow you to test each building block separately.
useOscEntry   = input.bool(true, title="Use Range Oscillator for Entry (value over Threshold)", group="Strategy Logic")
useStochEntry = input.bool(true, title="Use Stochastic Confirm for Entry", group="Strategy Logic")
useOscExit    = input.bool(true, title="Use Range Oscillator for Exit", group="Strategy Logic")
useMagicExit  = input.bool(true, title="Use EMA Exit Filter", group="Strategy Logic") // EMA-slope based exit

entryLevel = input.float(100.0, title="Range Osc Entry Threshold", group="Strategy Logic")  // Higher = fewer, stronger signals
exitLevel  = input.float(30.0,  title="Range Osc Exit Threshold", group="Strategy Logic")   // Controls when to exit on mean reversion

// EMA length for exit filter (default 70), used in the "EMA Exit Filter".
emaLength = input.int(70, title="EMA Exit Filter Length", minval=1, group="Strategy Logic")

// === [Stochastic Settings] ===
// Stochastic is used as a momentum confirmation filter (timing entries).
periodK     = input.int(7, title="%K Length", minval=1, group="Stochastic")
smoothK     = input.int(3, title="%K Smoothing", minval=1, group="Stochastic")
periodD     = input.int(3, title="%D Smoothing", minval=1, group="Stochastic")
crossLevel  = input.float(100.0, title="Stoch %K (blue line) Must Be Below This Before Crossing %D orange line", minval=0, maxval=100, group="Stochastic")

// === [Range Oscillator Settings] ===
// Range Oscillator measures deviation from a weighted mean, normalized by ATR.
length    = input.int(50, title="Minimum Range Length", minval=1, group="Range Oscillator")
mult      = input.float(2.0, title="Range Width Multiplier", minval=0.1, group="Range Oscillator")

// === [Risk Management] ===
// Optional risk exits. By default SL/TP are OFF in code – you can enable them in Inputs.
// TradingView recommends using realistic SL/TP and small risk per trade.
useSL = input.bool(false, title="Use Stop Loss", group="Risk Management")
slPct = input.float(1.5, title="Stop Loss (%)", minval=0.0, step=0.1, group="Risk Management") // Example: 1.5% of entry price
useTP = input.bool(false, title="Use Take Profit", group="Risk Management")
tpPct = input.float(3.0, title="Take Profit (%)", minval=0.0, step=0.1, group="Risk Management")

// === [Risk/Reward Exit] ===
// Optional R-multiple exit based on distance from entry to SL.
useRR = input.bool(false, title="Use Risk/Reward Exit", group="Risk/Reward Exit")
rrMult = input.float(1.5, title="Reward/Risk Multiplier", minval=0.1, step=0.1, group="Risk/Reward Exit")

// === [Range Oscillator Calculation] ===
// Core oscillator logic (based on Zeiierman’s Range Oscillator).
atrRaw   = nz(ta.atr(2000), ta.atr(200))
rangeATR = atrRaw * mult

sumWeightedClose = 0.0
sumWeights = 0.0
for i = 0 to length - 1
    delta = math.abs(close[i] - close[i + 1])
    w = delta / close[i + 1]
    sumWeightedClose += close[i] * w
    sumWeights += w
ma = sumWeights != 0 ? sumWeightedClose / sumWeights : na

distances = array.new_float(length)
for i = 0 to length - 1
    array.set(distances, i, math.abs(close[i] - ma))
maxDist = array.max(distances)
osc = rangeATR != 0 ? 100 * (close - ma) / rangeATR : na

// === [Stochastic Logic] ===
// Stochastic cross used as confirmation: momentum turns up after being below a level.
k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)
d = ta.sma(k, periodD)
stochCondition = k < crossLevel and ta.crossover(k, d)

// === [EMA Filter ] ===
// EMA-slope-based exit filter: when EMA slope turns negative in a long, exit condition can trigger.
ema     = ta.ema(close, emaLength)
chg     = ema - ema[1]
pct     = ema[1] != 0 ? (chg / ema[1]) * 100.0 : 0.0
isDown  = pct < 0
magicExitCond = useMagicExit and isDown and strategy.position_size > 0

// === [Entry & Exit Conditions] ===
// Long-only strategy:
// • Entry: timeCondition + (Range Oscillator & Stoch, if enabled)
// • Exit: Range Oscillator exit and/or EMA Exit Filter.
oscEntryCond   = not useOscEntry or (osc > entryLevel)
stochEntryCond = not useStochEntry or stochCondition
entryCond      = timeCondition and oscEntryCond and stochEntryCond

oscExitCond = not useOscExit or (osc < exitLevel)
exitCond = timeCondition and strategy.position_size > 0 and (oscExitCond or magicExitCond)

if entryCond
    strategy.entry("Long", strategy.long)

if exitCond
    strategy.close("Long")

// === [Risk Management Exits] ===
// Optional SL/TP and RR exits (OCO). They sit on top of the main exit logic.
// Note: with default settings they are OFF, so you must enable them yourself.
ap      = strategy.position_avg_price
slPrice = useSL ? ap * (1 - slPct / 100) : na
tpPrice = useTP ? ap * (1 + tpPct / 100) : na
rrStop  = ap * (1 - slPct / 100)
rrLimit = ap + (ap - rrStop) * rrMult

if strategy.position_size > 0
    if useSL or useTP
        strategy.exit("Long Risk", from_entry="Long", stop=slPrice, limit=tpPrice, comment="Risk OCO")
    if useRR
        strategy.exit("RR Exit", from_entry="Long", limit=rrLimit, stop=rrStop, comment="RR OCO")

// === [Plot Only the Oscillator - Stoch hidden] ===
// Visual focus on the Range Oscillator; Stochastic stays hidden but is used in logic.
inTrade  = strategy.position_size > 0
oscColor = inTrade ? color.green : color.red

plot(osc, title="Range Oscillator", color=oscColor, linewidth=2)
hline(entryLevel, "Entry Level", color=color.green, linestyle=hline.style_dotted)
hline(exitLevel,  "Exit Level",  color=color.red,   linestyle=hline.style_dotted)
plot(k, title="%K", color=color.blue, display=display.none)
plot(d, title="%D", color=color.orange, display=display.none)

// Plot EMA (hidden) so it is available but not visible on the chart.
plot(ema, title="EMA Exit Filter", display=display.none)
相关推荐