本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Fixed 5m 4/9 EMA Cloud + 5m 21/50", overlay=true)
// --- Inputs for 21 and 50 EMA ---
grp_emas = "21 & 50 EMA Settings (5m Fixed)"
show_21 = input.bool(true, title="Show 21 EMA", group=grp_emas)
color_21 = input.color(color.orange, title="21 EMA Color", group=grp_emas)
width_21 = input.int(2, title="21 EMA Line Width", minval=1, maxval=4, group=grp_emas)
show_50 = input.bool(true, title="Show 50 EMA", group=grp_emas)
color_50 = input.color(color.white, title="50 EMA Color", group=grp_emas)
width_50 = input.int(2, title="50 EMA Line Width", minval=1, maxval=4, group=grp_emas)
// --- 4 & 9 EMA (Fixed 5-minute timeframe) ---
ema4_5m = request.security(syminfo.tickerid, "5", ta.ema(close, 4))
ema9_5m = request.security(syminfo.tickerid, "5", ta.ema(close, 9))
p1 = plot(ema4_5m, title="4 EMA (5m)", color=color.new(color.blue, 0), linewidth=1)
p2 = plot(ema9_5m, title="9 EMA (5m)", color=color.new(color.purple, 0), linewidth=1)
// Determine if the current candle closes between the two 5m EMAs
high_ema = math.max(ema4_5m, ema9_5m)
low_ema = math.min(ema4_5m, ema9_5m)
closed_between = close <= high_ema and close >= low_ema
// Determine the fill color based on the rules
cloud_color = closed_between ? color.new(color.yellow, 50) :
(ema4_5m > ema9_5m ? color.new(color.green, 80) : color.new(color.red, 80))
// Fill the space between the EMAs
fill(p1, p2, color=cloud_color, title="EMA Cloud")
// --- 21 & 50 EMA (Fixed 5-minute timeframe) ---
ema21_5m = request.security(syminfo.tickerid, "5", ta.ema(close, 21))
ema50_5m = request.security(syminfo.tickerid, "5", ta.ema(close, 50))
plot(show_21 ? ema21_5m : na, title="21 EMA (5m)", color=color_21, linewidth=width_21)
plot(show_50 ? ema50_5m : na, title="50 EMA (5m)", color=color_50, linewidth=width_50)