这是一个结合了日线高低点突破和多时间周期EMA趋势的量化交易策略。策略主要通过监测价格对前一日高低点的突破情况,结合EMA均线和资金流向指标(CMF)来判断交易时机。策略同时运用了小时线和日线两个时间周期的200周期EMA均线,通过多重技术指标的验证来提高交易的准确性。
策略的核心逻辑包含以下几个关键要素: 1. 使用request.security函数获取前一日的最高价和最低价作为关键的支撑阻力位。 2. 结合24周期EMA均线作为趋势判断的基准线。 3. 引入CMF(20周期)作为交易量和价格的综合指标,用于判断市场资金流向。 4. 同时计算当前时间周期和1小时周期的200均线,用于判断更大周期的趋势方向。
具体的交易规则如下: 做多条件:价格突破前一日高点 + 收盘价在EMA之上 + CMF为正值 做空条件:价格跌破前一日低点 + 收盘价在EMA之下 + CMF为负值 平仓条件:做多时价格跌破EMA,做空时价格突破EMA
风险控制建议: 1. 设置合理的止损位置 2. 根据不同市场环境调整参数 3. 增加趋势过滤器 4. 考虑加入波动率指标
这是一个结合了多重技术指标和多时间周期分析的完整交易系统。策略通过日内高低点突破、均线趋势和资金流向的综合分析来寻找交易机会。虽然存在一定的风险,但通过合理的风险控制和持续的优化改进,该策略具有良好的应用价值。建议交易者在实盘使用前进行充分的回测和参数优化。
/*backtest
start: 2024-10-28 00:00:00
end: 2024-11-27 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy(title='The security Daily HIGH/LOW strategy', overlay=true, initial_capital=10000, calc_on_every_tick=true,
default_qty_type=strategy.percent_of_equity, default_qty_value=100,
commission_type=strategy.commission.percent, commission_value=0.1)
// General Inputs
len = input.int(24, minval=1, title='Length MA', group='Optimization parameters')
src = input.source(close, title='Source MA', group='Optimization parameters')
out = ta.ema(src, len)
length = input.int(20, minval=1, title='CMF Length', group='Optimization parameters')
ad = close == high and close == low or high == low ? 0 : (2 * close - low - high) / (high - low) * volume
mf = math.sum(ad, length) / math.sum(volume, length)
// Function to get daily high and low
f_secureSecurity(_symbol, _res, _src) =>
request.security(_symbol, _res, _src[1], lookahead=barmerge.lookahead_on)
pricehigh = f_secureSecurity(syminfo.tickerid, 'D', high)
pricelow = f_secureSecurity(syminfo.tickerid, 'D', low)
// Plotting previous daily high and low
plot(pricehigh, title='Previous Daily High', style=plot.style_linebr, linewidth=2, color=color.new(color.white, 0))
plot(pricelow, title='Previous Daily Low', style=plot.style_linebr, linewidth=2, color=color.new(color.white, 0))
// Entry Conditions
short = ta.crossunder(low, pricelow) and close < out and mf < 0
long = ta.crossover(high, pricehigh) and close > out and mf > 0
if short and barstate.isconfirmed
strategy.entry('short', strategy.short, stop=pricelow[1])
strategy.close('short', when=close > out)
if long and barstate.isconfirmed
strategy.entry('long', strategy.long, stop=pricehigh[1])
strategy.close('long', when=close < out)
// 200 EMA on 1-hour timeframe
ema_200 = ta.ema(close, 200)
ema_200_1h = request.security(syminfo.tickerid, "60", ta.ema(close, 200))
plot(ema_200_1h, color=color.purple, title="200 EMA (1H)")
plot(ema_200, color=color.white, title="200 EMA")