该策略是一个基于多重技术指标的动量趋势交易系统,通过结合相对强弱指标(RSI)、移动平均收敛散度指标(MACD)和随机指标(Stochastic)来识别市场的买卖信号。策略采用概率阈值方法,通过Z分数标准化处理来过滤交易信号,提高交易的可靠性。该策略特别适合日线级别的趋势跟踪交易。
策略主要基于三个核心技术指标: 1. RSI用于识别超买超卖区域,RSI<30视为超卖买入信号,RSI>70视为超买卖出信号 2. MACD通过分析快慢均线的交叉来判断动量变化,MACD线上穿信号线产生买入信号,下穿产生卖出信号 3. 随机指标用于判断价格在一定周期内的相对位置,%K<20产生买入信号,%K>80产生卖出信号 策略创新地引入了基于Z分数的概率阈值机制,通过计算价格的标准差来过滤虚假信号。只有当Z分数超过设定阈值时,才会触发实际的交易信号。
这是一个将经典技术指标与现代统计方法相结合的创新策略。通过多指标协同和概率阈值过滤,在保持策略稳健性的同时提高了交易效率。该策略具有较强的适应性和可扩展性,适合进行中长期趋势交易。虽然存在一定的滞后性风险,但通过合理的参数优化和风险管理可以实现稳定的交易表现。
/*backtest
start: 2024-01-06 00:00:00
end: 2025-01-04 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("RSI-MACD-Stochastic Strategy", shorttitle = "RMS_V1", overlay=true)
// Inputs
use_macd = input.bool(true, title="Use MACD")
use_rsi = input.bool(true, title="Use RSI")
use_stochastic = input.bool(true, title="Use Stochastic")
threshold_buy = input.float(0.5, title="Buy Threshold (Probability)")
threshold_sell = input.float(-0.5, title="Sell Threshold (Probability)")
// Indicators
// RSI
rsi_period = input.int(14, title="RSI Period")
rsi = ta.rsi(close, rsi_period)
// Stochastic Oscillator
stoch_k = ta.stoch(close, high, low, rsi_period)
stoch_d = ta.sma(stoch_k, 3)
// MACD
[macd_line, signal_line, _] = ta.macd(close, 12, 26, 9)
// Calculate Z-score
lookback = input.int(20, title="Z-score Lookback Period")
mean_close = ta.sma(close, lookback)
stddev_close = ta.stdev(close, lookback)
zscore = (close - mean_close) / stddev_close
// Buy and Sell Conditions
long_condition = (use_rsi and rsi < 30) or (use_stochastic and stoch_k < 20) or (use_macd and macd_line > signal_line)
short_condition = (use_rsi and rsi > 70) or (use_stochastic and stoch_k > 80) or (use_macd and macd_line < signal_line)
buy_signal = long_condition and zscore > threshold_buy
sell_signal = short_condition and zscore < threshold_sell
// Trading Actions
if (buy_signal)
strategy.entry("Buy", strategy.long)
if (sell_signal)
strategy.entry("Sell", strategy.short)