该策略基于指数移动平均线(EMA)和平均振幅指标(AO)来判断市场趋势方向,并利用K线形态来确认买入信号。当EMA指示市场处于上升趋势,AO指标为正,且出现看涨吞没形态时,策略会产生买入信号。该策略只做多,不做空。同时,策略设置了止损点来控制风险。
该策略的核心原理是利用EMA和AO指标来判断市场趋势方向,并利用K线形态来确认买入信号。具体来说:
该策略通过EMA、AO和K线形态来判断趋势和产生交易信号,具有逻辑清晰、易于实现的特点。同时,策略设置了止损点来控制风险。但是,该策略也存在一些局限性,如只适用于趋势性市场,对参数选择敏感等。未来可以通过加入更多技术指标、优化止损策略、加入仓位管理等方式来进一步提高策略的表现。
/*backtest
start: 2023-05-23 00:00:00
end: 2024-05-28 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA & K-Pattern Trend Trading (Long Only)", overlay=true)
// 输入参数
emaLength = input.int(50, title="EMA长度")
aoShortLength = input.int(5, title="AO短期长度")
aoLongLength = input.int(34, title="AO长期长度")
stopLossPct = input.float(2, title="止损百分比") / 100 // 止损百分比
// 计算EMA和AO指标
ema = ta.ema(close, emaLength)
ao = ta.sma(high, aoShortLength) - ta.sma(low, aoLongLength)
// 定义趋势方向
isBullish = close > ema
// 定义K线形态
bullishK = close > open and close[1] < open[1] and open < close[1] and close > high[1] // 看涨吞没形态
// 定义买入信号
longCondition = bullishK and isBullish and ao > 0
// 绘制EMA
plot(ema, title="EMA", color=color.blue)
// 计算止损点
stopLossLevelLong = close * (1 - stopLossPct)
// 策略执行并标注信号
if (longCondition)
strategy.entry("做多", strategy.long)
label.new(bar_index, high, text="买入", style=label.style_label_up, color=color.green, textcolor=color.white)
strategy.exit("止损", from_entry="做多", stop=stopLossLevelLong)