该策略通过移动平均线和布林带的组合利用双重指标验证信号,进行趋势判断和交易。策略利用快速和慢速移动平均线的金叉做多,死叉做空;同时结合布林带上下轨的突破作为辅助验证信号,提高策略的稳定性。
计算快速和慢速移动平均线,当快线上穿慢线时产生做多信号,下穿时做空信号。同时计算布林带的上轨和下轨。只有当价格同时突破布林带上轨或下轨时,才确认移动平均线的交易信号。这样可以避免被假突破所套。
可适当缩短平均线和布林带周期,或优化参数组合来控制风险。
该策略融合双重指标验证信号,可减少假信号,适合中长线持仓。通过参数优化等进一步完善策略,可获得更好效果。
/*backtest
start: 2023-08-18 00:00:00
end: 2023-09-17 00:00:00
period: 3h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=2
strategy("MA-Zorrillo",overlay=true)
ma_short= sma(close,8)
ma_long= sma(close,89)
entry_ma = crossover (ma_short,ma_long)
exit_ma = crossunder (ma_short,ma_long)
BBlength = input(24, minval=1,title="Bollinger Period Length")
BBmult = 2 // input(2.0, minval=0.001, maxval=50,title="Bollinger Bands Standard Deviation")
BBbasis = sma(close, BBlength)
BBdev = BBmult * stdev(close, BBlength)
BBupper = BBbasis + BBdev
BBlower = BBbasis - BBdev
source = close
entry_bb = crossover(source, BBlower)
exit_bb = crossunder(source, BBupper)
vs_entry = false
vs_exit = false
for i = 0 to 63
if (entry_bb[i])
vs_entry := true
if (exit_bb[i])
vs_exit := true
entry = entry_ma and vs_entry
exit = exit_ma and vs_exit
strategy.entry(id="long_ma",long=true,when=entry)
strategy.close(id="long_ma", when=exit)
strategy.entry(id="short_ma",long=false,when=exit)
strategy.close(id="short_ma",when=entry)