基于均线斜率和交叉的趋势交易策略


创建日期: 2023-09-20 14:32:22 最后修改: 2023-09-20 14:32:22
复制: 0 点击次数: 590
1
关注
1188
关注者

概述

该策略通过多组EMA的斜率方向和交叉关系来判断趋势方向,实现非停止的趋势交易。它可以始终持有看涨或看跌的头寸。

策略原理

  1. 计算3组不同周期的EMA,分别为快、中、慢速EMA。

  2. 当快速EMA上穿中速EMA,且中速EMA斜率转正,产生做多信号。

  3. 当快速EMA下穿中速EMA,且中速EMA斜率转负,产生做空信号。

  4. 当价格上穿慢速EMA时做多,下穿时做空。

  5. 快中慢EMA的斜率关系反映趋势的变化。价格与EMA的交叉确认入场。

优势分析

  1. 多组EMA判断趋势方向更准确。

  2. 快中慢速EMA合理区分趋势和震荡。

  3. 均线斜率变化提示趋势变化提前入场。

  4. 价格交叉再次确认,可避免假突破。

  5. 始终持仓,可充分捕捉趋势机会。

风险分析

  1. 仅基于EMA,在震荡行情下持仓风险大。

  2. EMA参数设定不当,可能错过转折点。

  3. 无法判断趋势强弱,可能过早反向开仓。

  4. 无法有效控制单笔亏损。

优化方向

  1. 测试不同EMA参数组合,找到更优参数。

  2. 增加其他指标判断强弱,如MACD。

  3. 添加止损机制控制风险。

  4. 评估趋势强弱,避免反向开仓过早。

  5. 优化资金管理,调整仓位规模。

  6. 在趋势震荡时主动暂停交易。

总结

该策略利用EMA的多重组合判断趋势,思路合理。但仅依赖EMA存在一定盲点,优化空间较大,可引入更多指标判断。也需要加入风险控制机制以提高稳定性。总体而言,框架设计科学,通过持续改进可望成长为较强的趋势交易策略。

策略源码
/*backtest
start: 2023-08-20 00:00:00
end: 2023-09-19 00:00:00
period: 6h
basePeriod: 15m
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/

//@version=3
strategy("EMA Slope + EMA Cross Strategy (by ChartArt)", shorttitle="CA_-_EMA_slope_cross", overlay=true)

// ChartArt's EMA Slope + EMA Cross Strategy
//
// Version 1.0
// Idea by ChartArt on March 10, 2018.
//
// This strategy uses divergences between
// three moving averages and their slope
// directions as well as crosses between
// the price and the moving averages
// to switch between long/short positions.
//
// The strategy is non-stop in the market
// and always either long or short.
// 
// In addition the moving averages are colored
// depending if they are trending up or down.
//
// List of my work: 
// https://www.tradingview.com/u/ChartArt/

// Input
price = input(close)
MA1_Length = input(2,step=1, title="EMA 1 Length")
MA2_Length = input(4,step=1, title="EMA 2 Length")
MA3_Length = input(20,step=1, title="EMA 3 Length")

switch1=input(true, title="Show Bar Color?")
switch2=input(true, title="Show Moving Averages?")

// Calculation
MA1 = ema(price, MA1_Length)
MA2 = ema(price, MA2_Length)
MA3 = ema(price, MA3_Length)

// Strategy
long = crossunder(price, MA3) or ( change(price)<0 and change(MA1)<0 and crossunder(price,MA1) and change(MA2)>0 )
short = crossover(price, MA3) or ( change(price)>0 and change(MA1)>0 and crossover(price,MA1)  and change(MA2)<0 ) 

if long
    strategy.entry("Long", strategy.long, comment="Long")

if short
    strategy.entry("Short", strategy.short, comment="Short")

// Strategy Alert
alertcondition(long, title='EMA Slope + EMA Cross Strategy, Long Alert', message='Go Long!')
alertcondition(short, title='EMA Slope + EMA Cross Strategy, Short Alert', message='Go Short!')

// MA trend bar color
up =  change(MA2)>0 and change(MA3)>0
dn =  change(MA2)<0 and change(MA3)<0
bar_color = up?green:dn?red:blue
barcolor(switch1?bar_color:na)

// MA trend output color
MA2_color = change(MA2)>0?lime:change(MA2)<0?red:blue
MA3_color = change(MA3)>0?lime:change(MA3)<0?red:blue

// MA output
EMA2 = plot(switch2?MA2:na, title="EMA 2", style=linebr, linewidth=2, color=MA2_color)
EMA3 = plot(switch2?MA3:na, title="EMA 3", style=linebr, linewidth=4, color=MA3_color)
fill(EMA2, EMA3, color=silver, transp=50)

//plot(strategy.equity, title="equity", color=red, linewidth=2, style=areabr)
更多内容