该策略是一个基于高斯通道(Gaussian Channel)和随机RSI指标(Stochastic RSI)的量化交易系统。策略通过结合技术分析中的均值回归和动量原理,在价格触及通道下轨且随机RSI指标显示超卖信号时进场做多,在价格触及通道上轨或随机RSI指标显示超买信号时平仓出场。该策略仅用于做多交易,不进行做空操作。
策略的核心逻辑基于以下几个关键计算: 1. 高斯通道的构建:使用EMA作为中轨,以标准差的2倍作为通道宽度计算上下轨。 2. 随机RSI的计算:首先计算14周期的RSI,然后在14个周期内计算RSI的最高值和最低值,最后算出当前RSI在这个范围内的相对位置。 3. 入场信号:价格突破通道下轨的同时,随机RSI指标从20以下向上突破。 4. 出场信号:价格突破通道上轨或随机RSI指标从80以上向下突破。
该策略通过结合高斯通道和随机RSI指标,构建了一个相对稳健的交易系统。策略的优势在于双重确认机制和完善的风险控制,但也需要注意应对不同市场环境的适应性问题。通过引入自适应参数和市场环境识别等优化方向,可以进一步提升策略的稳定性和盈利能力。
/*backtest
start: 2024-02-18 00:00:00
end: 2025-01-30 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Gaussian Channel with Stochastic RSI", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=200, commission_type=strategy.commission.percent, commission_value=0.1, slippage=0)
// Gaussian Channel Parameters
gc_length = input.int(20, "Gaussian Channel Length", minval=1)
gc_mult = input.float(2.0, "Gaussian Channel Multiplier", minval=0.1)
middle = ta.ema(close, gc_length)
stdev = ta.stdev(close, gc_length)
upper = middle + gc_mult * stdev
lower = middle - gc_mult * stdev
// Plot Channels
plot(middle, "Middle Line", color=color.blue)
plot(upper, "Upper Channel", color=color.red)
plot(lower, "Lower Channel", color=color.green)
// Stochastic RSI Parameters
rsi_length = input.int(14, "RSI Length", minval=1)
stoch_length = input.int(14, "Stochastic Length", minval=1)
smooth_k = input.int(3, "Smooth %K", minval=1)
oversold = input.int(20, "Oversold Level", minval=0, maxval=100)
overbought = input.int(80, "Overbought Level", minval=0, maxval=100)
// Calculate Stochastic RSI
rsi = ta.rsi(close, rsi_length)
lowest_rsi = ta.lowest(rsi, stoch_length)
highest_rsi = ta.highest(rsi, stoch_length)
stoch_rsi = highest_rsi != lowest_rsi ? (rsi - lowest_rsi) / (highest_rsi - lowest_rsi) * 100 : 0
k = ta.sma(stoch_rsi, smooth_k)
// Entry/Exit Conditions
enterLong = ta.crossover(close, lower) and ta.crossover(k, oversold)
exitLong = ta.crossover(close, upper) or ta.crossunder(k, overbought)
// Strategy Execution
if (time >= timestamp(2018, 01, 01, 0, 0) and time < timestamp(2069, 01, 01, 0, 0))
if enterLong
strategy.entry("Long", strategy.long)
if exitLong
strategy.close("Long")