EMA Crossover Algo with Signal Priority

Seatheat · study · 22 行 · 点赞 518 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=5
indicator("EMA Crossover Buy/Sell Indicator", shorttitle="EMA Crossover", overlay=true)
 
// Define the EMAs
ema20 = ta.ema(close, 20)
ema50 = ta.ema(close, 50)
 
// Plot the EMAs
plot(ema20, color=color.blue, linewidth=2, title="EMA 20")
plot(ema50, color=color.orange, linewidth=2, title="EMA 50")
 
// Generate buy and sell signals
buySignal = ta.crossover(ema20, ema50)
sellSignal = ta.crossunder(ema20, ema50)
 
// Plot buy and sell signals on the chart
plotshape(series=buySignal, location=location.belowbar, color=color.green, style=shape.labelup, title="Buy Signal", text="BUY")
plotshape(series=sellSignal, location=location.abovebar, color=color.red, style=shape.labeldown, title="Sell Signal", text="SELL")
 
// Optionally, you can add alerts for these signals
alertcondition(buySignal, title="Buy Alert", message="Buy signal: EMA 20 crossed above EMA 50")
alertcondition(sellSignal, title="Sell Alert", message="Sell signal: EMA 20 crossed below EMA 50")

← 返回列表