移动平均线交叉策略


创建日期: 2024-01-12 14:04:37 最后修改: 2024-01-12 14:04:37
复制: 0 点击次数: 349
1
关注
1188
关注者

移动平均线交叉策略

移动平均线交叉是一种常见的交易信号。该策略利用快速移动平均线和慢速移动平均线的交叉为交易信号。具体来说,当快速移动平均线从下方上穿慢速移动平均线时,做多;当快速移动平均线从上方下穿慢速移动平均线时,做空。

本策略采用20日exponential moving average (EMA) 作为快速移动平均线,50日EMA作为中速线,200日EMA作为慢速移动平均线。当20日EMA和50日EMA同时上穿200日EMA时做多;当20日EMA和50日EMA同时下穿200日EMA时做空。这样可以过滤掉部分假信号。

策略优势

  1. 移动平均线策略简单易行,容易理解和实现
  2. 利用多条移动平均线组合可以过滤假信号
  3. 多空条件清晰,容易判断进出场时机

策略风险

  1. 在盘整行情中容易产生假信号
  2. 移动平均线具有滞后性,无法及时捕捉价格转折
  3. 无法有效利用突破性行情的利润

优化思路

  1. 优化移动平均线的周期参数,适应不同品种和周期 2.增加其他指标过滤信号,如交易量,布林带等
  2. 结合趋势和反转策略,在趋势行情中追踪,在盘整中等待机会

总结

移动平均线交叉策略概念简单,容易掌握,是量化交易的基础策略之一。本策略作为入门学习具有很好的参考价值。但实战中仍需针对品种和周期进行参数优化,并辅以其他更复杂的技术指标来过滤信号,从而提高策略的实战效果。

策略源码
/*backtest
start: 2023-01-05 00:00:00
end: 2024-01-11 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/
// © rt-maax

//@version=5

strategy(title = "rt maax EMA cross strategy", shorttitle = "rt maax ema ", overlay = true, precision = 8, max_bars_back = 200, pyramiding = 0, initial_capital = 100000, 
     currency = currency.USD, default_qty_type = strategy.cash, default_qty_value = 100000, commission_type = "percent", commission_value = 0.27)
fastema = ta.ema (close , 50)
fema=ta.ema(close,20)
slowema= ta.ema(close,200)
price = close

// === INPUT BACKTEST RANGE ===
fromMonth = input.int(defval = 1,    title = "From Month",  minval = 1, maxval = 12)
fromDay   = input.int(defval = 1,    title = "From Day",    minval = 1, maxval = 31)
fromYear  = input.int(defval = 2021, title = "From Year",   minval = 1970)
thruMonth = input.int(defval = 10,    title = "Thru Month",  minval = 1, maxval = 12)
thruDay   = input.int(defval = 25,    title = "Thru Day",    minval = 1, maxval = 31)
thruYear  = input.int(defval = 2112, title = "Thru Year",   minval = 1970)

// === INPUT SHOW PLOT ===
showDate  = input(defval = true, title = "Show Date Range")

// === FUNCTION EXAMPLE ===



longCondition1= ta.crossover (fema , fastema) 
longcondition2= fema> slowema
longcondition3=fastema>slowema


if (longCondition1 and longcondition2 and longcondition3 )
    stoploss=low*0.97
    takeprofit=high*1.12
    strategy.entry("Long Entry", strategy.long)
    strategy.exit ("exit","long",stop=stoploss,limit=takeprofit)
   


shortCondition1 = ta.crossunder (fema , fastema )
shortcondition2= fastema< slowema
shortcondition3= fema< slowema

if (shortCondition1 and shortcondition2 and shortcondition3 )
    stoploss=low*0.97 
    takeprofit=high*1.5
    strategy.entry("Short Entry", strategy.short)
    strategy.exit("exit","short",stop=stoploss,limit=takeprofit)




更多内容