该策略基于移动均线、Hull移动均线和相对强弱指数(RSI)构建交易信号,属于典型的机会跟踪策略。它可以自动识别市场机会,进行长空切换,适用于中短期交易。
该策略利用EMA、Hull和RSI三种指标的组合来捕捉中短期交易机会。策略信号的产生需要满足趋势、动量和超买超卖三个维度,从而过滤很多假信号。同时,可以通过参数优化和引入更多辅助指标等方式来进一步提高策略的稳定性和交易绩效。
/*backtest
start: 2023-01-11 00:00:00
end: 2024-01-17 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Bitduke
//@version=4
strategy(shorttitle="EHR", title="Simple EMA_Hull_RSI", overlay=false,
calc_on_every_tick=false, pyramiding=0, default_qty_type=strategy.cash,
default_qty_value=1000, currency=currency.USD, initial_capital=1000,
commission_type=strategy.commission.percent, commission_value=0.075)
// EMA
len = input(minval=1, title="EMA Length", defval=50)
src = input(close, title="EMA Source")
final_ema = ema(src, len)
plot(final_ema, color=color.red, title="EMA")
overbought = input(60, title="overbought value")
oversold = input(45, title="oversold value")
overbought_signal = rsi(close, 14) > overbought
oversold_signal = rsi(close, 14) < oversold
barcolor(overbought_signal ? color.black : na)
barcolor(oversold_signal ? color.blue : na)
// Hull MA
n = input(title="Hull Length", defval=7)
n2ma=2*wma(close,round(n/2))
nma=wma(close,n)
diff=n2ma-nma
sqn=round(sqrt(n))
n2ma1=2*wma(close[1],round(n/2))
nma1=wma(close[1],n)
diff1=n2ma1-nma1
sqn1=round(sqrt(n))
n1=wma(diff,sqn)
n2=wma(diff1,sqn)
c=n1>n2?color.green:color.red
ma=plot(n1,color=c)
// Strategy Logic
longCondition = overbought_signal and crossover(n1,final_ema)
shortCondition = oversold_signal and crossover(final_ema,n1)
strategy.entry("EHR_Long", strategy.long, when=longCondition)
strategy.entry("EHR_Short", strategy.short, when=shortCondition)