
Đây là một chiến lược theo dõi xu hướng dựa trên tín hiệu chéo của đường trung bình di chuyển ba chỉ số ((EMA)). Chiến lược này sử dụng các chỉ số EMA 9 chu kỳ, 15 chu kỳ và 50 chu kỳ để đánh giá các tín hiệu chéo của đường trung bình ngắn hạn và đường trung bình trung hạn, kết hợp với đường trung bình dài hạn làm bộ lọc xu hướng, đồng thời kết hợp với cơ chế dừng lỗ động để quản lý rủi ro giao dịch. Chiến lược này được thiết kế để đáp ứng đầy đủ nhu cầu theo dõi xu hướng và quản lý rủi ro, phù hợp với giao dịch trung hạn dài hạn.
Lý luận cốt lõi của chiến lược là xác định thời gian giao dịch bằng cách theo dõi tín hiệu chéo của EMA 9 chu kỳ với EMA 15 chu kỳ và sử dụng EMA 50 chu kỳ làm chỉ số xác nhận xu hướng. Cụ thể:
Đây là một chiến lược theo dõi xu hướng được thiết kế hợp lý, logic rõ ràng. Bằng cách sử dụng kết hợp của nhiều đường trung bình, cả hai đảm bảo độ tin cậy của tín hiệu và thực hiện theo dõi hiệu quả của xu hướng.
/*backtest
start: 2019-12-23 08:00:00
end: 2024-11-27 00:00:00
period: 1d
basePeriod: 1d
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA Crossover Strategy with 50 EMA Filter", overlay=true)
// Customizable Inputs
ema9Length = input(9, title="EMA 9 Length")
ema15Length = input(15, title="EMA 15 Length")
ema50Length = input(50, title="EMA 50 Length")
stopLossPoints = input(100, title="Stop Loss Points")
takeProfitPoints = input(200, title="Take Profit Points")
// Calculate EMAs
ema9 = ta.ema(close, ema9Length)
ema15 = ta.ema(close, ema15Length)
ema50 = ta.ema(close, ema50Length)
// Detect crossovers
crossover_above = ta.crossover(ema9, ema15)
crossover_below = ta.crossunder(ema9, ema15)
// Plot EMAs
plot(ema9, color=color.blue, title="EMA 9")
plot(ema15, color=color.red, title="EMA 15")
// Make the 50 EMA invisible
plot(ema50, color=color.new(color.white, 100), title="EMA 50", display=display.none)
// Plot buy and sell signals as shapes
plotshape(crossover_above and close > ema50, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small)
plotshape(crossover_below and close < ema50, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small)
// Execute trades
if (crossover_above and close > ema50)
strategy.entry("Buy", strategy.long)
if (crossover_below and close < ema50)
strategy.close("Buy")
// Apply stop loss and take profit
if (crossover_above and close > ema50)
strategy.exit("Exit", from_entry="Buy", loss=stopLossPoints, profit=takeProfitPoints)
// Alerts for notifications
if (crossover_above and close > ema50)
alert("EMA 9 crossed above EMA 15 with price above EMA 50 - Buy Signal", alert.freq_once_per_bar_close)
if (crossover_below and close < ema50)
alert("EMA 9 crossed below EMA 15 with price below EMA 50 - Sell Signal", alert.freq_once_per_bar_close)