本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Developing FAB4 Zone", overlay=true)
// ── Inputs ──
smaFastLen = input.int(20, "Fast SMA Length", minval=1)
smaSlowLen = input.int(200, "Slow SMA Length", minval=1)
rangeMinutes = input.int(45, "Rolling Range (Minutes)", minval=2)
showSMAs = input.bool(true, "Show 20 & 200 SMA")
showZone = input.bool(true, "Show Developing Zone")
showRange = input.bool(true, "Show Rolling High/Low")
// ── Calculate lookback ──
barMinutes = timeframe.in_seconds() / 60.0
barsNeeded = math.max(1, int(math.ceil(rangeMinutes / barMinutes)))
// ── Moving averages ──
sma20 = ta.sma(close, smaFastLen)
sma200 = ta.sma(close, smaSlowLen)
// ── Reset rolling range at start of each day ──
newDay = timeframe.change("D")
barsToday = nz(ta.barssince(newDay), 0) + 1
effectiveBars = math.max(1, math.min(barsNeeded, barsToday))
rangeHigh = ta.highest(high, effectiveBars)
rangeLow = ta.lowest(low, effectiveBars)
// ── Developing FAB4 zone ──
// Zone includes the 20 SMA, 200 SMA, current close,
// and rolling 45-minute high/low.
zoneHigh = math.max(
math.max(sma20, sma200),
math.max(close, rangeHigh))
zoneLow = math.min(
math.min(sma20, sma200),
math.min(close, rangeLow))
// ── Plot moving averages ──
plot(showSMAs ? sma20 : na, title="20 SMA",
color=color.orange, linewidth=2)
plot(showSMAs ? sma200 : na, title="200 SMA",
color=color.blue, linewidth=2)
// ── Plot rolling high and low ──
plot(showRange ? rangeHigh : na, title="Last 45m High",
color=color.green, linewidth=1,
style=plot.style_stepline)
plot(showRange ? rangeLow : na, title="Last 45m Low",
color=color.red, linewidth=1,
style=plot.style_stepline)
// ── Plot developing zone ──
pHigh = plot(showZone ? zoneHigh : na,
title="FAB4 Zone High",
color=color.lime, linewidth=2)
pLow = plot(showZone ? zoneLow : na,
title="FAB4 Zone Low",
color=color.fuchsia, linewidth=2)
// ── Shade the zone ──
fill(pHigh, pLow,
color=showZone ? color.new(color.aqua, 88) : na,
title="Developing FAB4 Zone")