
Chiến lược này là một hệ thống theo dõi xu hướng dựa trên các tín hiệu giao thoa đa chỉ số trung bình di chuyển ((EMA)). Bằng cách kết hợp các EMA 20, 50 và 150 chu kỳ, xây dựng một khuôn khổ hoàn chỉnh để nhận biết xu hướng và thực hiện giao dịch. Chiến lược sử dụng mối quan hệ giao thoa giữa các EMA chu kỳ khác nhau để xác định sự thay đổi xu hướng thị trường và thời gian giao dịch cụ thể.
Chiến lược này sử dụng các đường trung bình di chuyển chỉ số của ba chu kỳ khác nhau: EMA20 cho xu hướng ngắn hạn, EMA50 cho xu hướng trung hạn, EMA150 cho xu hướng dài hạn. Khi EMA50 vượt qua EMA150 hình thành một đường chéo vàng, cho thấy xu hướng tăng dài hạn được hình thành; khi EMA50 vượt qua EMA150 hình thành một đường chéo chết, cho thấy xu hướng giảm dài hạn được hình thành. Tín hiệu giao dịch cụ thể được tạo ra bởi sự giao nhau của EMA20 và EMA50: Đường chéo EMA50 trên EMA20 tạo ra tín hiệu mua, đường chéo EMA50 dưới EMA20 tạo ra tín hiệu bán.
Chiến lược này xây dựng một hệ thống giao dịch theo dõi xu hướng hoàn chỉnh bằng cách sử dụng kết hợp các đường trung bình di chuyển của nhiều chỉ số. Logic của chiến lược rõ ràng, thực hiện đơn giản, có khả năng mở rộng tốt.
/*backtest
start: 2024-02-20 00:00:00
end: 2025-01-20 00:00:00
period: 1h
basePeriod: 1h
exchanges: [{"eid":"Binance","currency":"BTC_USDT"}]
*/
//@version=6
strategy("EMA2050150 Crossover Strategy#ganges", overlay=true, default_qty_type=strategy.percent_of_equity, default_qty_value=100, commission_value=0.1, slippage=3)
// EMAs
ema20 = ta.ema(close, 20)
ema50 = ta.ema(close, 50)
ema150 = ta.ema(close, 150)
// Cross conditions
longCondition = ta.crossover(ema20, ema50)
flatCondition = ta.crossunder(ema20, ema50)
deathCross = ta.crossunder(ema50, ema150)
goldenCross = ta.crossover(ema50, ema150)
// // Trade execution
// if longCondition and time >= startDate and time <= endDate and strategy.position_size == 0
// strategy.entry("Long", strategy.long)
// if flatCondition and time >= startDate and time <= endDate and strategy.position_size > 0
// strategy.close("Long")
// Plot EMAs
plot(ema20, title="EMA 20", color=color.blue)
plot(ema50, title="EMA 50", color=color.orange)
plot(ema150, title="EMA 150", color=color.red)
// Plot cross signals
plotshape(series=goldenCross, location=location.belowbar, color=color.green, style=shape.labelup, title="Golden Cross", size=size.small, text="Golden Cross")
plotshape(series=deathCross, location=location.abovebar, color=color.red, style=shape.labeldown, title="Death Cross", size=size.small, text="Death Cross")
// Plot buy and sell signals
plotshape(series=longCondition, location=location.belowbar, color=color.blue, style=shape.triangleup, title="Buy Signal", size=size.small, text="Buy")
plotshape(series=flatCondition, location=location.abovebar, color=color.orange, style=shape.triangledown, title="Sell Signal", size=size.small, text="Sell")
// Trade execution
if longCondition and strategy.position_size == 0
strategy.entry("Long", strategy.long)
if flatCondition and strategy.position_size > 0
strategy.close("Long")