本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//==============================================================================
// ELLIOTT WAVE + ICHIMOKU -LINE + TAITO SUCHI TIME CYCLE (HENKA-BI)
// Pine Script v6 - universal (any symbol / any timeframe)
//==============================================================================
// DESCRIPTION
// ---------------------------------------------------------------------------
// As per Elliott, we are in wave 3 of one lesser degree.
// This wave-3 scenario is supported by the Ichimoku 5-line analysis:
// * SSA / SSB (the cloud) pointing up
// * Tenkan-sen and Kijun-sen pointing up
// * Chikou span is "free" (no price / cloud / line in its way)
//
// 1. Ichimoku (9 / 26 / 52 / 26): Tenkan (blue), Kijun (red), Chikou (green),
// SSA (green), SSB (red), cloud filled green when SSA > SSB, red otherwise.
// 2. Vertical teal lines = Taito Suchi time cycle. They are spaced exactly
// 12 bars apart starting from the major swing low (anchor).
// 3. Each cycle line lands on a wave turning point:
// line 0 : anchor low (start of wave i)
// line 1 : low (wave ii) -> "12 bars - low to low"
// line 2 : high (wave 1) -> "12 bars - low to high"
// line 3 : low (wave 2) -> "Flat consolidation"
// line 4 : projected high (wave 3) -> Henka-bi (time target)
// Waves 4 and 5 are projected further to the right.
// 4. Red horizontal levels 0 / 1 / 2 / 3 :
// level 0 = low of wave ii
// level 1 = high of wave 1
// unit = level1 - level0
// level n = level0 + n * unit (n = 0,1,2,3 ...)
// Levels 2 and 3 are labelled "1 E" and "2 E" (extension targets).
// "1 E" = wave-1 amplitude projected from the wave-1 high (100% / equal leg).
// 5. Red roman numerals (i ii iii iv v) = sub-waves of the lower degree.
// Purple circled numbers (1)(2)(3)(4)(5) = waves of one higher degree.
// 6. Dotted horizontal line = last price.
// 7. The note under line 3 is generated automatically: which E-target is next,
// the number of bars remaining, and the calendar date of the Henka-bi.
// The script also supports bearish (mirror) structures: direction can be
// Auto / Bullish / Bearish.
//==============================================================================
//@version=6
indicator(title = 'Elliott Wave & Taito Suchi Time Cycle (Henka-bi)', shorttitle = 'Ichimoku-Time Cycle', overlay = true, max_bars_back = 1000, max_lines_count = 200, max_labels_count = 200)
//------------------------------------------------------------------------------
// INPUTS
//------------------------------------------------------------------------------
G1 = 'Ichimoku Kinko Hyo'
showIchi = input.bool(true, 'Show Ichimoku', group = G1)
tenkanLen = input.int(9, 'Tenkan-sen length', minval = 1, group = G1)
kijunLen = input.int(26, 'Kijun-sen length', minval = 1, group = G1)
senkouBLen = input.int(52, 'Senkou Span B length', minval = 1, group = G1)
disp = input.int(26, 'Displacement (Chikou / cloud)', minval = 2, group = G1)
G2 = 'Structure / anchor'
dirMode = input.string('Auto', 'Direction', options = ['Auto', 'Bullish', 'Bearish'], group = G2)
anchorLook = input.int(100, 'Anchor lookback (bars)', minval = 20, maxval = 900, group = G2, tooltip = 'Anchor = lowest low (bullish) / highest high (bearish) in this many bars.')
anchorManual = input.int(0, 'Manual anchor: bars back (0 = auto)', minval = 0, maxval = 900, group = G2)
pivTol = input.int(3, 'Turning-point search tolerance (+/- bars)', minval = 0, maxval = 10, group = G2, tooltip = 'Each wave extreme is searched within +/- this many bars around its cycle line.')
G3 = 'Taito Suchi time cycle'
showCyc = input.bool(true, 'Show time-cycle lines', group = G3)
cycLen = input.int(12, 'Cycle length (bars)', minval = 2, group = G3)
cycCount = input.int(5, 'Number of cycle lines (incl. anchor)', minval = 2, maxval = 20, group = G3)
showWinTx = input.bool(true, 'Show window notes (low to low, Henka-bi ...)', group = G3)
flatMult = input.float(3.0, 'Flat-consolidation threshold (window range / ATR)', minval = 0.5, step = 0.5, group = G3)
labelDrop = input.float(0.65, 'Note drop below anchor (in wave units)', minval = 0.0, step = 0.05, group = G3)
G4 = 'Elliott levels & waves'
showLevels = input.bool(true, 'Show 0 / 1 / 2 / 3 levels', group = G4)
levelCount = input.int(4, 'Number of levels (0 .. n-1)', minval = 2, maxval = 8, group = G4)
lblOffset = input.int(35, 'Level label offset to the right (bars)', minval = 1, maxval = 300, group = G4)
showWaves = input.bool(true, 'Show roman / circled wave labels', group = G4)
showProj = input.bool(true, 'Project wave 4 and wave 5', group = G4)
p4Cyc = input.float(2.0, 'Wave 4 time: cycles after wave-3 line', minval = 0.25, step = 0.25, group = G4, tooltip = 'Distance from the wave-3 cycle line, in multiples of the cycle length.')
p5Cyc = input.float(2.25, 'Wave 5 time: cycles after wave-3 line', minval = 0.25, step = 0.25, group = G4)
p4Ret = input.float(1.236, 'Wave 4 depth: x wave-3 span below wave-3 target', minval = 0.1, step = 0.001, group = G4, tooltip = 'Fibonacci multiple of the wave 0 -> 3 span, projected back from the wave-3 target.')
p5Ret = input.float(1.20, 'Wave 5 depth: x wave-3 span below wave-3 target', minval = 0.1, step = 0.001, group = G4)
showLast = input.bool(true, 'Dotted last-price line', group = G4)
G5 = 'Analysis table'
showTbl = input.bool(true, 'Show Ichimoku 5-line / time-cycle table', group = G5)
G6 = 'Colours'
cTenkan = input.color(#2962FF, 'Tenkan-sen', group = G6)
cKijun = input.color(#F23645, 'Kijun-sen', group = G6)
cChikou = input.color(#43A047, 'Chikou span', group = G6)
cSSA = input.color(#43A047, 'Senkou Span A', group = G6)
cSSB = input.color(#F23645, 'Senkou Span B', group = G6)
cCloudUp = input.color(color.new(#43A047, 88), 'Cloud bullish', group = G6)
cCloudDn = input.color(color.new(#F23645, 88), 'Cloud bearish', group = G6)
cCycle = input.color(color.new(#26A69A, 45), 'Time-cycle lines', group = G6)
cLevel = input.color(#DC143C, 'Elliott levels', group = G6)
cRoman = input.color(#E53935, 'Roman sub-waves', group = G6)
cCircle = input.color(#5E35B1, 'Circled waves', group = G6)
cNote = input.color(#8B0000, 'Window notes', group = G6)
G7 = 'Text & font'
sizeOpts = array.from('Tiny', 'Small', 'Normal', 'Large', 'Huge')
fontChoice = input.string('Default', 'Font family', options = ['Default', 'Monospace'], group = G7, tooltip = 'Monospace gives fixed-width characters (good for aligned table values). Applies to all labels and the table.')
szLevel = input.string('Small', 'Level label size (0 / 1 / 2 / 3, E-targets)', options = ['Tiny', 'Small', 'Normal', 'Large', 'Huge'], group = G7)
szRoman = input.string('Small', 'Roman sub-wave size (i ii iii iv v)', options = ['Tiny', 'Small', 'Normal', 'Large', 'Huge'], group = G7)
szCircle = input.string('Large', 'Circled wave size (1)(2)(3)(4)(5)', options = ['Tiny', 'Small', 'Normal', 'Large', 'Huge'], group = G7)
szNote = input.string('Small', 'Window note size (low to low, Henka-bi ...)', options = ['Tiny', 'Small', 'Normal', 'Large', 'Huge'], group = G7)
szTable = input.string('Small', 'Analysis table text size', options = ['Tiny', 'Small', 'Normal', 'Large', 'Huge'], group = G7)
useBg = input.bool(true, 'Label background (masks lines behind text)', group = G7)
cBg = input.color(color.new(#FFFFFF, 15), 'Label background colour', group = G7, tooltip = 'Use a colour close to your chart background (e.g. dark grey on a dark theme) for a cleaner look.')
noteStagger = input.float(0.45, 'Stagger alternate window notes (wave units)', minval = 0.0, step = 0.05, group = G7, tooltip = 'Every second window note is dropped this much lower so notes do not collide. 0 = no stagger.')
//------------------------------------------------------------------------------
// TEXT HELPERS
//------------------------------------------------------------------------------
f_sz(string s) =>
switch s
'Tiny' => size.tiny
'Small' => size.small
'Normal' => size.normal
'Large' => size.large
'Huge' => size.huge
=> size.small
string fontFam = fontChoice == 'Monospace' ? font.family_monospace : font.family_default
string lvlSz = f_sz(szLevel)
string romSz = f_sz(szRoman)
string cirSz = f_sz(szCircle)
string notSz = f_sz(szNote)
string tblSz = f_sz(szTable)
//------------------------------------------------------------------------------
// ICHIMOKU
//------------------------------------------------------------------------------
donchian(int len) =>
math.avg(ta.lowest(len), ta.highest(len))
float tenkan = donchian(tenkanLen)
float kijun = donchian(kijunLen)
float ssa = math.avg(tenkan, kijun)
float ssb = donchian(senkouBLen)
plot(showIchi ? tenkan : na, 'Tenkan-sen', color = cTenkan, linewidth = 1)
plot(showIchi ? kijun : na, 'Kijun-sen', color = cKijun, linewidth = 1)
plot(showIchi ? close : na, 'Chikou span', color = cChikou, linewidth = 1, offset = -disp + 1)
pSSA = plot(showIchi ? ssa : na, 'Senkou Span A', color = cSSA, linewidth = 1, offset = disp - 1)
pSSB = plot(showIchi ? ssb : na, 'Senkou Span B', color = cSSB, linewidth = 1, offset = disp - 1)
fill(pSSA, pSSB, color = ssa > ssb ? cCloudUp : cCloudDn, title = 'Kumo (cloud)')
//------------------------------------------------------------------------------
// DIRECTION + ICHIMOKU 5-LINE CONDITIONS (evaluated every bar)
//------------------------------------------------------------------------------
bool isBull = dirMode == 'Bullish' ? true : dirMode == 'Bearish' ? false : close >= nz(kijun, close)
float atr = ta.atr(14)
int lowOff = ta.lowestbars(low, anchorLook)
int hiOff = ta.highestbars(high, anchorLook)
bool cloudOk = isBull ? ssa > ssb and ssa >= nz(ssa[1]) and ssb >= nz(ssb[1]) : ssa < ssb and ssa <= nz(ssa[1]) and ssb <= nz(ssb[1])
bool tenkanOk = isBull ? tenkan > nz(tenkan[1]) : tenkan < nz(tenkan[1])
bool kijunOk = isBull ? kijun >= nz(kijun[1]) : kijun <= nz(kijun[1])
// Chikou is "free" when today's close is clear of price, cloud (at its plotted position)
float hiAround = nz(ta.highest(high, 5)[disp - 2], high)
float loAround = nz(ta.lowest(low, 5)[disp - 2], low)
float cloudTopThen = math.max(nz(ssa[2 * disp - 1], ssa), nz(ssb[2 * disp - 1], ssb))
float cloudBotThen = math.min(nz(ssa[2 * disp - 1], ssa), nz(ssb[2 * disp - 1], ssb))
bool chikouOk = isBull ? close > hiAround and close > cloudTopThen : close < loAround and close < cloudBotThen
//------------------------------------------------------------------------------
// DRAWING CONTAINERS + HELPERS
//------------------------------------------------------------------------------
var array<line> lnArr = array.new<line>()
var array<label> lbArr = array.new<label>()
var table tbl = table.new(position.top_right, 2, 8, bgcolor = color.new(#2A2E39, 8), frame_color = color.new(color.gray, 40), frame_width = 1, border_color = color.new(color.gray, 60), border_width = 1)
// highest high (wantHigh) or lowest low between two bar indexes -> [price, barIndex]
f_ext(int fromB, int toB, bool wantHigh) =>
float best = wantHigh ? -1.0e10 : 1.0e10
int bestB = bar_index
int lo = math.max(math.max(fromB, 0), bar_index - 990)
int hi = math.min(toB, bar_index)
if lo <= hi
for b = lo to hi by 1
float v = wantHigh ? high[bar_index - b] : low[bar_index - b]
bool better = wantHigh ? v > best : v < best
if better
best := v
bestB := b
bestB
[best, bestB]
// calendar date of a future bar (skips weekends on daily non-crypto charts)
f_futureTime(int t0, int barsAhead) =>
int stepMs = timeframe.in_seconds(timeframe.period) * 1000
int t = t0
if timeframe.isdaily and syminfo.type != 'crypto'
int n = 0
while n < barsAhead
t := t + stepMs
int dw = dayofweek(t, syminfo.timezone)
if dw != dayofweek.saturday and dw != dayofweek.sunday
n := n + 1
n
else
t := t + barsAhead * stepMs
t
t
// label with selectable size + selectable font family
f_lbl(int x, float y, string t, color tc, string sty, string sz, bool bgOn = false) =>
color bgc = bgOn and useBg ? cBg : color.new(color.white, 100)
label lb = label.new(x, y, t, xloc = xloc.bar_index, yloc = yloc.price, color = bgc, style = sty, textcolor = tc, size = sz, textalign = text.align_left, text_font_family = fontFam)
array.push(lbArr, lb)
lb
f_line(int x1, float y1, int x2, float y2, color c, int w, string ext, string sty) =>
line ln = line.new(x1, y1, x2, y2, xloc = xloc.bar_index, extend = ext, color = c, width = w, style = sty)
array.push(lnArr, ln)
ln
// table cell with selectable size + selectable font family
f_cell(int col, int row, string t, color tc, string ha = text.align_center) =>
table.cell(tbl, col, row, t, text_color = tc, text_size = tblSz, text_halign = ha, text_font_family = fontFam)
//------------------------------------------------------------------------------
// MAIN (runs on the last bar only)
//------------------------------------------------------------------------------
if barstate.islast
// ---- clean previous drawings
for l in lnArr
line.delete(l)
array.clear(lnArr)
for lb in lbArr
label.delete(lb)
array.clear(lbArr)
int sgn = isBull ? 1 : -1
int anchorB = anchorManual > 0 ? bar_index - anchorManual : bar_index + (isBull ? lowOff : hiOff)
anchorB := math.max(anchorB, 0)
float anchorP = isBull ? low[bar_index - anchorB] : high[bar_index - anchorB]
// ---- wave turning points on the cycle lines (k = 0 .. 4)
// k=0 anchor, k=1 wave ii, k=2 wave 1, k=3 wave 2, k=4 wave 3
int maxK = 4
array<float> exP = array.new_float(maxK + 1, na)
array<int> exB = array.new_int(maxK + 1, 0)
array<bool> exOk = array.new_bool(maxK + 1, false)
array.set(exP, 0, anchorP)
array.set(exB, 0, anchorB)
array.set(exOk, 0, true)
for k = 1 to maxK by 1
int cbk = anchorB + k * cycLen
if cbk <= bar_index
bool wantHigh = k % 2 == 1 ? not isBull : isBull
[p, b] = f_ext(cbk - pivTol, cbk + pivTol, wantHigh)
array.set(exP, k, p)
array.set(exB, k, b)
array.set(exOk, k, true)
bool ok2 = array.get(exOk, 2)
float L0 = array.get(exP, 1)
float H1 = array.get(exP, 2)
int x0 = array.get(exB, 1)
float U = H1 - L0
bool validStruct = ok2 and U * sgn > 0
float Uabs = validStruct ? math.abs(U) : atr * 5
// ---- which E-target is next?
int reachedK = 0
if validStruct
[hh, hb] = f_ext(x0, bar_index, isBull)
for kk = 0 to levelCount - 1 by 1
float pr = L0 + kk * U
if isBull and hh >= pr or not isBull and hh <= pr
reachedK := kk
reachedK
int tgtK = math.min(reachedK + 1, levelCount - 1)
int eNum = math.max(tgtK - 1, 1)
// ---- time-cycle vertical lines
if showCyc
for k = 0 to cycCount - 1 by 1
int xc = anchorB + k * cycLen
f_line(xc, close, xc, close + syminfo.mintick, cCycle, 1, extend.both, line.style_solid)
// ---- Elliott levels 0 / 1 / 2 / 3
if showLevels and validStruct
for kk = 0 to levelCount - 1 by 1
float pr = L0 + kk * U
f_line(x0, pr, x0 + 1, pr, cLevel, 2, extend.right, line.style_solid)
f_lbl(bar_index + lblOffset, pr, str.tostring(kk) + ' (' + str.tostring(pr, format.mintick) + ')', cLevel, label.style_label_lower_left, lvlSz, true)
if kk >= 2
f_lbl(bar_index + 11 + (kk - 2) * 7, pr - sgn * 0.06 * Uabs, str.tostring(kk - 1) + ' E', cLevel, label.style_label_up, lvlSz, true)
// ---- dotted last price
if showLast
f_line(bar_index - 1, close, bar_index, close, color.new(color.gray, 20), 1, extend.both, line.style_dotted)
// ---- Elliott wave labels
if showWaves and ok2
// wave i : with-trend extreme between anchor and cycle line 1
int cb1 = anchorB + cycLen
int cb2 = anchorB + 2 * cycLen
[iP, iB] = f_ext(anchorB, cb1, isBull)
f_lbl(iB, iP, 'i', cRoman, isBull ? label.style_label_down : label.style_label_up, romSz)
// wave ii
f_lbl(array.get(exB, 1), array.get(exP, 1), 'ii', cRoman, isBull ? label.style_label_up : label.style_label_down, romSz)
// sub-waves iii, iv inside wave 1 ; v = top of wave 1
if validStruct
int midEnd = cb1 + math.round(cycLen * 0.6)
[iiiP, iiiB] = f_ext(cb1, midEnd, isBull)
f_lbl(iiiB, iiiP, 'iii', cRoman, isBull ? label.style_label_down : label.style_label_up, romSz)
[ivP, ivB] = f_ext(iiiB, cb2, not isBull)
if ivB > iiiB
f_lbl(ivB, ivP, 'iv', cRoman, isBull ? label.style_label_up : label.style_label_down, romSz)
f_lbl(array.get(exB, 2), array.get(exP, 2), 'v', cRoman, isBull ? label.style_label_down : label.style_label_up, romSz)
// circled (1) (2) (3)
float off = 0.30 * Uabs * sgn
f_lbl(array.get(exB, 2), array.get(exP, 2) + off, '①', cCircle, isBull ? label.style_label_down : label.style_label_up, cirSz)
if array.get(exOk, 3)
f_lbl(array.get(exB, 3), array.get(exP, 3) - off, '②', cCircle, isBull ? label.style_label_up : label.style_label_down, cirSz)
int cb4 = anchorB + 4 * cycLen
if array.get(exOk, 4)
f_lbl(array.get(exB, 4), array.get(exP, 4) + off, '③', cCircle, isBull ? label.style_label_down : label.style_label_up, cirSz)
else // projected wave 3 on the 3-unit target at the Henka-bi cycle line
f_lbl(cb4, L0 + 3 * U + 0.05 * U, '③', cCircle, isBull ? label.style_label_down : label.style_label_up, cirSz)
// projected waves 4 and 5
if showProj
f_lbl(cb4 + math.round(p4Cyc * cycLen), L0 + 3 * U - p4Ret * 3 * U, '④', cCircle, label.style_label_center, cirSz)
f_lbl(cb4 + math.round(p5Cyc * cycLen), L0 + 3 * U - p5Ret * 3 * U, '⑤', cCircle, label.style_label_center, cirSz)
// ---- notes inside each 12-bar window
if showWinTx
string againstTxt = isBull ? 'low' : 'high'
string withTxt = isBull ? 'high' : 'low'
float noteY0 = anchorP - sgn * labelDrop * Uabs
for w = 0 to cycCount - 2 by 1
int s = anchorB + w * cycLen
int e = s + cycLen
string txt = ''
float noteY = noteY0 - sgn * (w % 2) * noteStagger * Uabs
if e <= bar_index
[wH, wHb] = f_ext(s, e, true)
[wL, wLb] = f_ext(s, e, false)
bool flat = (wH - wL) / math.max(atr, syminfo.mintick) < flatMult and w >= 2
string startT = w == 0 or w % 2 == 1 ? againstTxt : withTxt
string endT = (w + 1) % 2 == 1 ? againstTxt : withTxt
txt := flat ? 'Flat consolidation\n- corrective wave\n' + str.tostring(cycLen) + ' bars' : str.tostring(cycLen) + ' bars -\n' + startT + ' to ' + endT
txt
else if s <= bar_index
int ahead = e - bar_index
string dt = str.format_time(f_futureTime(time, ahead), 'dd MMM yyyy', syminfo.timezone)
txt := validStruct ? 'Expecting Henka-bi\non ' + dt + '\nafter ' + str.tostring(cycLen) + ' bars at\n' + str.tostring(eNum) + 'E target' : 'Expecting Henka-bi\non ' + dt + '\n(' + str.tostring(ahead) + ' bars ahead)'
txt
if txt != ''
f_lbl(s + 1, noteY, txt, cNote, label.style_label_left, notSz, true)
// ---- analysis table
if showTbl
int nextB = anchorB + (math.floor((bar_index - anchorB) / cycLen) + 1) * cycLen
int aheadNext = nextB - bar_index
string nextDt = str.format_time(f_futureTime(time, aheadNext), 'dd MMM yyyy', syminfo.timezone)
int score = (cloudOk ? 1 : 0) + (tenkanOk ? 1 : 0) + (kijunOk ? 1 : 0) + (chikouOk ? 1 : 0)
color good = color.new(#26A69A, 0)
color bad = color.new(#EF5350, 0)
f_cell(0, 0, 'Ichimoku 5-line analysis', color.white, text.align_left)
f_cell(1, 0, isBull ? 'BULLISH' : 'BEARISH', isBull ? good : bad)
f_cell(0, 1, 'Cloud (SSA/SSB)', color.silver, text.align_left)
f_cell(1, 1, cloudOk ? isBull ? 'Up' : 'Down' : 'Not aligned', cloudOk ? good : bad)
f_cell(0, 2, 'Tenkan-sen', color.silver, text.align_left)
f_cell(1, 2, tenkanOk ? isBull ? 'Pointing up' : 'Pointing down' : 'Against', tenkanOk ? good : bad)
f_cell(0, 3, 'Kijun-sen', color.silver, text.align_left)
f_cell(1, 3, kijunOk ? isBull ? 'Pointing up' : 'Pointing down' : 'Against', kijunOk ? good : bad)
f_cell(0, 4, 'Chikou span', color.silver, text.align_left)
f_cell(1, 4, chikouOk ? 'Free' : 'Blocked', chikouOk ? good : bad)
f_cell(0, 5, 'Elliott verdict', color.silver, text.align_left)
f_cell(1, 5, score == 4 ? 'Wave 3 impulse supported' : 'Not confirmed (' + str.tostring(score) + '/4)', score == 4 ? good : color.orange)
f_cell(0, 6, str.tostring(cycLen) + '-bar time cycle', color.silver, text.align_left)
f_cell(1, 6, 'Henka-bi: ' + nextDt + ' (+' + str.tostring(aheadNext) + ' bars)', color.white)
f_cell(0, 7, 'Next target', color.silver, text.align_left)
f_cell(1, 7, validStruct ? str.tostring(eNum) + 'E = ' + str.tostring(L0 + tgtK * U, format.mintick) : 'n/a', color.white)