
この戦略は、複数の指数移動平均 (EMA) クロスオーバーに基づく定量取引システムです。 9 日間 EMA、21 日間 EMA、200 日間 EMA の 3 つの移動平均を調整することで、完全なトレンド追跡取引フレームワークを構築します。この戦略では、高速移動平均と低速移動平均のクロスオーバーと、それらの長期移動平均との位置関係を決定することによって、市場のトレンドと取引を識別します。
この戦略の中心的なロジックは、3 つの移動平均線のクロスオーバーを通じて市場のトレンドを捉えることです。具体的には:
これは、よく設計された、論理的に明確なトレンド追従戦略です。複数の移動平均線を連携させることで、リスク管理能力を高めながら、市場動向を効果的に捉えることができます。戦略には最適化の余地が大きく、継続的な改善を通じてその安定性と収益性をさらに高めることができます。
/*backtest
start: 2019-12-23 08:00:00
end: 2024-12-25 08:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("EMA Cross with both MinhTuan", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=10)
// Tham số EMA
fastLength = input.int(9, title="Fast EMA Length", minval=1)
slowLength = input.int(21, title="Slow EMA Length", minval=1)
filterLength = input.int(200, title="EMA Filter Length", minval=1)
// Tùy chọn chế độ giao dịch
tradeMode = input.string("Both", options=["Long", "Short", "Both"], title="Trade Mode")
// Tính toán EMA
fastEMA = ta.ema(close, fastLength)
slowEMA = ta.ema(close, slowLength)
filterEMA = ta.ema(close, filterLength)
// Điều kiện vào lệnh Long: EMA nhanh cắt lên EMA chậm và cả hai nằm trên EMA 200
longCondition = ta.crossover(fastEMA, slowEMA) and fastEMA > filterEMA and slowEMA > filterEMA
// Điều kiện vào lệnh Short: EMA nhanh cắt xuống EMA chậm và cả hai nằm dưới EMA 200
shortCondition = ta.crossunder(fastEMA, slowEMA) and fastEMA < filterEMA and slowEMA < filterEMA
// Điều kiện thoát lệnh: EMA nhanh cắt ngược lại EMA chậm
closeLongCondition = ta.crossunder(fastEMA, slowEMA) // Thoát lệnh Long
closeShortCondition = ta.crossover(fastEMA, slowEMA) // Thoát lệnh Short
// Thực hiện lệnh Long
if (longCondition and (tradeMode == "Long" or tradeMode == "Both"))
strategy.entry("EMA_Cross_Long", strategy.long)
label.new(x=bar_index, y=low, text="Long", color=color.green, textcolor=color.white, size=size.small)
// Thực hiện lệnh Short
if (shortCondition and (tradeMode == "Short" or tradeMode == "Both"))
strategy.entry("EMA_Cross_Short", strategy.short)
label.new(x=bar_index, y=high, text="Short", color=color.red, textcolor=color.white, size=size.small)
// Thoát lệnh Long
if (closeLongCondition)
strategy.close("EMA_Cross_Long")
label.new(x=bar_index, y=high, text="Close Long", color=color.orange, textcolor=color.white, size=size.small)
// Thoát lệnh Short
if (closeShortCondition)
strategy.close("EMA_Cross_Short")
label.new(x=bar_index, y=low, text="Close Short", color=color.blue, textcolor=color.white, size=size.small)
// Vẽ đường EMA nhanh, EMA chậm, và EMA 200
plot(fastEMA, title="Fast EMA", color=color.blue, linewidth=2)
plot(slowEMA, title="Slow EMA", color=color.orange, linewidth=2)
plot(filterEMA, title="Filter EMA (200)", color=color.red, linewidth=2)
// Hiển thị nền khi đang giữ lệnh
bgcolor(strategy.position_size > 0 ? color.new(color.green, 90) : strategy.position_size < 0 ? color.new(color.red, 90) : na)