本策略运用快速移动平均线和慢速移动平均线构建交易信号,实现对趋势的识别和跟踪。当快速线上穿慢速线时产生买入信号;当快速线下穿慢速线时产生卖出信号。该策略适合追踪中长线趋势,可以有效过滤市场噪音。
本策略使用两条不同周期的Exponential Moving Average(指数移动平均线)作为交易决策的基础。快速移动平均线参数设置为30日,用来捕捉较短期的价格变动;慢速移动平均线参数设置为100日,用来判断价格中长线趋势的方向。
当快速线从下方上穿慢速线时,表示市场步入上升趋势,产生买入信号;当快速线从上方下穿慢速线时,表示市场步入下跌趋势,产生卖出信号。
该策略具有以下优势:
该策略也存在一些风险:
该策略可以从以下几个方面进行优化:
本策略基于双均线构建交易决策系统,通过快速均线和慢速均线的价格关系来判断市场趋势,信号生成简单清晰。该策略过滤了部分噪音,能够顺势而为,适合中长线趋势交易。但也存在一些缺陷,通过进行多指标优化和风险控制,可以将该策略优化得更加通用和高效。
/*backtest start: 2023-01-21 00:00:00 end: 2024-01-21 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=2 strategy("EMA Strategy v2", shorttitle = "EMA Strategy v2", overlay=true, pyramiding = 3,default_qty_type = strategy.percent_of_equity, default_qty_value = 10) // === Inputs === // short ma maFastSource = input(defval = close, title = "Fast MA Source") maFastLength = input(defval = 30, title = "Fast MA Period", minval = 1) // long ma maSlowSource = input(defval = close, title = "Slow MA Source") maSlowLength = input(defval = 100, title = "Slow MA Period", minval = 1) // invert trade direction tradeInvert = input(defval = false, title = "Invert Trade Direction?") // risk management useStop = input(defval = true, title = "Use Initial Stop Loss?") slPoints = input(defval = 0, title = "Initial Stop Loss Points", minval = 1) useTS = input(defval = true, title = "Use Trailing Stop?") tslPoints = input(defval = 0, title = "Trail Points", minval = 1) useTSO = input(defval = false, title = "Use Offset For Trailing Stop?") tslOffset = input(defval = 0, title = "Trail Offset Points", minval = 1) // === Vars and Series === fastMA = ema(maFastSource, maFastLength) slowMA = ema(maSlowSource, maSlowLength) plot(fastMA, color=blue) plot(slowMA, color=purple) goLong() => crossover(fastMA, slowMA) killLong() => crossunder(fastMA, slowMA) strategy.entry("Buy", strategy.long, when = goLong()) strategy.close("Buy", when = killLong()) // Shorting if using goShort() => crossunder (fastMA, slowMA) killShort() => crossover(fastMA, slowMA) //strategy.entry("Sell", strategy.short, when = goShort()) //strategy.close("Sell", when = killShort()) if (useStop) strategy.exit("XLS", from_entry ="Buy", stop = strategy.position_avg_price / 1.08 ) strategy.exit("XSS", from_entry ="Sell", stop = strategy.position_avg_price * 1.58)