本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Multi-Timeframe EMA 15m 1H", overlay=true)
//────────────────────────────────────────────────────────────
// Inputs
//────────────────────────────────────────────────────────────
length = input.int(20, "EMA Length", minval=1)
show_15min = input.bool(true, "Show 15-minute EMA")
show_60min = input.bool(true, "Show 1-hour EMA")
color_15min = input.color(#00008B, "15-minute EMA Color")
color_60min = input.color(#FF0000, "1-hour EMA Color")
//────────────────────────────────────────────────────────────
// Smooth EMA calculation
//────────────────────────────────────────────────────────────
f_smooth_ema(src, len) =>
alpha = 2.0 / (len + 1.0)
float emaValue = na
emaValue := na(emaValue[1]) ? src : alpha * src + (1.0 - alpha) * emaValue[1]
emaValue
//────────────────────────────────────────────────────────────
// Higher-timeframe-equivalent smooth EMAs on 5-minute data
//
// 15 minutes = 3 × 5-minute candles
// 1 hour = 12 × 5-minute candles
//
// This preserves the smooth continuous-line behavior of the
// original indicator while keeping the calculation on 5m data.
//────────────────────────────────────────────────────────────
ema_15 = f_smooth_ema(close, length * 3)
ema_60 = f_smooth_ema(close, length * 12)
//────────────────────────────────────────────────────────────
// Plotting
//────────────────────────────────────────────────────────────
plot(
show_15min ? ema_15 : na,
color=color_15min,
title="15-minute EMA",
linewidth=2)
plot(
show_60min ? ema_60 : na,
color=color_60min,
title="1-hour EMA",
linewidth=2)