
Chiến lược này dựa trên sự giao thoa của hai đường trung bình di chuyển ((EMA) để tạo ra tín hiệu giao dịch. Khi EMA ngắn hạn (20 ngày) đi từ dưới lên qua EMA dài ((50 ngày), nó tạo ra tín hiệu mua; Khi EMA ngắn hạn đi từ trên xuống qua EMA dài, nó tạo ra tín hiệu bán. Đồng thời, chiến lược này cũng vẽ một EMA 200 ngày để tham khảo xu hướng dài hạn.
Chiến lược giao dịch chéo đường hai đường EMA là một chiến lược giao dịch đơn giản, dễ hiểu và phù hợp với thị trường xu hướng. Nó sử dụng chéo đường trung bình di chuyển ngắn hạn và dài hạn để nắm bắt sự thay đổi của xu hướng thị trường, đồng thời đưa ra tham chiếu xu hướng dài hạn. Mặc dù chiến lược này có một số hạn chế, chẳng hạn như hoạt động kém trong thị trường biến động và sự chậm trễ của đường trung bình di chuyển, nhưng bằng cách đưa ra các chỉ số khác, tối ưu hóa các tham số, thêm các biện pháp kiểm soát rủi ro, các biện pháp có thể tiếp tục nâng cao sự ổn định và lợi nhuận của chiến lược.
/*backtest
start: 2023-03-23 00:00:00
end: 2024-03-28 00:00:00
period: 1d
basePeriod: 1h
exchanges: [{"eid":"Futures_Binance","currency":"BTC_USDT"}]
*/
//@version=5
strategy("EMA Crossover Strategy by Peter Gangmei", overlay=true)
// Define the length for moving averages
short_ma_length = input.int(20, "Short MA Length")
long_ma_length = input.int(50, "Long MA Length")
long_ma_200_length = input.int(200, "Long MA 200 Length")
// Define start time for testing
start_time = timestamp(2024, 01, 01, 00, 00)
// Calculate current date and time
current_time = timenow
// Calculate moving averages
ema20 = ta.ema(close, short_ma_length)
ema50 = ta.ema(close, long_ma_length)
ema200 = ta.ema(close, long_ma_200_length)
// Crossing conditions
crossed_above = ta.crossover(ema20, ema50)
crossed_below = ta.crossunder(ema20, ema50)
// Entry and exit conditions within the specified time frame
if true
if (crossed_above)
strategy.entry("Buy", strategy.long)
alert("Buy Condition", alert.freq_once_per_bar_close)
if (crossed_below)
strategy.entry("Sell", strategy.short)
alert("Sell Condition", alert.freq_once_per_bar_close)
// Plotting moving averages for visualization
plot(ema20, color=color.green, title="EMA20")
plot(ema50, color=color.red, title="EMA50")
plot(ema200, color=color.blue, title="EMA200")
// Placing buy and sell markers
plotshape(series=crossed_above, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Buy Signal")
plotshape(series=crossed_below, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Sell Signal")