本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// Ichimoku Cloud [Saikix]
// © Saikix
//@version=6
indicator("Ichimoku Cloud [Saikix]", shorttitle="Saikix-Ichimoku", overlay=true, max_lines_count=500, max_labels_count=500, max_polylines_count=10, max_bars_back=2000, behind_chart=false)
G1 = "Basic settings"
convLen = input.int(9, "Conversion Line length", minval=1, maxval=200, group=G1, display=display.none)
baseLen = input.int(26, "Base Line length", minval=1, maxval=200, group=G1, display=display.none)
spanBLen = input.int(52, "Leading Span B length", minval=1, maxval=400, group=G1, display=display.none)
disp = input.int(26, "Displacement", minval=2, maxval=200, group=G1, tooltip="The cloud is drawn this many bars ahead and the Lagging Span this many bars back, counting the current bar as the first", display=display.none)
lookback = input.int(500, "Lookback (bars)", minval=50, maxval=1500, group=G1, tooltip="How many bars back the Sanyaku Kouten / Gyakuten labels are drawn", display=display.none)
G2 = "Ichimoku lines"
showConv = input.bool(true, "Conversion Line", inline="conv", group=G2, display=display.none)
convCol = input.color(#2962FF, "", inline="conv", group=G2, active=showConv, display=display.none)
showBase = input.bool(true, "Base Line", inline="base", group=G2, display=display.none)
baseCol = input.color(#B71C1C, "", inline="base", group=G2, active=showBase, display=display.none)
showLag = input.bool(true, "Lagging Span", inline="lag", group=G2, display=display.none)
lagUpCol = input.color(#089981, "", inline="lag", group=G2, active=showLag, display=display.none)
lagDnCol = input.color(#F23645, "", inline="lag", group=G2, active=showLag, display=display.none)
lagMidCol = input.color(#787B86, "", inline="lag", group=G2, active=showLag, tooltip="Colors: above the candles, below the candles, inside the candles", display=display.none)
showCloud = input.bool(true, "Cloud", inline="cloud", group=G2, display=display.none)
cloudUpCol = input.color(color.new(#089981, 85), "", inline="cloud", group=G2, active=showCloud, display=display.none)
cloudDnCol = input.color(color.new(#F23645, 85), "", inline="cloud", group=G2, active=showCloud, tooltip="Colors: Leading Span A above B, Leading Span A below B", display=display.none)
showHighlight = input.bool(true, "Highlight the lines that matter now", group=G2, tooltip="Draws a thicker line over the Conversion Line, Base Line or Lagging Span when it matters now: a Base Line that price keeps bouncing off, a Conversion Line clearly away from the Base Line, a Lagging Span close to the candles", display=display.none)
G3 = "Sanyaku Kouten / Gyakuten"
showSignals = input.bool(true, "Show the latest Sanyaku Kouten / Gyakuten", group=G3, tooltip="The bar where all three checks lined up: price above the cloud, price above the bar 25 bars ago, fast line above slow line (all three the other way for Sanyaku Gyakuten). Checked at bar close", display=display.none)
showPast = input.bool(false, "Show past Sanyaku Kouten / Gyakuten", group=G3, tooltip="Labels on every bar where Sanyaku Kouten or Sanyaku Gyakuten started, back to Lookback (bars)", display=display.none)
showLevels = input.bool(true, "Show Sanyaku levels", group=G3, tooltip="The price where Sanyaku Kouten / Gyakuten would start, or where it would end", display=display.none)
G4 = "Price targets"
showTargets = input.bool(true, "Show price targets (N, V, E, NT)", inline="tgt", group=G4, display=display.none)
tgtCol = input.color(#0097A7, "", inline="tgt", group=G4, active=showTargets, tooltip="Shown after an A-B-C swing (up, pullback, up again or the reverse). The solid line is the main target: N when the pullback B-C is less than half of A-B, V otherwise", display=display.none)
showWave = input.bool(true, "Show the swing used (A, B, C)", group=G4, active=showTargets, display=display.none)
G5 = "Time cycle"
showTime = input.bool(true, "Show next time cycle", inline="time", group=G5, display=display.none)
timeCol = input.color(#FF9800, "", inline="time", group=G5, active=showTime, tooltip="A vertical line on the next bar that is an Ichimoku basic number of bars (9, 17, 26, 33, 42, 51, 65, 76, 83, 97, 129, 226) after the last swing high or low. Price often speeds up, slows down or turns around these bars", display=display.none)
G6 = "Higher timeframe"
showHtf = input.bool(false, "Show higher timeframe", group=G6, tooltip="Adds the state of the higher timeframe next to the label, for example 4h Sanyaku Kouten", display=display.none)
htfAuto = input.bool(true, "Auto timeframe", inline="htf", group=G6, active=showHtf, display=display.none)
htfIn = input.timeframe("240", "", inline="htf", group=G6, active=showHtf and not htfAuto, tooltip="On: one step above the chart timeframe (15m → 30m, 1h → 4h, 4h → D, D → W). Off: the timeframe on the right", display=display.none)
G7 = "Label and text"
showPanel = input.bool(true, "Show state label", inline="label", group=G7, display=display.none)
panelPosIn = input.string("Top right", "", options=["Top left", "Middle left", "Bottom left", "Top right", "Middle right", "Bottom right"], inline="label", group=G7, active=showPanel, tooltip="Top left overlaps the symbol name and the indicator list. On the free plan, bottom left overlaps the TradingView logo", display=display.none)
fontSize = input.int(13, "Text size", minval=6, maxval=30, group=G7, display=display.none)
G8 = "Alerts"
alertCond = input.string("Sanyaku", "Alert condition", options=["None", "Sanyaku", "Sanyaku + 2 of 3", "Sanyaku + 2 of 3 + cloud", "All"], group=G8, tooltip="Events sent after you create an alert on this indicator. Sanyaku: all three checks line up. 2 of 3: two checks, none against. Cloud: price closes above or below the cloud. All: also the time cycle bar. Checked at bar close", display=display.none)
COL_UP = #089981
COL_DN = #F23645
COL_GRAY = #787B86
SWING_DEPTH = 12
SWING_MIN_ATR = 0.8
MAX_SCAN = 1500
MAX_PIVOTS = 8
KIJUN_TOUCH_LOOKBACK = 120
KIJUN_TOUCH_ATR = 0.25
NEAR_ATR = 2.0
TENKAN_SPREAD_ATR = 0.50
HIGHLIGHT_THRESHOLD = 0.60
TARGET_RETRACE_SPLIT = 0.50
donchian(int len) =>
math.avg(ta.lowest(len), ta.highest(len))
conv = donchian(convLen)
base = donchian(baseLen)
leadA = math.avg(conv, base)
leadB = donchian(spanBLen)
d1 = disp - 1
atrMT = ta.sma(ta.tr(true), 14)
lo50 = ta.lowest(low, 50)
kumoTopAt(int o) =>
math.max(leadA[o + d1], leadB[o + d1])
kumoBotAt(int o) =>
math.min(leadA[o + d1], leadB[o + d1])
cond1At(int o) =>
na(conv[o]) or na(base[o]) ? 0 : conv[o] > base[o] ? 1 : conv[o] < base[o] ? -1 : 0
cond2At(int o) =>
float hiRef = high[o + d1]
float loRef = low[o + d1]
na(hiRef) ? 0 : close[o] > hiRef ? 1 : close[o] < loRef ? -1 : 0
cond3At(int o) =>
float top = kumoTopAt(o)
float bot = kumoBotAt(o)
na(top) or na(bot) ? 0 : close[o] > top ? 1 : close[o] < bot ? -1 : 0
c1 = cond1At(0)
c2 = cond2At(0)
c3 = cond3At(0)
bullCnt = (c1 > 0 ? 1 : 0) + (c2 > 0 ? 1 : 0) + (c3 > 0 ? 1 : 0)
bearCnt = (c1 < 0 ? 1 : 0) + (c2 < 0 ? 1 : 0) + (c3 < 0 ? 1 : 0)
stateText(int b, int s) =>
b == 3 ? "Sanyaku Kouten" : s == 3 ? "Sanyaku Gyakuten" : b == 2 ? "2 of 3 bullish" : s == 2 ? "2 of 3 bearish" : "Mixed"
stateColor(int b, int s) =>
b >= 2 ? COL_UP : s >= 2 ? COL_DN : COL_GRAY
plot(showConv ? conv : na, "Conversion Line", color=convCol, linewidth=1)
plot(showBase ? base : na, "Base Line", color=baseCol, linewidth=1)
color lagCol = c2 > 0 ? lagUpCol : c2 < 0 ? lagDnCol : lagMidCol
plot(showLag ? close : na, "Lagging Span", color=lagCol, linewidth=1, offset=-d1)
pA = plot(showCloud ? leadA : na, "Leading Span A", color=color.new(cloudUpCol, 50), linewidth=1, offset=d1)
pB = plot(showCloud ? leadB : na, "Leading Span B", color=color.new(cloudDnCol, 50), linewidth=1, offset=d1)
fill(pA, pB, color=leadA > leadB ? cloudUpCol : cloudDnCol, title="Cloud")
TIP_BULL = "Sanyaku Kouten: price above the cloud, price above " + str.tostring(disp - 1) + " bars ago, fast line above slow line"
TIP_BEAR = "Sanyaku Gyakuten: price below the cloud, price below " + str.tostring(disp - 1) + " bars ago, fast line below slow line"
var label lastBullLb = na
var label lastBearLb = na
bool inRange = bar_index > last_bar_index - lookback
if showSignals and barstate.isconfirmed and inRange
if bullCnt == 3 and bullCnt[1] < 3
if not showPast and not na(lastBullLb)
label.delete(lastBullLb)
lastBullLb := label.new(bar_index, low, "Sanyaku Kouten", yloc=yloc.belowbar, style=label.style_label_up, color=COL_UP, textcolor=color.white, size=fontSize, tooltip=TIP_BULL)
if bearCnt == 3 and bearCnt[1] < 3
if not showPast and not na(lastBearLb)
label.delete(lastBearLb)
lastBearLb := label.new(bar_index, high, "Sanyaku Gyakuten", yloc=yloc.abovebar, style=label.style_label_down, color=COL_DN, textcolor=color.white, size=fontSize, tooltip=TIP_BEAR)
chartSec = timeframe.in_seconds(timeframe.period)
higherOf() =>
chartSec < 900 ? "15" : chartSec < 1800 ? "30" : chartSec < 3600 ? "60" : chartSec < 14400 ? "240" : chartSec < 86400 ? "D" : chartSec < 604800 ? "W" : "M"
tfHtf = htfAuto or htfIn == "" ? higherOf() : htfIn
int htfBull = na
int htfBear = na
if showHtf and showPanel
[hb, hs] = request.security(syminfo.tickerid, tfHtf, [bullCnt[1], bearCnt[1]], lookahead=barmerge.lookahead_on)
htfBull := hb
htfBear := hs
tfLabel(string tf) =>
int sec = timeframe.in_seconds(tf)
sec < 3600 ? str.tostring(math.round(sec / 60.0), "#") + "m" : sec < 86400 ? str.tostring(math.round(sec / 3600.0), "#") + "h" : sec < 604800 ? "D" : sec < 2419200 ? "W" : "M"
fmtP(float p) =>
str.tostring(p, format.mintick)
sendAlert(string body) =>
alert("[Saikix-Ichimoku] " + syminfo.ticker + " " + tfLabel(timeframe.period) + " " + body, alert.freq_all)
alertLevel = alertCond == "None" ? 0 : alertCond == "Sanyaku" ? 1 : alertCond == "Sanyaku + 2 of 3" ? 2 : alertCond == "Sanyaku + 2 of 3 + cloud" ? 3 : 4
var array<float> zp = array.new<float>()
var array<int> zo = array.new<int>()
var array<bool> zh = array.new<bool>()
panelPos(string p) =>
p == "Top left" ? position.top_left : p == "Middle left" ? position.middle_left : p == "Top right" ? position.top_right : p == "Middle right" ? position.middle_right : p == "Bottom right" ? position.bottom_right : position.bottom_left
var table panel = table.new(panelPos(panelPosIn), 2, 4, border_color=color.new(chart.bg_color, 100), border_width=4)
var array<line> drawnLines = array.new<line>()
var array<label> drawnLabels = array.new<label>()
var array<polyline> drawnPolys = array.new<polyline>()
clearDrawn() =>
while array.size(drawnLines) > 0
line.delete(array.pop(drawnLines))
while array.size(drawnLabels) > 0
label.delete(array.pop(drawnLabels))
while array.size(drawnPolys) > 0
polyline.delete(array.pop(drawnPolys))
levelLine(int x1, float p, color c, string sty, int w) =>
array.push(drawnLines, line.new(x1, p, bar_index, p, xloc=xloc.bar_index, extend=extend.right, color=c, style=sty, width=w))
startLabel(int x, float p, string txt, color c, bool above, bool filled, string tip) =>
array.push(drawnLabels, label.new(x, p, txt, xloc=xloc.bar_index, style=above ? label.style_label_lower_left : label.style_label_upper_left, color=filled ? c : color.new(c, 100), textcolor=filled ? color.white : c, size=fontSize, textalign=text.align_left, tooltip=tip))
endLabel(float p, string txt, color c, bool above, bool filled, string tip) =>
array.push(drawnLabels, label.new(bar_index, p, txt, xloc=xloc.bar_index, style=above ? label.style_label_lower_right : label.style_label_upper_right, color=filled ? c : color.new(c, 100), textcolor=filled ? color.white : c, size=fontSize, textalign=text.align_right, tooltip=tip))
polyFrom(array<chart.point> pts, color c) =>
if pts.size() > 1
array.push(drawnPolys, polyline.new(pts, curved=false, closed=false, xloc=xloc.bar_index, line_color=c, line_width=3))
checkText(int c, bool bull, string upTxt, string dnTxt, string midTxt) =>
c == 0 ? "– " + midTxt : (c > 0) == bull ? "✓ " + (bull ? upTxt : dnTxt) : "✗ " + (bull ? upTxt : dnTxt)
checkColor(int c, bool bull) =>
c == 0 ? COL_GRAY : (c > 0) == bull ? COL_UP : COL_DN
oJ = barstate.isconfirmed ? 0 : 1
j1 = cond1At(oJ)
j2 = cond2At(oJ)
j3 = cond3At(oJ)
jTop = kumoTopAt(oJ)
jBot = kumoBotAt(oJ)
if barstate.islast
clearDrawn()
table.clear(panel, 0, 0, 1, 3)
int o = oJ
int s1 = j1
int s2 = j2
int s3 = j3
int sb = (s1 > 0 ? 1 : 0) + (s2 > 0 ? 1 : 0) + (s3 > 0 ? 1 : 0)
int ss = (s1 < 0 ? 1 : 0) + (s2 < 0 ? 1 : 0) + (s3 < 0 ? 1 : 0)
float topNow = jTop
float botNow = jBot
float atrNow = nz(atrMT[o], syminfo.mintick * 10)
atrNow := atrNow > 0 ? atrNow : syminfo.mintick * 10
int refBars = o + d1
bool custom = convLen != 9 or baseLen != 26 or spanBLen != 52 or disp != 26
if showHighlight
int touches = 0
float tol = atrNow * KIJUN_TOUCH_ATR
int lastT = math.min(o + KIJUN_TOUCH_LOOKBACK - 1, bar_index - 1)
if lastT >= o
for i = o to lastT
float k = base[i]
if not na(k)
bool touched = low[i] <= k + tol and high[i] >= k - tol
if touched and i - 1 >= o
bool bounceUp = close[i] > k and close[i - 1] > close[i]
bool bounceDn = close[i] < k and close[i - 1] < close[i]
if bounceUp or bounceDn
touches += 1
float hlKijun = math.min(1.0, touches / 4.0)
float hlTenkan = math.min(1.0, math.abs(conv[o] - base[o]) / atrNow / TENKAN_SPREAD_ATR)
float dc = s2 > 0 ? (close[o] - high[refBars]) / atrNow : s2 < 0 ? (low[refBars] - close[o]) / atrNow : 0.0
float hlChikou = 1.0 - math.min(1.0, math.abs(dc) / NEAR_ATR)
bool doConv = showConv and hlTenkan >= HIGHLIGHT_THRESHOLD
bool doBase = showBase and hlKijun >= HIGHLIGHT_THRESHOLD
bool doLag = showLag and hlChikou >= HIGHLIGHT_THRESHOLD
if doConv or doBase or doLag
array<chart.point> pConv = array.new<chart.point>()
array<chart.point> pBase = array.new<chart.point>()
array<chart.point> pLag = array.new<chart.point>()
int nT = math.min(d1, bar_index - 1)
for j = nT to 0
if doConv and not na(conv[j])
pConv.push(chart.point.from_index(bar_index - j, conv[j]))
if doBase and not na(base[j])
pBase.push(chart.point.from_index(bar_index - j, base[j]))
if doLag
pLag.push(chart.point.from_index(bar_index - j - d1, close[j]))
polyFrom(pConv, convCol)
polyFrom(pBase, baseCol)
polyFrom(pLag, s2 > 0 ? lagUpCol : s2 < 0 ? lagDnCol : lagMidCol)
if showLevels and not na(topNow)
if sb == 3
levelLine(bar_index - o, topNow, COL_DN, line.style_dashed, 2)
endLabel(topNow, "Sanyaku Kouten ends below " + fmtP(topNow), COL_DN, false, true, "Closing below the top of the cloud ends Sanyaku Kouten")
else if ss == 3
levelLine(bar_index - o, botNow, COL_UP, line.style_dashed, 2)
endLabel(botNow, "Sanyaku Gyakuten ends above " + fmtP(botNow), COL_UP, true, true, "Closing above the bottom of the cloud ends Sanyaku Gyakuten")
else
float upP = na
int upX = na
if s2 <= 0 and not na(high[refBars])
upP := high[refBars]
upX := bar_index - refBars
if s3 <= 0 and (na(upP) or topNow > upP)
upP := topNow
upX := bar_index - o
if not na(upP)
levelLine(upX, upP, COL_UP, line.style_dashed, 2)
endLabel(upP, s1 > 0 ? "Sanyaku Kouten above " + fmtP(upP) : "Above " + fmtP(upP) + " (fast line still below)", COL_UP, true, true, "Price above the cloud and above " + str.tostring(d1) + " bars ago. Sanyaku Kouten also needs the fast line (Conversion Line) above the slow line (Base Line)")
float dnP = na
int dnX = na
if s2 >= 0 and not na(low[refBars])
dnP := low[refBars]
dnX := bar_index - refBars
if s3 >= 0 and (na(dnP) or botNow < dnP)
dnP := botNow
dnX := bar_index - o
if not na(dnP)
levelLine(dnX, dnP, COL_DN, line.style_dashed, 2)
endLabel(dnP, s1 < 0 ? "Sanyaku Gyakuten below " + fmtP(dnP) : "Below " + fmtP(dnP) + " (fast line still above)", COL_DN, false, true, "Price below the cloud and below " + str.tostring(d1) + " bars ago. Sanyaku Gyakuten also needs the fast line (Conversion Line) below the slow line (Base Line)")
array.clear(zp)
array.clear(zo)
array.clear(zh)
int scan = math.min(MAX_SCAN, bar_index - SWING_DEPTH - 1)
if (showTargets or showTime) and scan > SWING_DEPTH + 1
for i = SWING_DEPTH + 1 to scan
if array.size(zp) >= MAX_PIVOTS
break
float h = high[i]
float l = low[i]
bool isH = true
bool isL = true
for k = 1 to SWING_DEPTH
if high[i - k] > h or high[i + k] > h
isH := false
if low[i - k] < l or low[i + k] < l
isL := false
if not isH and not isL
break
if isH != isL
float price = isH ? h : l
int n = array.size(zp)
bool skip = false
if n > 0 and array.get(zh, n - 1) == isH
bool more = isH ? price > array.get(zp, n - 1) : price < array.get(zp, n - 1)
if more
array.set(zp, n - 1, price)
array.set(zo, n - 1, i)
skip := true
if not skip and n > 0
float a = atrMT[i]
if a > 0 and math.abs(price - array.get(zp, n - 1)) < a * SWING_MIN_ATR
skip := true
if not skip
array.push(zp, price)
array.push(zo, i)
array.push(zh, isH)
int np = array.size(zp)
if showTargets and np >= 3
bool isPY = false
if np >= 5
array<float> hs = array.new<float>()
array<float> ls = array.new<float>()
for i = 0 to 4
if array.get(zh, i)
if hs.size() < 3
hs.push(array.get(zp, i))
else
if ls.size() < 3
ls.push(array.get(zp, i))
if hs.size() >= 2 and ls.size() >= 2
bool highsDown = hs.get(0) < hs.get(1)
bool highsUp = hs.get(0) > hs.get(1)
bool lowsUp = ls.get(0) > ls.get(1)
bool lowsDown = ls.get(0) < ls.get(1)
if hs.size() >= 3
highsDown := highsDown and hs.get(1) < hs.get(2)
highsUp := highsUp and hs.get(1) > hs.get(2)
if ls.size() >= 3
lowsUp := lowsUp and ls.get(1) > ls.get(2)
lowsDown := lowsDown and ls.get(1) < ls.get(2)
isPY := (highsDown and lowsUp) or (highsUp and lowsDown)
float C = array.get(zp, 0)
float B = array.get(zp, 1)
float A = array.get(zp, 2)
bool cLow = not array.get(zh, 0)
bool up = cLow and array.get(zh, 1) and not array.get(zh, 2) and close > C and C > A
bool dn = not cLow and not array.get(zh, 1) and array.get(zh, 2) and close < C and C < A
if not isPY and (up or dn)
int xA = bar_index - array.get(zo, 2)
int xB = bar_index - array.get(zo, 1)
int xC = bar_index - array.get(zo, 0)
float tV = B + (B - C)
float tN = C + (B - A)
float tE = B + (B - A)
float tNT = C + (C - A)
float legAB = math.abs(B - A)
float retr = legAB > 0 ? math.abs(B - C) / legAB : 0.0
bool mainN = retr < TARGET_RETRACE_SPLIT
string dir = up ? "Upside target " : "Downside target "
color dimCol = color.new(tgtCol, 40)
if showWave
color waveCol = color.new(tgtCol, 15)
array.push(drawnLines, line.new(xA, A, xB, B, xloc=xloc.bar_index, color=waveCol, style=line.style_solid, width=2))
array.push(drawnLines, line.new(xB, B, xC, C, xloc=xloc.bar_index, color=waveCol, style=line.style_solid, width=2))
array.push(drawnLabels, label.new(xA, A, "A start", xloc=xloc.bar_index, style=up ? label.style_label_up : label.style_label_down, color=tgtCol, textcolor=color.white, size=fontSize, tooltip="Start of the swing " + fmtP(A)))
array.push(drawnLabels, label.new(xB, B, up ? "B swing high" : "B swing low", xloc=xloc.bar_index, style=up ? label.style_label_down : label.style_label_up, color=tgtCol, textcolor=color.white, size=fontSize, tooltip=fmtP(B)))
array.push(drawnLabels, label.new(xC, C, up ? "C pullback low" : "C rally high", xloc=xloc.bar_index, style=up ? label.style_label_up : label.style_label_down, color=tgtCol, textcolor=color.white, size=fontSize, tooltip=fmtP(C)))
levelLine(xB, tE, dimCol, line.style_dotted, 1)
startLabel(xB, tE, "E " + fmtP(tE), tgtCol, up, false, dir + "(E) = B + (B - A)")
levelLine(xB, tV, mainN ? dimCol : tgtCol, mainN ? line.style_dotted : line.style_solid, mainN ? 1 : 2)
startLabel(xB, tV, mainN ? "V " + fmtP(tV) : dir + fmtP(tV) + " (V)", tgtCol, up, not mainN, dir + "(V) = B + (B - C)")
levelLine(xC, tN, mainN ? tgtCol : dimCol, mainN ? line.style_solid : line.style_dotted, mainN ? 2 : 1)
startLabel(xC, tN, mainN ? dir + fmtP(tN) + " (N)" : "N " + fmtP(tN), tgtCol, up, mainN, dir + "(N) = C + (B - A)")
levelLine(xC, tNT, dimCol, line.style_dotted, 1)
startLabel(xC, tNT, "NT " + fmtP(tNT), tgtCol, up, false, dir + "(NT) = C + (C - A)")
if showTime and np >= 1
int elapsed = array.get(zo, 0)
array<int> kihon = array.from(9, 17, 26, 33, 42, 51, 65, 76, 83, 97, 129, 226)
int ahead = na
int num = na
for k in kihon
if k == elapsed
ahead := 0
num := k
break
if k > elapsed and na(ahead)
ahead := k - elapsed
num := k
break
if not na(ahead) and ahead <= 120
int x = bar_index + ahead
float yTop = lo50 - atrNow
array.push(drawnLines, line.new(x, yTop, x, yTop + atrNow, xloc=xloc.bar_index, extend=extend.both, color=timeCol, style=line.style_dotted, width=1))
array.push(drawnLabels, label.new(x, yTop, "Time cycle " + str.tostring(num), xloc=xloc.bar_index, style=label.style_label_right, color=color.new(timeCol, 100), textcolor=timeCol, size=fontSize, tooltip=str.tostring(num) + " bars after the last swing " + (array.get(zh, 0) ? "high" : "low") + " (" + (ahead == 0 ? "this bar" : str.tostring(ahead) + " bars ahead") + ")"))
if ahead == 0 and barstate.isconfirmed and alertLevel >= 4
sendAlert("Time cycle " + str.tostring(num) + ": " + str.tostring(num) + " bars after the last swing. Price: " + fmtP(close))
if showPanel
bool bullSide = ss <= sb
string ago = str.tostring(d1) + " bars ago"
table.cell(panel, 1, 0, stateText(sb, ss), text_color=color.white, bgcolor=stateColor(sb, ss), text_size=fontSize + 1, text_halign=text.align_left, tooltip=custom ? "Custom lengths: other traders' Ichimoku shows different values" : "Sanyaku Kouten: all three checks bullish. Sanyaku Gyakuten: all three bearish (Ichimoku names)")
table.cell(panel, 1, 1, checkText(s3, bullSide, "Price above the cloud", "Price below the cloud", "Price inside the cloud"), text_color=checkColor(s3, bullSide), text_size=fontSize, text_halign=text.align_left, tooltip="The shaded band is the cloud")
table.cell(panel, 1, 2, checkText(s2, bullSide, "Price above " + ago, "Price below " + ago, "Price near " + ago), text_color=checkColor(s2, bullSide), text_size=fontSize, text_halign=text.align_left, tooltip="Compared with the high and low of the bar " + ago + " (the Lagging Span)")
table.cell(panel, 1, 3, checkText(s1, bullSide, "Fast line above slow line", "Fast line below slow line", "Fast line on slow line"), text_color=checkColor(s1, bullSide), text_size=fontSize, text_halign=text.align_left, tooltip="Fast line = Conversion Line (blue). Slow line = Base Line (red)")
if showHtf and not na(htfBull)
table.cell(panel, 0, 0, tfLabel(tfHtf) + " " + stateText(htfBull, htfBear), text_color=color.white, bgcolor=stateColor(htfBull, htfBear), text_size=fontSize, tooltip="Higher timeframe, last closed bar")
if barstate.isconfirmed and alertLevel > 0
if bullCnt == 3 and bullCnt[1] < 3
sendAlert("Sanyaku Kouten: all three checks met. Price: " + fmtP(close))
else if bearCnt == 3 and bearCnt[1] < 3
sendAlert("Sanyaku Gyakuten: all three checks met. Price: " + fmtP(close))
else if alertLevel >= 2 and bullCnt == 2 and bearCnt == 0 and bullCnt[1] < 2
sendAlert("2 of 3 bullish: two of three checks met. Price: " + fmtP(close))
else if alertLevel >= 2 and bearCnt == 2 and bullCnt == 0 and bearCnt[1] < 2
sendAlert("2 of 3 bearish: two of three checks met. Price: " + fmtP(close))
else if alertLevel >= 3 and c3 != c3[1] and c3 != 0
sendAlert((c3 > 0 ? "Cloud breakout up" : "Cloud breakout down") + ". Price: " + fmtP(close))