本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// ============================================================================
// Elliott Wave Impulse 12345, ABC & Fibonacci Targets [LunqFX]
// ----------------------------------------------------------------------------
// Counts Elliott waves live on confirmed swings: the five-wave impulse and
// the A-B-C correction after it. Each step is checked against the three hard
// rules of the wave principle, the next wave is projected with Fibonacci
// ratios, every wave carries its measured ratio, and every finished count
// goes into a record of how waves actually behave on this symbol.
//
// NON-REPAINTING: everything is decided on closed bars from confirmed pivots.
// The end of a running wave moves only when a new extreme is confirmed.
// No request.security, no lookahead.
// ============================================================================
indicator("Elliott Wave Impulse 12345, ABC & Fibonacci Targets [LunqFX]", "Elliott Wave [LunqFX]",
overlay = true, max_lines_count = 300, max_labels_count = 400, max_polylines_count = 80)
// ─────────────────────────────────────────────────────────────────────────
// INPUTS
// ─────────────────────────────────────────────────────────────────────────
gC = "Count"
side = input.string("Both", "Direction", options = ["Both", "Bullish", "Bearish"], group = gC)
pivLen = input.int(5, "Swing strength", minval = 2, maxval = 20, group = gC, tooltip = "Bars on each side that confirm a swing. Higher = larger waves.")
legMin = input.float(1.5, "Min. swing size (× ATR)", minval = 0.5, maxval = 10.0, step = 0.1, group = gC, tooltip = "Smaller moves against the current swing are ignored.")
w1Min = input.float(4.0, "Min. wave 1 (× ATR)", minval = 1.0, maxval = 20.0, step = 0.5, group = gC)
w3Min = input.float(1.0, "Min. wave 3 (× wave 1)", minval = 0.5, maxval = 3.0, step = 0.1, group = gC, tooltip = "A swing beyond wave 1 counts as the end of wave 3 only if wave 3 is at least this large.")
r2Min = input.float(0.382, "Wave 2 min. retracement", minval = 0.1, maxval = 0.8, step = 0.01, group = gC)
r2Max = input.float(0.886, "Wave 2 max. retracement", minval = 0.5, maxval = 0.99, step = 0.01, group = gC,
tooltip = "Applies when the count starts. Rule 1 still allows a later, deeper wave 2 as long as the start of wave 1 holds.")
maxAge = input.int(600, "Count expiry (bars)", minval = 100, maxval = 3000, group = gC)
gD = "Drawing"
showPath = input.bool(true, "Draw the wave path", group = gD)
showTgt = input.bool(true, "Fibonacci targets and invalidation", group = gD)
showRat = input.bool(true, "Measured ratio on wave labels", group = gD)
keepN = input.int(3, "Counts drawn", minval = 1, maxval = 20, group = gD, tooltip = "Finished counts older than this are removed from the chart. The record keeps all of them.")
lblSize = input.string("Normal", "Label size", options = ["Small", "Normal", "Large"], group = gD)
gP = "Panel"
showTbl = input.bool(true, "Show panel", group = gP)
tblPos = input.string("Top Right", "Position", options = ["Top Right", "Bottom Right", "Top Left", "Bottom Left"], group = gP)
tblSize = input.string("Normal", "Text size", options = ["Small", "Normal", "Large"], group = gP)
gA = "Alerts"
alWave = input.bool(true, "Alert: wave 3 confirmed and each finished wave", group = gA)
alEnd = input.bool(true, "Alert: impulse complete / ABC complete / rule broken", group = gA)
candOn_ = input.bool(true, "Neon candles", group = "Visuals")
candGlw = input.bool(true, "Glow candles", group = "Visuals", tooltip = "Each body is drawn in four bands that brighten towards the close, so the candle reads in the direction it moved. Off = flat translucent bodies.")
// ─────────────────────────────────────────────────────────────────────────
// THEME
// ─────────────────────────────────────────────────────────────────────────
bgLum = 0.2126 * color.r(chart.bg_color) + 0.7152 * color.g(chart.bg_color) + 0.0722 * color.b(chart.bg_color)
isLight = bgLum > 128
UP = isLight ? #6D4FE0 : #A58BFF // ultraviolet: bullish impulse
DN = isLight ? #D91E50 : #FF5E7E // rose: bearish impulse
ACC = isLight ? #0E9488 : #5CF2E6 // aqua: A-B-C correction
GREY = isLight ? #8A8F9C : #5F5A70
TXT = isLight ? #1A1626 : #F0EDF7
MUTE = isLight ? #625C72 : #A29BB5
PANEL = isLight ? #FFFFFF : #0E0A18
ROW = isLight ? #F3F0FA : #1A1428
INK = #0E0A18
NONE = color.new(color.black, 100)
lSize = lblSize == "Small" ? size.small : lblSize == "Large" ? size.large : size.normal
tSize = tblSize == "Small" ? size.small : tblSize == "Large" ? size.large : size.normal
px(float v) =>
str.tostring(v, format.mintick)
pct(int a, int b) =>
b > 0 ? str.tostring(a * 100.0 / b, "0") + "%" : "—"
// ─────────────────────────────────────────────────────────────────────────
// SERIES (computed on every bar)
// ─────────────────────────────────────────────────────────────────────────
atr = ta.atr(50)
ph = ta.pivothigh(high, pivLen, pivLen)
pl = ta.pivotlow(low, pivLen, pivLen)
pBar = bar_index - pivLen
// ─────────────────────────────────────────────────────────────────────────
// STATE
// stage = the last finished point of the count: 2 wave 2 · 3 wave 3 ·
// 4 wave 4 · 5 wave 5 · 6 A · 7 B · 8 C (stage 0 = searching)
// dir 1 = bullish impulse, -1 = bearish impulse
// Points are indexed 0..8; odd points lie in the direction of the impulse,
// even points against it.
// ─────────────────────────────────────────────────────────────────────────
var int stage = 0
var int reach = 0
var int dir = 0
var bool brk = false // a close beyond the end of wave 1 confirmed wave 3
var array<float> zP = array.new_float() // zigzag of confirmed swings
var array<int> zB = array.new_int()
var array<bool> zH = array.new_bool()
var array<float> wv = array.new_float(9, na)
var array<int> wb = array.new_int(9, na)
var array<label> wL = array.new<label>(9, na)
var array<polyline> pP = array.new<polyline>(4, na)
// running targets and invalidation: not filed, removed when the count moves on
var array<line> tLn = array.new<line>(2, na)
var array<label> tLb = array.new<label>(2, na)
var array<float> tY = array.new_float(2, na)
var array<bool> tHit = array.new_bool(2, false)
var array<int> tD = array.new_int(1, 0)
var array<line> iLn = array.new<line>(1, na)
var array<label> iLb = array.new<label>(1, na)
// record: index 0 = bullish, 1 = bearish
var array<int> rN = array.new_int(2, 0)
var array<int> r5 = array.new_int(2, 0)
var array<int> rC = array.new_int(2, 0)
var array<int> rFail = array.new_int(2, 0)
var array<float> sW = array.new_float(9, 0.0) // sum of each wave's ratio, indexed like the points
var array<int> nW = array.new_int(9, 0)
evStart = false
evBreak = false
evW = 0
evImp = false
evDone = false
evFail = false
evExp = false
evDrop = false
failTxt = ""
bumpI(array<int> a, int i, int add) =>
array.set(a, i, array.get(a, i) + add)
bumpF(array<float> a, int i, float add) =>
array.set(a, i, array.get(a, i) + add)
// ── drawing registry: every object of a count is filed under its id,
// so only the last "Counts drawn" stay on the chart
var int mId = 0
var array<label> gLb = array.new<label>()
var array<int> gLbI = array.new_int()
var array<polyline> gPl = array.new<polyline>()
var array<int> gPlI = array.new_int()
regLb(label o) =>
array.push(gLb, o)
array.push(gLbI, mId)
regPl(polyline o) =>
array.push(gPl, o)
array.push(gPlI, mId)
prune(int upTo) =>
while array.size(gLbI) > 0 and array.get(gLbI, 0) <= upTo
label.delete(array.shift(gLb))
array.shift(gLbI)
while array.size(gPlI) > 0 and array.get(gPlI, 0) <= upTo
polyline.delete(array.shift(gPl))
array.shift(gPlI)
// removes the drawings of a candidate that never reached wave 3
dropTail(int id) =>
while array.size(gLbI) > 0 and array.last(gLbI) == id
label.delete(array.pop(gLb))
array.pop(gLbI)
while array.size(gPlI) > 0 and array.last(gPlI) == id
polyline.delete(array.pop(gPl))
array.pop(gPlI)
P(int i) =>
array.get(wv, i)
leg(int a, int b) =>
math.abs(P(a) - P(b))
waveRatio(int i) =>
float r = na
if i == 2
r := leg(2, 1) / leg(1, 0)
else if i == 3
r := leg(3, 2) / leg(1, 0)
else if i == 4
r := leg(4, 3) / leg(3, 2)
else if i == 5
r := leg(5, 4) / leg(1, 0)
else if i == 6
r := leg(6, 5) / leg(5, 0)
else if i == 7
r := leg(7, 6) / leg(6, 5)
else if i == 8
r := leg(8, 7) / leg(6, 5)
r
waveTxt(int i) =>
name = i <= 5 ? str.tostring(i) : i == 6 ? "A" : i == 7 ? "B" : "C"
r = waveRatio(i)
showRat and not na(r) ? name + " · " + str.tostring(r, "0.00") : name
setPt(int i, float p, int b) =>
array.set(wv, i, p)
array.set(wb, i, b)
lb = array.get(wL, i)
txt = waveTxt(i)
if na(lb)
isHighPt = (i % 2 == 1) == (dir == 1)
c = i == 0 ? GREY : i <= 5 ? (dir == 1 ? UP : DN) : ACC
nl = label.new(b, p, txt, style = isHighPt ? label.style_label_down : label.style_label_up, color = c, textcolor = i == 0 ? color.white : INK, size = lSize)
regLb(nl)
array.set(wL, i, nl)
else
label.set_xy(lb, b, p)
label.set_text(lb, txt)
clearPt(int i) =>
label.delete(array.get(wL, i))
array.set(wL, i, na)
array.set(wv, i, na)
array.set(wb, i, na)
// wave path: impulse in the direction colour, correction in aqua, each with a wide glow
redrawPath(int upTo) =>
for k = 0 to 3
polyline.delete(array.get(pP, k))
array.set(pP, k, na)
if showPath
c = dir == 1 ? UP : DN
a1 = array.new<chart.point>()
for k = 0 to math.min(upTo, 5)
array.push(a1, chart.point.from_index(array.get(wb, k), P(k)))
g1 = polyline.new(a1, line_color = color.new(c, 86), line_width = 8)
l1 = polyline.new(a1, line_color = color.new(c, 5), line_width = 2)
regPl(g1)
regPl(l1)
array.set(pP, 0, g1)
array.set(pP, 1, l1)
if upTo > 5
a2 = array.new<chart.point>()
for k = 5 to upTo
array.push(a2, chart.point.from_index(array.get(wb, k), P(k)))
g2 = polyline.new(a2, line_color = color.new(ACC, 86), line_width = 8)
l2 = polyline.new(a2, line_color = color.new(ACC, 5), line_width = 2, line_style = line.style_dashed)
regPl(g2)
regPl(l2)
array.set(pP, 2, g2)
array.set(pP, 3, l2)
clearT() =>
for k = 0 to 1
line.delete(array.get(tLn, k))
label.delete(array.get(tLb, k))
array.set(tLn, k, na)
array.set(tLb, k, na)
array.set(tY, k, na)
array.set(tHit, k, false)
line.delete(array.get(iLn, 0))
label.delete(array.get(iLb, 0))
array.set(iLn, 0, na)
array.set(iLb, 0, na)
// projects the next wave from the point the count has just reached
refreshT(int st) =>
clearT()
if showTgt and st >= 2 and st <= 7
float y1 = na
float y2 = na
n1 = ""
n2 = ""
td = dir
c = dir == 1 ? UP : DN
if st == 2
y1 := P(2) + dir * 1.618 * leg(1, 0)
y2 := P(2) + dir * 2.618 * leg(1, 0)
n1 := "W3 · 1.618"
n2 := "W3 · 2.618"
else if st == 3
y1 := P(3) - dir * 0.382 * leg(3, 2)
y2 := P(3) - dir * 0.5 * leg(3, 2)
n1 := "W4 · 0.382"
n2 := "W4 · 0.5"
td := -dir
else if st == 4
y1 := P(4) + dir * 0.618 * leg(1, 0)
y2 := P(4) + dir * leg(1, 0)
n1 := "W5 · 0.618"
n2 := "W5 · 1.0"
else if st == 5
y1 := P(5) - dir * 0.382 * leg(5, 0)
y2 := P(5) - dir * 0.618 * leg(5, 0)
n1 := "A · 0.382"
n2 := "A · 0.618"
td := -dir
c := ACC
else if st == 6
y1 := P(6) + dir * 0.5 * leg(6, 5)
y2 := P(6) + dir * 0.786 * leg(6, 5)
n1 := "B · 0.5"
n2 := "B · 0.786"
c := ACC
else
y1 := P(7) - dir * leg(6, 5)
y2 := P(7) - dir * 1.618 * leg(6, 5)
n1 := "C · 1.0"
n2 := "C · 1.618"
td := -dir
c := ACC
array.set(tD, 0, td)
array.set(tY, 0, y1)
array.set(tY, 1, y2)
array.set(tLn, 0, line.new(bar_index, y1, bar_index + 4, y1, color = color.new(c, 10), width = 2))
array.set(tLn, 1, line.new(bar_index, y2, bar_index + 4, y2, color = color.new(c, 10), width = 2, style = line.style_dashed))
array.set(tLb, 0, label.new(bar_index + 4, y1, n1 + " " + px(y1), style = label.style_label_left, color = INK, textcolor = c, size = lSize))
array.set(tLb, 1, label.new(bar_index + 4, y2, n2 + " " + px(y2), style = label.style_label_left, color = INK, textcolor = c, size = lSize))
if st <= 4
yi = st == 2 ? P(0) : P(1)
array.set(iLn, 0, line.new(bar_index, yi, bar_index + 4, yi, color = color.new(GREY, 10), style = line.style_dotted))
array.set(iLb, 0, label.new(bar_index + 4, yi, (st == 2 ? "INVALID · rule 1 " : "INVALID · rule 3 ") + px(yi), style = label.style_label_left, color = INK, textcolor = MUTE, size = lSize))
// ─────────────────────────────────────────────────────────────────────────
// COUNT — closed bars only
// ─────────────────────────────────────────────────────────────────────────
if barstate.isconfirmed and not na(atr)
zChanged = false
// ── closes: wave 3 confirmation, rules 1 and 3, expiry
if stage == 2
if (P(0) - close) * dir > 0
evDrop := true
else if not brk and (close - P(1)) * dir > 0
brk := true
evBreak := true
else if stage == 3 or stage == 4
if (P(1) - close) * dir > 0
evFail := true
failTxt := "✕ RULE 3 · wave 4 in wave 1"
if stage >= 2 and not evDrop and not evFail and bar_index - array.get(wb, 0) > maxAge
if reach >= 3
evExp := true
else
evDrop := true
// ── target ticks
if stage >= 2
td = array.get(tD, 0)
fav = td == 1 ? high : low
for k = 0 to 1
y = array.get(tY, k)
if not na(y) and not array.get(tHit, k) and (fav - y) * td >= 0
array.set(tHit, k, true)
lb = array.get(tLb, k)
label.set_text(lb, "✓ " + label.get_text(lb))
// ── confirmed swings
lastIsHigh = array.size(zH) > 0 and array.last(zH)
for i = 0 to 1
evH = i == 0 ? not lastIsHigh : lastIsHigh
pv = evH ? ph : pl
if not na(pv)
accepted = false
n = array.size(zP)
if n == 0
array.push(zP, pv)
array.push(zB, pBar)
array.push(zH, evH)
accepted := true
else if array.last(zH) == evH
if (pv - array.last(zP)) * (evH ? 1 : -1) > 0
array.set(zP, n - 1, pv)
array.set(zB, n - 1, pBar)
accepted := true
else if (pv - array.last(zP)) * (evH ? 1 : -1) >= legMin * atr and pBar > array.last(zB)
array.push(zP, pv)
array.push(zB, pBar)
array.push(zH, evH)
accepted := true
if array.size(zP) > 8
array.shift(zP)
array.shift(zB)
array.shift(zH)
if accepted
zChanged := true
// ── the count follows the swing
if accepted and stage >= 2 and not evDrop and not evFail and not evExp
isW = evH == (dir == 1) // a swing in the direction of the impulse
prev = stage
if stage == 2
if isW
if (pv - P(1)) * dir > 0 and (pv - P(2)) * dir >= w3Min * leg(1, 0)
setPt(3, pv, pBar)
stage := 3
else if (P(0) - pv) * dir > 0
evDrop := true
else if (P(2) - pv) * dir > 0
setPt(2, pv, pBar)
else if stage == 3
if isW
if (pv - P(3)) * dir > 0
setPt(3, pv, pBar)
else if (P(1) - pv) * dir > 0
evFail := true
failTxt := "✕ RULE 3 · wave 4 in wave 1"
else
setPt(4, pv, pBar)
stage := 4
else if stage == 4
if isW
if (pv - P(3)) * dir > 0
setPt(5, pv, pBar)
stage := 5
else if (P(1) - pv) * dir > 0
evFail := true
failTxt := "✕ RULE 3 · wave 4 in wave 1"
else if (P(4) - pv) * dir > 0
setPt(4, pv, pBar)
else if stage == 5
if isW
if (pv - P(5)) * dir > 0
setPt(5, pv, pBar)
else
setPt(6, pv, pBar)
stage := 6
else if stage == 6
if isW
if (pv - P(5)) * dir > 0
clearPt(6)
setPt(5, pv, pBar)
stage := 5
else
setPt(7, pv, pBar)
stage := 7
else if (P(6) - pv) * dir > 0
setPt(6, pv, pBar)
else if stage == 7
if isW
if (pv - P(5)) * dir > 0
clearPt(7)
clearPt(6)
setPt(5, pv, pBar)
stage := 5
else if (pv - P(7)) * dir > 0
setPt(7, pv, pBar)
else if (P(6) - pv) * dir > 0
setPt(8, pv, pBar)
stage := 8
evDone := true
// rule 2: wave 3 may not be the shortest of 1, 3 and 5
if stage == 5 and leg(3, 2) < leg(1, 0) and leg(3, 2) < leg(5, 4)
evFail := true
failTxt := "✕ RULE 2 · wave 3 shortest"
if stage > reach
reach := stage
evW := stage
evImp := stage == 5 and not evFail
if not evDrop
redrawPath(stage)
if not evFail and not evDone
refreshT(stage)
// ── endings
if evDrop
clearT()
dropTail(mId)
stage := 0
else if evFail or evDone or evExp
if reach >= 3
d = dir == 1 ? 0 : 1
bumpI(rN, d, 1)
bumpI(r5, d, reach >= 5 and not (evFail and reach == 5) ? 1 : 0)
bumpI(rC, d, evDone ? 1 : 0)
bumpI(rFail, d, evFail ? 1 : 0)
for k = 2 to 8
rk = waveRatio(k)
if not na(rk)
bumpF(sW, k, rk)
bumpI(nW, k, 1)
if evFail
regLb(label.new(bar_index, dir == 1 ? low : high, failTxt, style = dir == 1 ? label.style_label_up : label.style_label_down, color = GREY, textcolor = color.white, size = lSize))
clearT()
stage := 0
prune(mId - keepN)
// ── searching: the last three swings may be waves 1 and 2
if stage == 0 and zChanged and array.size(zP) >= 3
n = array.size(zP)
pA = array.get(zP, n - 3)
pB = array.get(zP, n - 2)
pC = array.get(zP, n - 1)
dN = array.get(zH, n - 1) ? -1 : 1
len1 = math.abs(pB - pA)
retr = len1 > 0 ? math.abs(pC - pB) / len1 : na
// wave 1 must start from a new swing extreme: the trend before it has just ended
fresh = n < 5 or (pA - array.get(zP, n - 5)) * dN < 0
allowed = side == "Both" or (side == "Bullish" and dN == 1) or (side == "Bearish" and dN == -1)
if allowed and fresh and len1 >= w1Min * atr and retr >= r2Min and retr <= r2Max
mId += 1
dir := dN
stage := 2
reach := 2
brk := false
evStart := true
array.fill(wv, na)
array.fill(wb, na)
array.fill(wL, na)
array.fill(pP, na)
array.set(wv, 0, pA)
array.set(wv, 1, pB)
array.set(wv, 2, pC)
setPt(0, pA, array.get(zB, n - 3))
setPt(1, pB, array.get(zB, n - 2))
setPt(2, pC, array.get(zB, n - 1))
redrawPath(2)
refreshT(2)
// running targets follow the current bar
if stage >= 2
for k = 0 to 1
if not na(array.get(tLn, k))
line.set_x2(array.get(tLn, k), bar_index + 4)
label.set_x(array.get(tLb, k), bar_index + 4)
if not na(array.get(iLn, 0))
line.set_x2(array.get(iLn, 0), bar_index + 4)
label.set_x(array.get(iLb, 0), bar_index + 4)
// ─────────────────────────────────────────────────────────────────────────
// PANEL — wave map: the shape of the count drawn in table cells, lit up to
// the running wave, with the numbers that matter below it
// ─────────────────────────────────────────────────────────────────────────
pos = tblPos == "Top Right" ? position.top_right : tblPos == "Bottom Right" ? position.bottom_right : tblPos == "Top Left" ? position.top_left : position.bottom_left
hSize = tblSize == "Small" ? size.normal : tblSize == "Large" ? size.huge : size.large
cellW = tblSize == "Small" ? 0.45 : tblSize == "Large" ? 0.8 : 0.6 // % of the chart
cellH = tblSize == "Small" ? 0.85 : tblSize == "Large" ? 1.45 : 1.1
MAP_C = 28
MAP_R = 11
var table tb = na
// wave ends on the map: column and row of points 0, 1..5, A, B, C
var array<int> mapC = array.from(0, 4, 7, 12, 15, 19, 22, 24, 27)
var array<int> mapR = array.from(9, 6, 7, 2, 4, 1, 5, 3, 8)
info(int c1, int c2, int r, string t, color fg, string sz, string al) =>
table.cell(tb, c1, r, t, text_color = fg, bgcolor = PANEL, text_size = sz, text_halign = al)
table.merge_cells(tb, c1, r, c2, r)
fmt(float v) =>
na(v) ? "—" : str.tostring(v, "0.00")
// the running wave measured against the same base as its finished ratio
liveRatio(int k) =>
base = k == 3 or k == 5 ? leg(1, 0) : k == 4 ? leg(3, 2) : k == 6 ? leg(5, 0) : leg(6, 5)
k >= 3 and k <= 8 and base > 0 ? math.abs(close - P(k - 1)) / base : na
if barstate.islast and showTbl
table.delete(tb) // rebuilt each time: merged cells cannot be merged twice
on = stage >= 2
mc = not on ? GREY : dir == 1 ? UP : DN
tb := table.new(pos, MAP_C, MAP_R + 6, bgcolor = PANEL, border_color = PANEL, border_width = 0, frame_color = color.new(mc, 40), frame_width = 1)
for r = 0 to MAP_R - 1
for c = 0 to MAP_C - 1
table.cell(tb, c, r, "", bgcolor = PANEL, width = cellW, height = cellH)
// the path; a bearish count is the same shape upside down
int prevR = na
for c = 0 to MAP_C - 1
seg = 1
while seg < 8 and c > array.get(mapC, seg)
seg += 1
c0 = array.get(mapC, seg - 1)
c1 = array.get(mapC, seg)
r0 = array.get(mapR, seg - 1)
r1 = array.get(mapR, seg)
rNow = int(math.round(r0 + (r1 - r0) * (c - c0) * 1.0 / (c1 - c0)))
base = seg <= 5 ? mc : (on ? ACC : GREY)
col = not on ? color.new(GREY, 75) : seg <= stage ? base : seg == stage + 1 ? color.new(base, 45) : color.new(base, 86)
fromR = na(prevR) ? rNow : prevR
for rr = math.min(fromR, rNow) to math.max(fromR, rNow)
table.cell_set_bgcolor(tb, c, on and dir == -1 ? MAP_R - 1 - rr : rr, col)
prevR := rNow
// wave names beside the turning points
for k = 1 to 8
c = array.get(mapC, k)
rl = array.get(mapR, k) + (k % 2 == 1 ? -1 : 1)
rw = on and dir == -1 ? MAP_R - 1 - rl : rl
c1 = math.max(c - 1, 0)
c2 = math.min(c + 1, MAP_C - 1)
lit = on and k <= stage + 1
table.cell_set_text(tb, c1, rw, k <= 5 ? str.tostring(k) : k == 6 ? "A" : k == 7 ? "B" : "C")
table.cell_set_text_color(tb, c1, rw, lit ? TXT : MUTE)
table.cell_set_text_size(tb, c1, rw, size.small)
table.merge_cells(tb, c1, rw, c2, rw)
// headline
running = stage + 1
hero = not on ? "NO COUNT" : "WAVE " + (running <= 5 ? str.tostring(running) : running == 6 ? "A" : running == 7 ? "B" : "C")
info(0, 16, MAP_R, hero, not on ? MUTE : stage == 2 and not brk ? color.new(mc, 45) : mc, hSize, text.align_left) // dimmed until wave 3 is confirmed
info(17, MAP_C - 1, MAP_R, not on ? "searching" : dir == 1 ? "▲ bullish" : "▼ bearish", MUTE, tSize, text.align_right)
// now against usual, broken
nA = array.sum(rN)
nk = on and running <= 8 ? array.get(nW, running) : 0
live = on ? liveRatio(running) : na
info(0, 8, MAP_R + 1, "NOW", MUTE, size.small, text.align_left)
info(9, 18, MAP_R + 1, "USUAL", MUTE, size.small, text.align_left)
info(19, MAP_C - 1, MAP_R + 1, "BROKEN", MUTE, size.small, text.align_left)
info(0, 8, MAP_R + 2, fmt(live), on ? TXT : MUTE, tSize, text.align_left)
info(9, 18, MAP_R + 2, nk > 0 ? fmt(array.get(sW, running) / nk) : "—", on ? TXT : MUTE, tSize, text.align_left)
info(19, MAP_C - 1, MAP_R + 2, pct(array.sum(rFail), nA), TXT, tSize, text.align_left)
// next levels, rules, record
y1 = array.get(tY, 0)
y2 = array.get(tY, 1)
info(0, MAP_C - 1, MAP_R + 3, on and not na(y1) ? "Next " + px(y1) + " · " + px(y2) : "Next —", on ? mc : MUTE, tSize, text.align_left)
r2 = not on or stage < 3 ? "·" : stage >= 5 or leg(3, 2) >= leg(1, 0) ? "✓" : "?"
r3 = not on or stage < 3 ? "·" : stage >= 4 ? "✓" : "?"
info(0, MAP_C - 1, MAP_R + 4, "Rules 1 " + (on ? "✓" : "·") + " 2 " + r2 + " 3 " + r3, on ? ACC : MUTE, tSize, text.align_left)
info(0, MAP_C - 1, MAP_R + 5, str.tostring(nA) + " counts · W5 " + pct(array.sum(r5), nA) + " · ABC " + pct(array.sum(rC), nA), MUTE, size.small, text.align_left)
// ─────────────────────────────────────────────────────────────────────────
// ALERTS
// ─────────────────────────────────────────────────────────────────────────
dirTxt = dir == 1 ? "bullish" : "bearish"
if alWave and evBreak
alert(syminfo.ticker + " Elliott Wave: wave 3 confirmed, " + dirTxt + " count closed beyond wave 1", alert.freq_once_per_bar_close)
if alWave and evW >= 3 and evW <= 4
alert(syminfo.ticker + " Elliott Wave: wave " + str.tostring(evW) + " finished, " + dirTxt + " count", alert.freq_once_per_bar_close)
if alEnd and evImp
alert(syminfo.ticker + " Elliott Wave: five-wave impulse complete, " + dirTxt + " count", alert.freq_once_per_bar_close)
if alEnd and evDone
alert(syminfo.ticker + " Elliott Wave: A-B-C correction complete, " + dirTxt + " count", alert.freq_once_per_bar_close)
if alEnd and evFail
alert(syminfo.ticker + " Elliott Wave: rule broken, " + dirTxt + " count ended", alert.freq_once_per_bar_close)
alertcondition(evBreak, "Wave 3 confirmed", "{{ticker}} Elliott Wave: wave 3 confirmed")
alertcondition(evImp, "Impulse complete", "{{ticker}} Elliott Wave: five-wave impulse complete")
alertcondition(evDone, "A-B-C complete", "{{ticker}} Elliott Wave: A-B-C correction complete")
alertcondition(evFail, "Rule broken", "{{ticker}} Elliott Wave: rule broken")
// ─────────────────────────────────────────────────────────────────────────
// GLOW CANDLES (LunqFX house style)
// ─────────────────────────────────────────────────────────────────────────
GLOW_UP_DARK = #A58BFF
GLOW_DN_DARK = #5CF2E6
GLOW_UP_LIGHT = #6D4FE0
GLOW_DN_LIGHT = #0E9488
glowUp = isLight ? GLOW_UP_LIGHT : GLOW_UP_DARK
glowDn = isLight ? GLOW_DN_LIGHT : GLOW_DN_DARK
glowEdge = close >= open ? glowUp : glowDn
glowOn = candOn_ and candGlw
GLOW_NONE = color.new(color.black, 100)
plotcandle(candOn_ and not glowOn ? open : na, high, low, close, "Candles", color = color.new(glowEdge, 24), wickcolor = color.new(glowEdge, 18), bordercolor = glowEdge, display = display.pane)
gQ = (close - open) / 4.0
plotcandle(glowOn ? open : na, glowOn ? math.max(open, close) : na, glowOn ? math.min(open, close) : na, glowOn ? close : na, "Glow mask", color = chart.bg_color, wickcolor = GLOW_NONE, bordercolor = chart.bg_color, display = display.pane)
plotcandle(glowOn ? open : na, glowOn ? math.max(open, open + gQ) : na, glowOn ? math.min(open, open + gQ) : na, glowOn ? open + gQ : na, "Glow band 1", color = color.new(glowEdge, 78), wickcolor = GLOW_NONE, bordercolor = GLOW_NONE, display = display.pane)
plotcandle(glowOn ? open + gQ : na, glowOn ? math.max(open + gQ, open + 2 * gQ) : na, glowOn ? math.min(open + gQ, open + 2 * gQ) : na, glowOn ? open + 2 * gQ : na, "Glow band 2", color = color.new(glowEdge, 58), wickcolor = GLOW_NONE, bordercolor = GLOW_NONE, display = display.pane)
plotcandle(glowOn ? open + 2 * gQ : na, glowOn ? math.max(open + 2 * gQ, open + 3 * gQ) : na, glowOn ? math.min(open + 2 * gQ, open + 3 * gQ) : na, glowOn ? open + 3 * gQ : na, "Glow band 3", color = color.new(glowEdge, 36), wickcolor = GLOW_NONE, bordercolor = GLOW_NONE, display = display.pane)
plotcandle(glowOn ? open + 3 * gQ : na, glowOn ? math.max(open + 3 * gQ, close) : na, glowOn ? math.min(open + 3 * gQ, close) : na, glowOn ? close : na, "Glow band 4", color = color.new(glowEdge, 8), wickcolor = GLOW_NONE, bordercolor = GLOW_NONE, display = display.pane)
plotcandle(glowOn ? open : na, glowOn ? high : na, glowOn ? low : na, glowOn ? close : na, "Glow wick", color = GLOW_NONE, wickcolor = color.new(glowEdge, 10), bordercolor = color.new(glowEdge, 30), display = display.pane)