
Chiến lược này là một hệ thống giao dịch dựa trên tín hiệu chéo đa chỉ số trung bình di chuyển (EMA), kết hợp các chỉ số EMA với các chu kỳ khác nhau và cơ chế dừng động ATR. Chiến lược sử dụng 10 chu kỳ, 39 chu kỳ, 73 chu kỳ EMA làm chỉ số tín hiệu chính, đồng thời giới thiệu 143 chu kỳ thời gian cao EMA làm bộ lọc xu hướng và thiết lập mục tiêu dừng lỗ và thu lợi nhuận thông qua chỉ số ATR.
Logic cốt lõi của chiến lược dựa trên tín hiệu chéo và xác nhận xu hướng của nhiều EMA. Khi EMA ngắn hạn (10 chu kỳ) vượt qua EMA trung bình (39 chu kỳ) và giá nằm trên EMA dài hạn (73 chu kỳ) và EMA cao hơn (143) thì hệ thống tạo ra nhiều tín hiệu. Ngược lại, khi EMA ngắn hạn vượt qua EMA trung bình và giá nằm dưới EMA dài hạn và EMA cao hơn, hệ thống tạo ra tín hiệu trống.
Chiến lược này xây dựng một hệ thống giao dịch kết hợp theo dõi xu hướng và quản lý rủi ro bằng cách dừng động ATR bằng cách chéo nhiều EMA. Ưu điểm chính của chiến lược là cơ chế xác nhận nhiều chu kỳ thời gian và quản lý vị trí động, nhưng cũng cần chú ý đến rủi ro của thị trường ngang và sự chậm trễ.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-28 00:00:00
period: 2d
basePeriod: 2d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("Enhanced EMA Crossover Strategy", overlay=true)
// Define the EMA lengths
ema_short_length = 10
ema_long_length = 39
ema_filter_length = 73
ema_higher_tf_length = 143
// Calculate the EMAs
ema_short = ta.ema(close, ema_short_length)
ema_long = ta.ema(close, ema_long_length)
ema_filter = ta.ema(close, ema_filter_length)
ema_higher_tf = request.security(syminfo.tickerid, "D", ta.ema(close, ema_higher_tf_length))
// Calculate ATR for volatility-based stop loss and take profit
atr_length = 14
atr = ta.atr(atr_length)
// Plot the EMAs
plot(ema_short, title="EMA 10", color=color.blue)
plot(ema_long, title="EMA 35", color=color.red)
plot(ema_filter, title="EMA 75", color=color.orange)
plot(ema_higher_tf, title="EMA Higher TF", color=color.purple)
// EMA crossover conditions with EMA 75 and higher timeframe EMA filter
longCondition = ta.crossover(ema_short, ema_long) and close > ema_filter and close > ema_higher_tf
shortCondition = ta.crossunder(ema_short, ema_long) and close < ema_filter and close < ema_higher_tf
// Execute long trade with dynamic stop loss and take profit
if (longCondition)
strategy.entry("Long", strategy.long)
strategy.exit("Take Profit/Stop Loss", "Long", limit=close + 2 * atr, stop=close - 1 * atr)
// Execute short trade with dynamic stop loss and take profit
if (shortCondition)
strategy.entry("Short", strategy.short)
strategy.exit("Take Profit/Stop Loss", "Short", limit=close - 2 * atr, stop=close + 1 * atr)
// Plot signals on the chart
plotshape(series=longCondition, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal", text="BUY")
plotshape(series=shortCondition, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal", text="SELL")