
This strategy is a comprehensive trading system that combines multi-timeframe analysis, trend following, and dynamic position sizing. It uses EMA as the primary trend indicator, MACD as a secondary confirmation indicator, and incorporates ATR for risk control and take profit/stop loss settings. The strategy’s uniqueness lies in its use of 8-hour timeframe volume-price analysis for signal filtering and dynamic position sizing based on trend strength.
The strategy employs a layered design approach with the following core components: 1. Trend Identification System: Uses 7-period and 90-period EMA crossovers and relative positions to determine trend direction 2. Signal Confirmation System: Uses MACD indicator’s golden and death crosses as entry signal confirmation 3. Multi-timeframe Validation: Ensures larger timeframe support through 8-hour period EMA and volume analysis 4. Dynamic Position Management: Adjusts position size based on trend strength (calculated through EMA difference to ATR ratio) 5. Risk Control System: Sets stop loss at 1.5x ATR and take profit at 3x ATR
The strategy builds a complete trend following trading system through multi-timeframe analysis and dynamic position management. Its strengths lie in its systematic design approach and comprehensive risk control mechanisms, while attention needs to be paid to market environment adaptability and parameter optimization issues. Through the suggested optimization directions, the strategy can further enhance its stability and profit potential.
/*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)