
Chiến lược này là một hệ thống giao dịch định lượng kết hợp các đường trung bình di chuyển (MA) và theo dõi xu hướng. Nó sử dụng đường trung bình di chuyển đơn giản (SMA) 15 chu kỳ làm bộ lọc xu hướng, đồng thời sử dụng các đường trung bình di chuyển 9 chu kỳ và 21 chu kỳ để tạo ra tín hiệu giao dịch. Chiến lược này sử dụng các điều kiện nhập cảnh nghiêm ngặt và tỷ lệ lợi nhuận rủi ro cố định 1:4 để quản lý rủi ro.
Logic cốt lõi của chiến lược này dựa trên các yếu tố chính sau:
Đây là một chiến lược theo dõi xu hướng được thiết kế hợp lý, logic nghiêm ngặt. Chiến lược này có tính thực tiễn tốt bằng cách kết hợp nhiều chỉ số kỹ thuật và quản lý rủi ro nghiêm ngặt. Mặc dù có một số rủi ro vốn có, nhưng có thể nâng cao hơn nữa sự ổn định và lợi nhuận của chiến lược thông qua hướng tối ưu hóa được đề xuất.
/*backtest
start: 2024-02-21 00:00:00
end: 2024-12-19 00:00:00
period: 4d
basePeriod: 4d
exchanges: [{"eid":"Binance","currency":"ETH_USDT"}]
*/
//@version=5
strategy("EMA Crossover Strategy with 15 SMA Trend", overlay=true, margin_long=100, margin_short=100)
// Calculate Indicators
sma15 = ta.sma(close, 15)
ema9 = ta.ema(close, 9)
ema21 = ta.ema(close, 21)
// Trend Detection
uptrend = close > sma15
downtrend = close < sma15
// Crossover Conditions
goldenCross = ta.crossover(ema9, ema21)
deathCross = ta.crossunder(ema9, ema21)
// Candle Conditions
twoBullish = (close > open) and (close[1] > open[1])
bearishCandle = (close < open)
// Entry Conditions
longCondition = goldenCross and uptrend and twoBullish and (ema9 > sma15) and (ema21 > sma15)
shortCondition = deathCross and downtrend and bearishCandle and (ema9 < sma15) and (ema21 < sma15)
// Risk Management
var float longStop = na
var float longTarget = na
var float shortStop = na
var float shortTarget = na
if longCondition
longStop := low
longTarget := close + 4*(close - longStop)
strategy.entry("Long", strategy.long)
strategy.exit("Long Exit", "Long", stop=longStop, limit=longTarget)
if shortCondition
shortStop := high
shortTarget := close - 4*(shortStop - close)
strategy.entry("Short", strategy.short)
strategy.exit("Short Exit", "Short", stop=shortStop, limit=shortTarget)
// Visual Elements
plot(sma15, "15 SMA", color=color.orange)
plot(ema9, "9 EMA", color=color.blue)
plot(ema21, "21 EMA", color=color.red)
// Plot trading levels
plot(longCondition ? longStop : na, "Long Stop", color=color.red, style=plot.style_linebr)
plot(longCondition ? longTarget : na, "Long Target", color=color.green, style=plot.style_linebr)
plot(shortCondition ? shortStop : na, "Short Stop", color=color.red, style=plot.style_linebr)
plot(shortCondition ? shortTarget : na, "Short Target", color=color.green, style=plot.style_linebr)
// Signal Markers
plotshape(longCondition, "Buy", shape.triangleup, location.belowbar, color=color.green, size=size.small)
plotshape(shortCondition, "Sell", shape.triangledown, location.abovebar, color=color.red, size=size.small)