该策略利用两条不同周期的指数移动平均线(EMA)的交叉信号来捕捉市场的短期动量,当快线从下向上穿越慢线时开多头仓位,当快线从上向下穿越慢线时开空头仓位。同时设置了止损和止盈来控制风险和锁定利润。这是一个简单而经典的基于动量效应的短线交易策略。
EMA交叉动量短线交易策略是一个简单易用的短线交易策略,适合初学者快速实践和熟悉量化交易的流程。该策略可以捕捉短期的动量效应,顺应市场趋势方向,同时设置了固定百分比止损止盈来控制风险。但是该策略也存在频繁交易、盈亏比不高、趋势识别滞后等风险。可以从优化止损止盈方式、过滤震荡行情、动态调整仓位、组合不同周期、结合宏观分析等方面对策略进行优化和改进,以期提高策略的风险回报和稳定性。
/*backtest start: 2023-06-08 00:00:00 end: 2024-06-13 00:00:00 period: 1d basePeriod: 1h exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}] */ //@version=5 strategy("Scalping Strategy", overlay=true) // Parameters length_fast = input.int(9, title="Fast EMA Length", minval=1) length_slow = input.int(21, title="Slow EMA Length", minval=1) stop_loss_pct = 0.7 // Risk 0.7% of capital take_profit_pct = 0.5 // Target 0.5% of capital // Calculate EMAs ema_fast = ta.ema(close, length_fast) ema_slow = ta.ema(close, length_slow) // Plot EMAs plot(ema_fast, color=color.blue, title="Fast EMA") plot(ema_slow, color=color.red, title="Slow EMA") // Trading logic long_condition = ta.crossover(ema_fast, ema_slow) short_condition = ta.crossunder(ema_fast, ema_slow) // Calculate stop loss and take profit levels stop_loss_long = strategy.position_avg_price * (1 - stop_loss_pct / 100) take_profit_long = strategy.position_avg_price * (1 + take_profit_pct / 100) stop_loss_short = strategy.position_avg_price * (1 + stop_loss_pct / 100) take_profit_short = strategy.position_avg_price * (1 - take_profit_pct / 100) // Enter and exit trades if (long_condition) strategy.entry("Long", strategy.long) if (short_condition) strategy.entry("Short", strategy.short) // Exit long trades if (strategy.position_size > 0) strategy.exit("Take Profit Long", "Long", limit=take_profit_long) strategy.exit("Stop Loss Long", "Long", stop=stop_loss_long) // Exit short trades if (strategy.position_size < 0) strategy.exit("Take Profit Short", "Short", limit=take_profit_short) strategy.exit("Stop Loss Short", "Short", stop=stop_loss_short)