该策略是一个结合了多重时间框架分析、趋势跟踪和动态仓位管理的完整交易系统。策略使用EMA作为主要趋势指标,MACD作为二级确认指标,同时结合ATR进行风险控制和止盈止损设置。策略的独特之处在于通过8小时时间框架的量价分析来过滤交易信号,并根据趋势强度动态调整持仓规模。
策略采用分层设计思路,包含以下核心组件: 1. 趋势识别系统:使用7周期和90周期EMA的交叉和位置关系判断趋势方向 2. 信号确认系统:使用MACD指标的金叉死叉作为入场信号确认 3. 多重时间框架验证:通过8小时周期的EMA和成交量分析确保更大时间框架支撑 4. 动态仓位管理:基于趋势强度(通过EMA差值与ATR的比值计算)动态调整仓位大小 5. 风险控制系统:使用1.5倍ATR设置止损,3倍ATR设置止盈
该策略通过多重时间框架分析和动态仓位管理,构建了一个完整的趋势跟踪交易系统。策略的优势在于其系统化的设计思路和完善的风险控制机制,但同时也需要注意市场环境适应性和参数优化的问题。通过建议的优化方向,策略可以进一步提升其稳定性和收益能力。
/*backtest
start: 2024-02-22 00:00:00
end: 2025-02-19 08:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=6
strategy('Optimized Trend Strategy', overlay = true, initial_capital = 10000, default_qty_type = strategy.cash, default_qty_value = 50, commission_value = 0.1)
// 🟢 核心指標
ema7 = ta.ema(close, 7)
ema90 = ta.ema(close, 90)
atr = ta.atr(14)
[macdLine, signalLine, _] = ta.macd(close, 12, 26, 9)
// 🟢 8 小時多時間框架確認
h8Close = request.security(syminfo.tickerid, '480', close)
h8Volume = request.security(syminfo.tickerid, '480', volume)
h8Ema7 = ta.ema(h8Close, 7)
h8Signal = h8Close > h8Ema7 and h8Volume > ta.sma(h8Volume, 50)
// 🟢 動態風控
stopLoss = close - 1.5 * atr
takeProfit = close + 3 * atr
// 🟢 交易信號
longCondition = close > ema7 and ema7 > ema90 and ta.crossover(macdLine, signalLine) and h8Signal
shortCondition = close < ema7 and ema7 < ema90 and ta.crossunder(macdLine, signalLine) and h8Signal
// 🟢 倉位管理(根據趨勢強度)
trendStrength = (ema7 - ema90) / (atr / close)
var float positionSize = na
if trendStrength > 2
positionSize := strategy.equity * 0.7 / close
positionSize
else if trendStrength < 0.5
positionSize := strategy.equity * 0.3 / close
positionSize
else
positionSize := strategy.equity * 0.5 / close
positionSize
// 🟢 訂單執行
if longCondition
strategy.entry('Long', strategy.long, qty = positionSize)
strategy.exit('Long Exit', from_entry = 'Long', stop = stopLoss, limit = takeProfit)
if shortCondition
strategy.entry('Short', strategy.short, qty = positionSize)
strategy.exit('Short Exit', from_entry = 'Short', stop = stopLoss, limit = takeProfit)