本策略通过计算并绘制 20 周期简单移动平均线(SMA)和 21 周期指数移动平均线(EMA),并在它们之间填充颜色来可视化价格波动区域。当价格上穿 20 周期 SMA 时生成买入信号;当价格下穿 21 周期 EMA 时生成卖出信号。该策略同时具有追踪止损和止盈功能。
双移动平均线突破策略的核心思想是利用快速移动平均线和慢速移动平均线之间的交叉作为买卖信号。20 周期 SMA 相对更为灵敏,能快速响应价格变化;21 周期 EMA 的反应稍微滞后但更为平滑。当短期和长期趋势方向一致时,即两条平均线发生向上或向下交叉时,判断趋势进入较强阶段,这个时候做出的买入或卖出决策胜率较大。
具体来说,当收盘价格上穿 20 周期 SMA 时,表示短期和长期均为上升趋势,因此做多;当收盘价格下穿 21 周期 EMA 时,表示短期和长期均为下降趋势,因此做空。平仓信号则与 entry 信号相反,如价格下破 20 周期 SMA 则平多仓,价格上破 21 周期 EMA 则平空仓。
该策略同时利用fill技术在两条移动平均线之间填充颜色,形成视觉指标,辅助判断市场走势。
双移动平均线突破策略具有以下优势:
该策略也存在一些风险:
针对上述风险,可以采取以下措施加以应对:
该策略可以从以下几个方面进行优化:
本策略通过快速和缓速双移动平均线的交叉来判断行情趋势变化,并相应做出买入和卖出决策。该策略具有简单、直观、容易实现等优点,也存在一定的风险。通过参数优化、增加过滤条件、人工干预等方式可以降低风险提高策略效果。该策略扩展空间大,值得深入研究与应用。
/*backtest
start: 2024-01-27 00:00:00
end: 2024-02-26 00:00:00
period: 4h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("BMSB Breakout Strategy", shorttitle="BMSB Breakout", overlay=true)
source = close
smaLength = 20
emaLength = 21
sma = ta.sma(source, smaLength)
ema = ta.ema(source, emaLength)
outSma = request.security(syminfo.tickerid, timeframe.period, sma)
outEma = request.security(syminfo.tickerid, timeframe.period, ema)
smaPlot = plot(outSma, color=color.new(color.red, 0), title='20w SMA')
emaPlot = plot(outEma, color=color.new(color.green, 0), title='21w EMA')
fill(smaPlot, emaPlot, color=color.new(color.orange, 75), fillgaps=true)
// Definir condiciones para la estrategia de compra y venta
buyCondition = ta.crossover(close, outSma)
sellCondition = ta.crossunder(close, outEma)
// Entrada larga (compra) y salida corta
strategy.entry("Long", strategy.long, when=buyCondition and not na(sellCondition))
strategy.close("Short", when=buyCondition)
// Entrada corta (venta) y salida larga
strategy.entry("Short", strategy.short, when=sellCondition and not na(buyCondition))
strategy.close("Long", when=sellCondition)
// Puedes ajustar la configuración de la estrategia y los valores predeterminados según tus preferencias
plotshape(series=buyCondition, location=location.belowbar, color=color.green, style=shape.triangleup, title="Buy Signal")
plotshape(series=sellCondition, location=location.abovebar, color=color.red, style=shape.triangledown, title="Sell Signal")