本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Auto Trend Cloud", overlay=true)
// ───────────── INPUTS ─────────────
showTrendCloud = input.bool(true, "Show Trend cloud", group="TREND CLOUD SETTINGS")
periodTrendCloud = input.string("New", "Trend cloud period", ["Short term", "Long term", "New"], group="TREND CLOUD SETTINGS")
fastTrendCloud = input.bool(false, "Fast trend cloud", group="TREND CLOUD SETTINGS")
fastTrendCloudLen = input.int(55, "Fast trend cloud length", 2, group="TREND CLOUD SETTINGS")
// ───────────── SUPERTREND (used by Short / Long term) ─────────────
supertrend(src, factor, len) =>
atr = ta.atr(len)
upperBand = src + factor * atr
lowerBand = src - factor * atr
prevLowerBand = nz(lowerBand[1])
prevUpperBand = nz(upperBand[1])
lowerBand := lowerBand > prevLowerBand or close[1] < prevLowerBand ? lowerBand : prevLowerBand
upperBand := upperBand < prevUpperBand or close[1] > prevUpperBand ? upperBand : prevUpperBand
int direction = na
float superTrend = na
prevSuperTrend = superTrend[1]
if prevSuperTrend == prevUpperBand
direction := close > upperBand ? 1 : -1
else
direction := close < lowerBand ? -1 : 1
superTrend := direction == 1 ? lowerBand : direction == -1 ? upperBand : na
// ───────────── CALCULATIONS ─────────────
green = #00DD00
red = #DD0000
avgOC = math.avg(open, close)
ema150 = ta.ema(close, 150)
ema250 = ta.ema(close, 250)
trendcloud = supertrend(ohlc4, periodTrendCloud == "Long term" ? 7 : 4, 10)
hmaRaw = ta.hma(close, fastTrendCloudLen)
hma = fastTrendCloud ? hmaRaw : na
// ───────────── PLOTS ─────────────
// "New" cloud: EMA 150 vs EMA 250
fill(plot(showTrendCloud and periodTrendCloud == "New" ? ema150 : na, "EMA 150", na, editable=false),
plot(showTrendCloud and periodTrendCloud == "New" ? ema250 : na, "EMA 250", na, editable=false),
ema150 > ema250 ? color.new(color.green, 70) : ema150 < ema250 ? color.new(color.red, 70) : na)
// "Short term" / "Long term" cloud: Supertrend line vs price
p0 = plot(avgOC, "Avg OC", na, editable=false)
fill(plot(showTrendCloud and periodTrendCloud != "New" and trendcloud != 0 and close > trendcloud ? trendcloud : na, "Trend Up", color.green, 1, plot.style_linebr, editable=false), p0, color.new(color.green, 90))
fill(plot(showTrendCloud and periodTrendCloud != "New" and trendcloud != 0 and close < trendcloud ? trendcloud : na, "Trend Down", color.red, 1, plot.style_linebr, editable=false), p0, color.new(color.red, 90))
// Fast trend cloud: HMA vs HMA 2 bars back
fill(plot(hma, "HMA", hma > hma[2] ? green : hma < hma[2] ? red : na, editable=false),
plot(hma[2], "HMA[2]", hma > hma[2] ? green : hma < hma[2] ? red : na, editable=false),
hma > hma[2] ? green : hma < hma[2] ? red : na)