移动平均线交叉交易策略通过计算不同周期的移动平均线,在它们发生金叉或死叉时进行买入或卖出操作,属于技术分析类交易策略。该策略简单易行,资金占用少,回撤较小,适合中长线操作。
该策略通过计算20周期和50周期的指数移动平均线(EMA)。当20周期EMA上穿50周期EMA时,进行买入操作。当20周期EMA下穿50周期EMA时,进行卖出操作。
EMA指指数移动平均线,它对最近的数据给予较大权重。EMA的计算公式为:
EMAtoday = (Pricetoday * k) + EMAyesterday * (1-k)
其中,k = 2/(周期数+1)
这样,当短期EMA上穿长期EMA时,表示价格走势转 bullish,LONG;当短期EMA下穿长期EMA时,表示价格走势转 bearish,SHORT。
该策略具有以下优势:
该策略也存在以下风险:
因此,该策略可从以下几个方面进行优化:
移动平均线交叉交易策略属于简单有效的技术交易策略,它易于理解实施,历经市场检验。通过参数优化、加入辅助条件等手段,可以进一步减少交易风险,提高策略稳定性。该策略可以成为量化交易的一个基础模块。
/*backtest
start: 2022-11-20 00:00:00
end: 2023-11-26 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/
// © brandlabng
//@version=5
//study(title="Holly Grail", overlay = true)
strategy('HG|E15m', overlay=true)
src = input(close, title='Source')
price = request.security(syminfo.tickerid, timeframe.period, src)
ma1 = input(20, title='1st MA Length')
type1 = input.string('EMA', '1st MA Type', options=['EMA'])
ma2 = input(50, title='2nd MA Length')
type2 = input.string('EMA', '2nd MA Type', options=['EMA'])
price1 = if type1 == 'EMA'
ta.ema(price, ma1)
price2 = if type2 == 'EMA'
ta.ema(price, ma2)
//plot(series=price, style=line, title="Price", color=black, linewidth=1, transp=0)
plot(series=price1, style=plot.style_line, title='1st MA', color=color.new(#219ff3, 0), linewidth=2)
plot(series=price2, style=plot.style_line, title='2nd MA', color=color.new(color.purple, 0), linewidth=2)
longCondition = ta.crossover(price1, price2)
if longCondition
strategy.entry('Long', strategy.long)
shortCondition = ta.crossunder(price1, price2)
if shortCondition
strategy.entry('Short', strategy.short)