
この戦略は,複数のタイムフレームの分析,トレンド追跡,ダイナミックなポジション管理を組み合わせた完全な取引システムである.この戦略は,EMAを主要トレンド指標として,MACDを二次確認指標として使用し,ATRと組み合わせてリスク管理とストップ・ローズ設定を行う.この戦略のユニークな点は,8時間枠の量値分析によって取引信号をフィルターし,トレンドの強さに応じてポジションの規模を動的に調整することです.
戦略は階層化されたデザインの考え方を採用し,以下の核心構成要素を含んでいます.
この戦略は,複数のタイムフレームの分析とダイナミックなポジション管理により,完全なトレンド追跡取引システムを構築している.戦略の優位性は,体系的な設計思考と完善したリスク制御機構にあるが,同時に,市場環境の適応性とパラメータの最適化の問題にも注意する必要がある.戦略は,推奨された最適化方向によって,その安定性と収益性をさらに向上させることができる.
/*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)