200 SMA Multi-Timeframe: 1H, 4H, Daily, Weekly

negative_gamma · study · 83 行 · 点赞 1 · TradingView 原页

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

Pine Script

//@version=6
indicator("SMA 200: 1H-4H-D-W", overlay=true)
 
// ─────────────────────────────────────────────
// Inputs
// ─────────────────────────────────────────────
length = input.int(200, "MA Length", minval=1)
 
smooth1H = input.int(8,  "1H smoothing", minval=1)
smooth4H = input.int(12, "4H smoothing", minval=1)
smooth1D = input.int(16, "1D smoothing", minval=1)
smooth1W = input.int(20, "1W smoothing", minval=1)
 
show1H = input.bool(true, "Show 1H")
show4H = input.bool(true, "Show 4H")
show1D = input.bool(true, "Show 1D")
show1W = input.bool(true, "Show 1W")
 
// ─────────────────────────────────────────────
// Native 200 SMA
// ─────────────────────────────────────────────
ma1H = request.security(
     syminfo.tickerid,
     "60",
     ta.sma(close, length),
     gaps=barmerge.gaps_off,
     lookahead=barmerge.lookahead_off)
 
ma4H = request.security(
     syminfo.tickerid,
     "240",
     ta.sma(close, length),
     gaps=barmerge.gaps_off,
     lookahead=barmerge.lookahead_off)
 
ma1D = request.security(
     syminfo.tickerid,
     "1D",
     ta.sma(close, length),
     gaps=barmerge.gaps_off,
     lookahead=barmerge.lookahead_off)
 
ma1W = request.security(
     syminfo.tickerid,
     "1W",
     ta.sma(close, length),
     gaps=barmerge.gaps_off,
     lookahead=barmerge.lookahead_off)
 
// ─────────────────────────────────────────────
// Visual smoothing
// ─────────────────────────────────────────────
ma1H_smooth = ta.ema(ma1H, smooth1H)
ma4H_smooth = ta.ema(ma4H, smooth4H)
ma1D_smooth = ta.ema(ma1D, smooth1D)
ma1W_smooth = ta.ema(ma1W, smooth1W)
 
// ─────────────────────────────────────────────
// Plots
// ─────────────────────────────────────────────
plot(
     show1H ? ma1H_smooth : na,
     title="200 MA 1H",
     color=color.aqua,
     linewidth=1)
 
plot(
     show4H ? ma4H_smooth : na,
     title="200 MA 4H",
     color=color.yellow,
     linewidth=2)
 
plot(
     show1D ? ma1D_smooth : na,
     title="200 MA 1D",
     color=color.orange,
     linewidth=2)
 
plot(
     show1W ? ma1W_smooth : na,
     title="200 MA 1W",
     color=color.fuchsia,
     linewidth=3)

← 返回列表