
Đây là chiến lược theo xu hướng dựa trên nhiều điểm giao nhau của đường trung bình động hàm mũ (EMA). Chiến lược này sử dụng mối quan hệ giao thoa của EMA ngắn hạn 10 kỳ, EMA trung hạn 50 kỳ và EMA dài hạn 200 kỳ để nắm bắt xu hướng thị trường và thực hiện các giao dịch mua và bán khi đáp ứng đủ điều kiện. Ý tưởng cốt lõi của chiến lược này là lọc nhiễu thị trường thông qua đường trung bình động của nhiều khung thời gian, xác định hướng xu hướng chính và thu lợi nhuận khi xu hướng tiếp tục.
Chiến lược này sử dụng hệ thống giao cắt ba đường EMA làm cơ chế tạo tín hiệu giao dịch. Cụ thể:
Chiến lược này là một hệ thống theo dõi xu hướng cổ điển. Thông qua việc sử dụng phối hợp nhiều EMA, nó không chỉ đảm bảo nắm bắt được xu hướng chính mà còn cho phép dừng lỗ và lãi kịp thời. Mặc dù có độ trễ nhất định, thông qua việc thiết lập thông số hợp lý và quản lý rủi ro, vẫn có thể đạt được lợi nhuận ổn định trong thị trường có xu hướng. Có rất nhiều chỗ để tối ưu hóa chiến lược và hiệu suất có thể được cải thiện bằng cách giới thiệu các chỉ báo kỹ thuật khác và cải thiện các quy tắc giao dịch.
/*backtest
start: 2024-12-10 00:00:00
end: 2025-01-09 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT","balance":49999}]
*/
//@version=5
strategy("EMA Crossover Strategy (Enhanced Debug)", overlay=true)
// Inputs for EMA periods
shortEMA = input.int(10, title="Short EMA Period")
mediumEMA = input.int(50, title="Medium EMA Period")
longEMA = input.int(200, title="Long EMA Period")
// Calculating EMAs
emaShort = ta.ema(close, shortEMA)
emaMedium = ta.ema(close, mediumEMA)
emaLong = ta.ema(close, longEMA)
// Plot EMAs
plot(emaShort, color=color.green, title="Short EMA")
plot(emaMedium, color=color.blue, title="Medium EMA")
plot(emaLong, color=color.red, title="Long EMA")
// Conditions for entry and exit
longCondition = close > emaLong and ta.crossover(emaShort, emaMedium) and emaMedium > emaLong
shortCondition = close < emaLong and ta.crossunder(emaShort, emaMedium) and emaMedium < emaLong
closeLongCondition = ta.crossunder(emaShort, emaMedium)
closeShortCondition = ta.crossover(emaShort, emaMedium)
// Debugging labels for unexpected behavior
if (ta.crossover(emaShort, emaLong) and not ta.crossover(emaShort, emaMedium))
label.new(bar_index, high, "Short > Long", style=label.style_circle, color=color.red, textcolor=color.white)
// Debugging EMA relationships
if (emaMedium <= emaLong)
label.new(bar_index, high, "Medium < Long", style=label.style_cross, color=color.orange, textcolor=color.white)
// Entry logic
if (longCondition)
strategy.entry("Long", strategy.long)
if (shortCondition)
strategy.entry("Short", strategy.short)
// Exit logic
if (closeLongCondition)
strategy.close("Long")
if (closeShortCondition)
strategy.close("Short")
// Display labels for signals
plotshape(series=longCondition, style=shape.labelup, color=color.green, location=location.belowbar, title="Buy Signal")
plotshape(series=shortCondition, style=shape.labeldown, color=color.red, location=location.abovebar, title="Sell Signal")