该策略是一个结合了高斯通道(Gaussian Channel)和随机相对强弱指标(Stochastic RSI)的量化交易系统。策略通过监测价格与高斯通道的交叉以及随机RSI的走势来捕捉市场的趋势反转机会。高斯通道由移动平均线和标准差构建,能够动态地反映市场波动范围,而随机RSI则提供了动量方面的确认信号。
策略的核心逻辑包含以下几个关键部分: 1. 高斯通道的构建:使用20周期的指数移动平均(EMA)作为通道中轴线,通道上下边界则是中轴线加减2倍标准差得到。 2. 随机RSI的计算:首先计算14周期的RSI,然后对RSI值应用14周期的随机公式,最后对结果进行3周期的平滑处理得到K线和D线。 3. 交易信号生成:当价格突破高斯通道上轨且随机RSI的K线上穿D线时,产生做多信号;当价格跌破高斯通道上轨时,平仓出场。
该策略通过结合技术分析中的趋势跟踪和动量指标,构建了一个逻辑完整、风险可控的量化交易系统。虽然存在一些固有的风险,但通过持续优化和完善,策略有望在不同市场环境下保持稳定的表现。策略的模块化设计也为后续的优化和扩展提供了良好的基础。
/*backtest
start: 2024-02-21 00:00:00
end: 2025-02-18 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Binance","currency":"BNB_USDT"}]
*/
//@version=5
strategy("SAJJAD JAMSHIDI Channel with Stochastic RSI Strategy", overlay=true, commission_type=strategy.commission.percent, commission_value=0.1, slippage=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100, process_orders_on_close=true)
// Gaussian Channel Inputs
lengthGC = input.int(20, "Gaussian Channel Length", minval=1)
multiplier = input.float(2.0, "Standard Deviation Multiplier", minval=0.1)
// Calculate Gaussian Channel
basis = ta.ema(close, lengthGC)
deviation = multiplier * ta.stdev(close, lengthGC)
upperChannel = basis + deviation
lowerChannel = basis - deviation
// Plot Gaussian Channel
plot(basis, "Basis", color=color.blue)
plot(upperChannel, "Upper Channel", color=color.green)
plot(lowerChannel, "Lower Channel", color=color.red)
// Stochastic RSI Inputs
rsiLength = input.int(14, "RSI Length", minval=1)
stochLength = input.int(14, "Stochastic Length", minval=1)
smoothK = input.int(3, "Smooth K", minval=1)
smoothD = input.int(3, "Smooth D", minval=1)
// Calculate RSI
rsi = ta.rsi(close, rsiLength)
// Calculate Stochastic RSI
lowestRSI = ta.lowest(rsi, stochLength)
highestRSI = ta.highest(rsi, stochLength)
stochRSI = (rsi - lowestRSI) / (highestRSI - lowestRSI) * 100
k = ta.sma(stochRSI, smoothK)
d = ta.sma(k, smoothD)
// Trading Conditions
stochUp = k > d
priceAboveUpper = ta.crossover(close, upperChannel)
priceBelowUpper = ta.crossunder(close, upperChannel)
strategy.entry("Long", strategy.long, when=priceAboveUpper and stochUp)
strategy.close("Long", when=priceBelowUpper)