本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script™ code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ingtian
//@version=6
indicator("Guppy Multiple Moving Average (GMMA) Scaled", "GMMA", overlay = true)
// ─── Inputs ───────────────────────────────────────────────────────────────────
string SCALED = "Scaled: 30–60 / 120–240"
string CLASSIC = "Classic Guppy: 3–15 / 30–60"
string preset = input.string(SCALED, "Periods", options = [SCALED, CLASSIC], group = "Averages",
tooltip = "Scaled: short group 30, 36 … 60 and long group 4× that (120 … 240). Its third long EMA is drawn thicker: at multiplier 1 it is the 168 EMA, one week of 1h bars on a 24/7 market.\nClassic: the standard Guppy periods 3, 5, 8, 10, 12, 15 and 30, 35, 40, 45, 50, 60.")
int mult = input.int(1, "Period multiplier", minval = 1, group = "Averages",
tooltip = "Multiplies every period. 2 doubles all twelve, e.g. to keep the 1h look on a 30m chart.")
float src = input.source(close, "Source", group = "Averages")
color shortCol = input.color(#FF8D1E, "Short group", group = "Style")
color longCol = input.color(#13FFFF, "Long group", group = "Style")
bool shade = input.bool(true, "Shade each group", group = "Style")
bool signals = input.bool(true, "Label full group separations", group = "Signals",
tooltip = "Bull: the lowest short-group EMA crosses above the highest long-group EMA, so the whole short group is now above the long group. Bear is the mirror case. Labels print only once the bar has closed, and none are drawn until the longest EMA has warmed up.")
color bullCol = input.color(#26A69A, "Bull label", group = "Signals")
color bearCol = input.color(#EF5350, "Bear label", group = "Signals")
// ─── Periods ──────────────────────────────────────────────────────────────────
bool classic = preset == CLASSIC
int s1 = mult * (classic ? 3 : 30)
int s2 = mult * (classic ? 5 : 36)
int s3 = mult * (classic ? 8 : 42)
int s4 = mult * (classic ? 10 : 48)
int s5 = mult * (classic ? 12 : 54)
int s6 = mult * (classic ? 15 : 60)
int l1 = mult * (classic ? 30 : 120)
int l2 = mult * (classic ? 35 : 144)
int l3 = mult * (classic ? 40 : 168)
int l4 = mult * (classic ? 45 : 192)
int l5 = mult * (classic ? 50 : 216)
int l6 = mult * (classic ? 60 : 240)
// ─── Averages ─────────────────────────────────────────────────────────────────
float e1 = ta.ema(src, s1)
float e2 = ta.ema(src, s2)
float e3 = ta.ema(src, s3)
float e4 = ta.ema(src, s4)
float e5 = ta.ema(src, s5)
float e6 = ta.ema(src, s6)
float e7 = ta.ema(src, l1)
float e8 = ta.ema(src, l2)
float e9 = ta.ema(src, l3)
float e10 = ta.ema(src, l4)
float e11 = ta.ema(src, l5)
float e12 = ta.ema(src, l6)
plot(e1, "Short EMA 1", shortCol)
plot(e2, "Short EMA 2", shortCol)
plot(e3, "Short EMA 3", shortCol)
plot(e4, "Short EMA 4", shortCol)
plot(e5, "Short EMA 5", shortCol)
plot(e6, "Short EMA 6", shortCol)
plot(e7, "Long EMA 1", longCol)
plot(e8, "Long EMA 2", longCol)
plot(e9, "Long EMA 3", longCol, classic ? 1 : 2)
plot(e10, "Long EMA 4", longCol)
plot(e11, "Long EMA 5", longCol)
plot(e12, "Long EMA 6", longCol)
// ─── Group bands ──────────────────────────────────────────────────────────────
float shortHi = math.max(e1, e2, e3, e4, e5, e6)
float shortLo = math.min(e1, e2, e3, e4, e5, e6)
float longHi = math.max(e7, e8, e9, e10, e11, e12)
float longLo = math.min(e7, e8, e9, e10, e11, e12)
pShortHi = plot(shortHi, "Short group high", display = display.none, editable = false)
pShortLo = plot(shortLo, "Short group low", display = display.none, editable = false)
pLongHi = plot(longHi, "Long group high", display = display.none, editable = false)
pLongLo = plot(longLo, "Long group low", display = display.none, editable = false)
fill(pShortHi, pShortLo, shade ? color.new(shortCol, 85) : na, "Short group shade")
fill(pLongHi, pLongLo, shade ? color.new(longCol, 85) : na, "Long group shade")
// ─── Signals ──────────────────────────────────────────────────────────────────
// ta.* calls come first: v6 `and` is lazy, and these must run on every bar to keep their history.
// The groups mean nothing until the longest EMA has seen l6 bars.
bool ready = bar_index >= l6
bool bull = ta.crossover(shortLo, longHi) and ready and barstate.isconfirmed
bool bear = ta.crossunder(shortHi, longLo) and ready and barstate.isconfirmed
plotshape(signals and bull, "Bull separation", shape.labelup, location.belowbar, bullCol, text = "Bull", textcolor = color.white, size = size.small)
plotshape(signals and bear, "Bear separation", shape.labeldown, location.abovebar, bearCol, text = "Bear", textcolor = color.white, size = size.small)
alertcondition(bull, "GMMA bull separation", "{{ticker}} {{interval}}: GMMA short group closed fully above the long group")
alertcondition(bear, "GMMA bear separation", "{{ticker}} {{interval}}: GMMA short group closed fully below the long group")