EMA21/55CrossoverAlert

cowboycraig · study · 51 行 · 点赞 540 · TradingView 原页

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

Pine Script

//@version=1
study(title="EMA21/55CrossoverAlert", overlay=true)
 
// Input options
EMA_21 = input(title="EMA 21", type=integer, defval=21)
EMA_55 = input(title="EMA 55", type=integer, defval=55)
 
// Calculate values
Alert_EMA_21 = ema(close, EMA_21)
Alert_EMA_55 = ema(close, EMA_55)
 
// Create Buy/Sell Arrows
// plotshape(Buy, color=green, style=shape.arrowup, text="Buy", location=location.bottom)
// plotshape(Sell, color=red, style=shape.arrowdown, text="Sell", location=location.top)
 
// Show on Chart
plot(Alert_EMA_21, color = white, linewidth=3)
plot(Alert_EMA_55, color = lime, linewidth=3)
 
 
// Create alert conditions
alertcondition(condition=crossover(Alert_EMA_21, Alert_EMA_55), 
     title="EMA 21 Cross Above",
     message="EMA 21 crossed over EMA 55."
     
     )
    
 
alertcondition(condition=crossunder(Alert_EMA_21, Alert_EMA_55),
     title="EMA 55 Cross Above",
     message="EMA 55 crossed over EMA 21."
    
     )
     
 
 
// EMA trend bar color
TrendingUp() => Alert_EMA_21 > Alert_EMA_55 
TrendingDown() => Alert_EMA_21 < Alert_EMA_55 
barcolor(TrendingUp() ? green : TrendingDown() ? red : blue)
 
// EMA cross background color alert to chart (Tall Candle)
Uptrend() => TrendingUp() and TrendingDown()[1]
Downtrend() => TrendingDown() and TrendingUp()[1]
bgcolor(Uptrend() ? green : Downtrend() ? red : na,transp=50)
 
// Buy and sell alert (Arrow bottom of Chart, using variables from above)
Buy = Uptrend() and close > close[1]
Sell = Downtrend() and close < close[1]
plotshape(Buy, color=white, style=shape.triangleup, text="Buy", location=location.bottom)
plotshape(Sell, color=white, style=shape.triangledown, text="Sell", location=location.bottom)

← 返回列表