Dual Moving Average Breakout Strategy

Author: ChaoZhang, Date: 2023-09-11 12:31:51
Tags:

该策略同时使用SMA和EMA两种移动平均线,根据价格突破的方向判断做多做空方向。当收盘价高于SMA和EMA时,做多;当收盘价低于SMA和EMA时,做空;当收盘价处于SMA和EMA之间时,平仓。用户可以自行设置SMA和EMA的周期长度。

该策略的优点是同时结合两种均线系统,可以提高准确性。但是也存在一些问题,例如在盘整市场中容易产生错误信号,均线本身滞后性较大等。此外,该策略也没有设置止损以控制亏损。

总而言之,该双均线突破策略适合趋势明显的市场,但需要谨慎使用。可通过优化参数,加入止损,以及增加其他指标过滤来完善该策略,减少信号错误率。

综上所述,双均线突破策略具有简单的交易思路,但实际运用时需要注意风险控制。只有参数设置得当,才能将策略稳定运用于实盘。


/*backtest
start: 2023-08-11 00:00:00
end: 2023-09-10 00:00:00
period: 10m
basePeriod: 1m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=2
strategy(title = "Noro's Multima v1.0", shorttitle = "Multima 1.0", overlay=true, default_qty_type = strategy.percent_of_equity, default_qty_value=100.0, pyramiding=0)

needlong = input(true, "long")
needshort = input(true, "short")

usema1 = input(true, "Use MA1 (SMA, blue)")
usema2 = input(true, "Use MA2 (EMA, red)")
lenma1 = input(40, defval = 40, minval = 2, maxval = 1000, title = "MA1 length")
lenma2 = input(40, defval = 40, minval = 2, maxval = 1000, title = "MA2 length")
//anti = input(true, defval = true, title = "Antipila")
usecf = input(true, defval = true, title = "Use color-filter")

//Strategy
ma1 = sma(close, lenma1)
ma2 = ema(close, lenma2)
signal1 = usema1 == false ? 0 : close > ma1 ? 1 : -1
signal2 = usema2 == false ? 0 : close > ma2 ? 1 : -1
lots = signal1 + signal2

//Lines
plot(ma1, color = blue, linewidth = 3, transp = 0)
plot(ma2, color = red, linewidth = 3, transp = 0)

//Trading
if lots > 0 and (close < open or usecf == false)
    strategy.entry("Long", strategy.long, needlong == false ? 0 : na)

if lots < 0 and (close > open or usecf == false)
    strategy.entry("Short", strategy.short, needshort == false ? 0 : na)
    
if lots == 0
    strategy.close_all()
    
    
    

更多内容