OPEN-SOURCE SCRIPT
EMA 20/40 Crossover

//version=5
indicator(title="EMA 20/40 Crossover", shorttitle="EMA Cross", overlay=true)
// Calculate EMAs
ema20 = ta.ema(close, 20)
ema40 = ta.ema(close, 40)
// Detect crossovers
bullCross = ta.crossover(ema20, ema40) // EMA20 crosses above EMA40 (Buy signal)
bearCross = ta.crossunder(ema20, ema40) // EMA20 crosses below EMA40 (Sell signal)
// Plot EMA lines
plot(ema20, color=color.blue, title="EMA 20", linewidth=2)
plot(ema40, color=color.red, title="EMA 40", linewidth=2)
// Plot signals
plotshape(series=bullCross, title="Buy Signal", location=location.belowbar, style=shape.labelup, size=size.small, color=color.green, text="BUY")
plotshape(series=bearCross, title="Sell Signal", location=location.abovebar, style=shape.labeldown, size=size.small, color=color.red, text="SELL")
// Alert setup (optional)
alertcondition(bullCross, title="EMA Bullish Cross", message="EMA 20 crossed above EMA 40 - BUY!")
alertcondition(bearCross, title="EMA Bearish Cross", message="EMA 20 crossed below EMA 40 - SELL!")
indicator(title="EMA 20/40 Crossover", shorttitle="EMA Cross", overlay=true)
// Calculate EMAs
ema20 = ta.ema(close, 20)
ema40 = ta.ema(close, 40)
// Detect crossovers
bullCross = ta.crossover(ema20, ema40) // EMA20 crosses above EMA40 (Buy signal)
bearCross = ta.crossunder(ema20, ema40) // EMA20 crosses below EMA40 (Sell signal)
// Plot EMA lines
plot(ema20, color=color.blue, title="EMA 20", linewidth=2)
plot(ema40, color=color.red, title="EMA 40", linewidth=2)
// Plot signals
plotshape(series=bullCross, title="Buy Signal", location=location.belowbar, style=shape.labelup, size=size.small, color=color.green, text="BUY")
plotshape(series=bearCross, title="Sell Signal", location=location.abovebar, style=shape.labeldown, size=size.small, color=color.red, text="SELL")
// Alert setup (optional)
alertcondition(bullCross, title="EMA Bullish Cross", message="EMA 20 crossed above EMA 40 - BUY!")
alertcondition(bearCross, title="EMA Bearish Cross", message="EMA 20 crossed below EMA 40 - SELL!")
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, người tạo ra tập lệnh này đã biến tập lệnh thành mã nguồn mở để các nhà giao dịch có thể xem xét và xác minh công năng. Xin dành lời khen tặng cho tác giả! Mặc dù bạn có thể sử dụng miễn phí, nhưng lưu ý nếu đăng lại mã, bạn phải tuân theo Quy tắc nội bộ của chúng tôi.
Thông báo miễn trừ trách nhiệm
Thông tin và ấn phẩm không có nghĩa là và không cấu thành, tài chính, đầu tư, kinh doanh, hoặc các loại lời khuyên hoặc khuyến nghị khác được cung cấp hoặc xác nhận bởi TradingView. Đọc thêm trong Điều khoản sử dụng.