EMA Crossover Strategy with 50 & 200 EMAs

imfaisal024 · study · 34 行 · 点赞 280 · TradingView 原页

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

Pine Script

//@version=6
indicator("EMA Crossover Strategy with 50 & 200 EMAs", shorttitle="EMA 50/200 Cross", overlay=true)
 
// User inputs to define the EMA periods
fastLength = input.int(50, title="Fast EMA Length")  // Corrected default value setting
slowLength = input.int(200, title="Slow EMA Length")  // Corrected default value setting
 
// Colors for the EMAs
fastColor = input(color.new(color.red, 0), title="Fast EMA Color")
slowColor = input(color.new(color.blue, 0), title="Slow EMA Color")
 
// Calculating the EMAs
fastEMA = ta.ema(close, fastLength)
slowEMA = ta.ema(close, slowLength)
 
// Plotting the EMAs on the chart
plot(fastEMA, title="50 EMA", color=fastColor)
plot(slowEMA, title="200 EMA", color=slowColor)
 
// Defining support interactions and golden crossover
uptrendSupport = close > fastEMA and fastEMA > slowEMA
downtrendSupport = close > slowEMA and slowEMA > fastEMA
 
// Golden crossover and death cross
goldenCrossover = ta.crossover(fastEMA, slowEMA)
deathCross = ta.crossunder(fastEMA, slowEMA)
 
// Plotting buy and sell signals based on golden crossover and death cross
plotshape(series=goldenCrossover, title="Golden Crossover", location=location.belowbar, color=color.new(color.green, 0), style=shape.labelup, text="BUY", size=size.small)
plotshape(series=deathCross, title="Death Cross", location=location.abovebar, color=color.new(color.red, 0), style=shape.labeldown, text="SELL", size=size.small)
 
// Highlighting support in trends
bgcolor(uptrendSupport ? color.new(color.green, 90) : na, title="Uptrend Support")
bgcolor(downtrendSupport ? color.new(color.red, 90) : na, title="Downtrend Support")

← 返回列表