本页源码来自 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/
// Multi Length Stochastic 8 Lines [Saikix]
// © Saikix
//@version=6
indicator("Multi Length Stochastic 8 Lines [Saikix]", shorttitle="Saikix-Stoch8", overlay=false, format=format.price, precision=0, max_labels_count=500, behind_chart=false)
G_BASIC = "Basic settings"
linesBy = input.string("Lengths", "Lines", options=["Lengths", "Timeframes"], group=G_BASIC, display=display.none,
tooltip="Lengths: stochastic lines with different lengths on one timeframe.\nTimeframes: one stochastic length on different timeframes.\nShort lines are blue and long lines are orange.")
IS_LEN = linesBy == "Lengths"
nS = input.int(4, "Number of lines", minval=1, maxval=6, inline="cnt", group=G_BASIC, display=display.none)
nL = input.int(4, "", minval=1, maxval=6, inline="cnt", group=G_BASIC, display=display.none,
tooltip="Short lines (left) and long lines (right), 1 to 6 each.")
s1 = input.int(9, "Short lengths 1–2", minval=2, maxval=200, inline="s12", group=G_BASIC, display=display.none, active=IS_LEN)
s2 = input.int(14, "", minval=2, maxval=200, inline="s12", group=G_BASIC, display=display.none, active=IS_LEN and nS >= 2)
s3 = input.int(18, "Short lengths 3–4", minval=2, maxval=200, inline="s34", group=G_BASIC, display=display.none, active=IS_LEN and nS >= 3)
s4 = input.int(26, "", minval=2, maxval=200, inline="s34", group=G_BASIC, display=display.none, active=IS_LEN and nS >= 4)
s5 = input.int(11, "Short lengths 5–6", minval=2, maxval=200, inline="s56", group=G_BASIC, display=display.none, active=IS_LEN and nS >= 5)
s6 = input.int(22, "", minval=2, maxval=200, inline="s56", group=G_BASIC, display=display.none, active=IS_LEN and nS >= 6)
l1 = input.int(33, "Long lengths 1–2", minval=2, maxval=200, inline="l12", group=G_BASIC, display=display.none, active=IS_LEN)
l2 = input.int(42, "", minval=2, maxval=200, inline="l12", group=G_BASIC, display=display.none, active=IS_LEN and nL >= 2)
l3 = input.int(52, "Long lengths 3–4", minval=2, maxval=200, inline="l34", group=G_BASIC, display=display.none, active=IS_LEN and nL >= 3)
l4 = input.int(75, "", minval=2, maxval=200, inline="l34", group=G_BASIC, display=display.none, active=IS_LEN and nL >= 4)
l5 = input.int(62, "Long lengths 5–6", minval=2, maxval=200, inline="l56", group=G_BASIC, display=display.none, active=IS_LEN and nL >= 5)
l6 = input.int(90, "", minval=2, maxval=200, inline="l56", group=G_BASIC, display=display.none, active=IS_LEN and nL >= 6,
tooltip="Any order is fine: the lines are sorted by length for the colors and the signals.")
tfIn = input.timeframe("", "Timeframe", group=G_BASIC, display=display.none, active=IS_LEN,
tooltip="Timeframe of all lengths. Empty = chart timeframe. A higher timeframe stochastic is built from its completed bars, the high and low of its current bar so far, and the current price, so past bars show what it was at that time. A timeframe lower than the chart uses the chart timeframe.")
lenT = input.int(14, "Length", minval=2, maxval=200, group=G_BASIC, display=display.none, active=not IS_LEN,
tooltip="Stochastic length used on all timeframes.")
t1 = input.timeframe("1", "Short timeframes 1–2", inline="t12", group=G_BASIC, display=display.none, active=not IS_LEN)
t2 = input.timeframe("5", "", inline="t12", group=G_BASIC, display=display.none, active=not IS_LEN and nS >= 2)
t3 = input.timeframe("15", "Short timeframes 3–4", inline="t34", group=G_BASIC, display=display.none, active=not IS_LEN and nS >= 3)
t4 = input.timeframe("30", "", inline="t34", group=G_BASIC, display=display.none, active=not IS_LEN and nS >= 4)
t5 = input.timeframe("3", "Short timeframes 5–6", inline="t56", group=G_BASIC, display=display.none, active=not IS_LEN and nS >= 5)
t6 = input.timeframe("10", "", inline="t56", group=G_BASIC, display=display.none, active=not IS_LEN and nS >= 6)
u1 = input.timeframe("60", "Long timeframes 1–2", inline="u12", group=G_BASIC, display=display.none, active=not IS_LEN)
u2 = input.timeframe("240", "", inline="u12", group=G_BASIC, display=display.none, active=not IS_LEN and nL >= 2)
u3 = input.timeframe("D", "Long timeframes 3–4", inline="u34", group=G_BASIC, display=display.none, active=not IS_LEN and nL >= 3)
u4 = input.timeframe("W", "", inline="u34", group=G_BASIC, display=display.none, active=not IS_LEN and nL >= 4)
u5 = input.timeframe("120", "Long timeframes 5–6", inline="u56", group=G_BASIC, display=display.none, active=not IS_LEN and nL >= 5)
u6 = input.timeframe("M", "", inline="u56", group=G_BASIC, display=display.none, active=not IS_LEN and nL >= 6,
tooltip="Higher than the chart: built from that timeframe's completed bars, the high and low of its current bar so far, and the current price, so past bars show what it was at that time.\nLower than the chart: not drawn as a line (it changes many times within one chart bar). Its current value is in the summary.")
smK = input.int(3, "%K smoothing", minval=1, maxval=20, group=G_BASIC, display=display.none,
tooltip="Each line is %K smoothed with an SMA of this length. 1 = raw %K.")
lvl = input.int(80, "Levels", minval=51, maxval=99, group=G_BASIC, display=display.none,
tooltip="Upper level. The lower level is 100 minus this, for example 80 and 20.")
LO = 100 - lvl
G_DISP = "Chart display"
showTable = input.bool(false, "Show summary", group=G_DISP, display=display.none,
tooltip="Top right of the price chart: how many lines are on the same side of 50, and the current value of each line. With Timeframes, timeframes lower than the chart are not drawn as lines, and their values are shown here.")
G_SIG = "Signals"
showPO = input.bool(true, "Show perfect order", group=G_SIG, display=display.none, active=IS_LEN,
tooltip="PO on the price chart when all lines line up in order of length: the shortest on top and the longest at the bottom (bullish), or the reverse (bearish). Checked at bar close. Lengths only.")
poGap = input.int(50, "Bars between perfect orders", minval=0, maxval=1000, group=G_SIG, display=display.none, active=IS_LEN,
tooltip="A perfect order in the same direction is not shown again within this many bars of the last one. 0 = every time.")
showGC = input.bool(true, "Show golden and death crosses", group=G_SIG, display=display.none, active=IS_LEN,
tooltip="GC when all short lines move above all long lines, DC when they all move below. Only when the direction changes from the last cross. Checked at bar close. Lengths only.")
G_STYLE = "Colors and text"
shortDark = input.color(color.new(#0064FF, 30), "Short colors", inline="sc", group=G_STYLE, display=display.none)
shortLight = input.color(color.new(#00DCFF, 30), "", inline="sc", group=G_STYLE, display=display.none,
tooltip="Shortest and longest of the short lines. The lines in between get the colors in between.")
longDark = input.color(color.new(#FF5000, 30), "Long colors", inline="lc", group=G_STYLE, display=display.none)
longLight = input.color(color.new(#FFC800, 30), "", inline="lc", group=G_STYLE, display=display.none,
tooltip="Shortest and longest of the long lines. The lines in between get the colors in between.")
upCol = input.color(#089981, "Signal colors", inline="sm", group=G_STYLE, display=display.none)
dnCol = input.color(#F23645, "", inline="sm", group=G_STYLE, display=display.none)
normCol = input.color(#787B86, "", inline="sm", group=G_STYLE, display=display.none,
tooltip="Up, down and mixed. Used for the signals and the summary.")
lineW = input.int(2, "Line width", minval=1, maxval=5, group=G_STYLE, display=display.none)
txtSize = input.int(13, "Text size", minval=8, maxval=30, group=G_STYLE, display=display.none)
tblPos = input.string("Top right", "Summary position", options=["Top right", "Top left", "Bottom right", "Bottom left"], group=G_STYLE, display=display.none)
G_ALERT = "Alerts"
alSide = input.bool(true, "All lines on one side of 50", group=G_ALERT, display=display.none,
tooltip="Create the alert with \"Any alert() function call\". Sent at bar close.\nAll lines move above 50, or all move below 50.")
alLevel = input.bool(true, "All lines beyond the levels", group=G_ALERT, display=display.none,
tooltip="All lines move above the upper level, or all move below the lower level.")
alPO = input.bool(true, "Perfect order", group=G_ALERT, display=display.none, active=IS_LEN,
tooltip="Bullish or bearish perfect order, as shown on the chart.")
alGC = input.bool(true, "Golden and death crosses", group=G_ALERT, display=display.none, active=IS_LEN,
tooltip="Golden cross or death cross, as shown on the chart.")
N_ALL = nS + nL
CHART_SEC = timeframe.in_seconds(timeframe.period)
tfSec(simple string tf) => tf == "" ? CHART_SEC : timeframe.in_seconds(tf)
tfLabel(simple string tf) =>
int sec = tfSec(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"
stoK(simple int n) => ta.sma(ta.stoch(close, high, low, n), smK)
htfParts(simple int n) =>
float rawK = ta.stoch(close, high, low, n)
float hh = n > 1 ? ta.highest(high, n - 1)[1] : na
float ll = n > 1 ? ta.lowest(low, n - 1)[1] : na
float sk = smK > 1 ? math.sum(rawK, smK - 1)[1] : 0.0
[hh, ll, sk]
stoAt(float hh, float ll, float sk, float curH, float curL) =>
float hi = na(hh) ? curH : math.max(hh, curH)
float lo = na(ll) ? curL : math.min(ll, curL)
float raw = hi - lo > 0 ? 100 * (close - lo) / (hi - lo) : 50.0
na(sk) ? na : (sk + raw) / smK
curHL(simple string tf) =>
var float h = na
var float l = na
if timeframe.change(tf)
h := high
l := low
else
h := math.max(nz(h, high), high)
l := math.min(nz(l, low), low)
[h, l]
float cT = stoK(lenT)
stoOnTf(simple string tf, simple int n) =>
int s = tfSec(tf)
float r = na
[ch, cl] = curHL(tf)
if s == CHART_SEC
r := cT
else if s > CHART_SEC
[hh, ll, sk] = request.security(syminfo.tickerid, tf, htfParts(n), lookahead=barmerge.lookahead_on)
r := stoAt(hh, ll, sk, ch, cl)
else
r := request.security(syminfo.tickerid, tf, ta.sma(ta.stoch(close, high, low, n), smK))
r
string tfL = tfIn == "" or timeframe.in_seconds(tfIn) <= CHART_SEC ? timeframe.period : tfIn
bool isHtf = tfL != timeframe.period
[curHi, curLo] = curHL(tfL)
bool aS2 = nS >= 2
bool aS3 = nS >= 3
bool aS4 = nS >= 4
bool aS5 = nS >= 5
bool aS6 = nS >= 6
bool aL2 = nL >= 2
bool aL3 = nL >= 3
bool aL4 = nL >= 4
bool aL5 = nL >= 5
bool aL6 = nL >= 6
htfAll() =>
[h1, k1, m1] = htfParts(s1)
[h2, k2, m2] = htfParts(s2)
[h3, k3, m3] = htfParts(s3)
[h4, k4, m4] = htfParts(s4)
[h5, k5, m5] = htfParts(s5)
[h6, k6, m6] = htfParts(s6)
[h7, k7, m7] = htfParts(l1)
[h8, k8, m8] = htfParts(l2)
[h9, k9, m9] = htfParts(l3)
[h10, k10, m10] = htfParts(l4)
[h11, k11, m11] = htfParts(l5)
[h12, k12, m12] = htfParts(l6)
[h1, k1, m1, h2, k2, m2, h3, k3, m3, h4, k4, m4, h5, k5, m5, h6, k6, m6, h7, k7, m7, h8, k8, m8, h9, k9, m9, h10, k10, m10, h11, k11, m11, h12, k12, m12]
float rS1 = na
float rS2 = na
float rS3 = na
float rS4 = na
float rS5 = na
float rS6 = na
float rL1 = na
float rL2 = na
float rL3 = na
float rL4 = na
float rL5 = na
float rL6 = na
if IS_LEN
if isHtf
[h1, k1, m1, h2, k2, m2, h3, k3, m3, h4, k4, m4, h5, k5, m5, h6, k6, m6, h7, k7, m7, h8, k8, m8, h9, k9, m9, h10, k10, m10, h11, k11, m11, h12, k12, m12] = request.security(syminfo.tickerid, tfL, htfAll(), lookahead=barmerge.lookahead_on)
rS1 := stoAt(h1, k1, m1, curHi, curLo)
rS2 := aS2 ? stoAt(h2, k2, m2, curHi, curLo) : na
rS3 := aS3 ? stoAt(h3, k3, m3, curHi, curLo) : na
rS4 := aS4 ? stoAt(h4, k4, m4, curHi, curLo) : na
rS5 := aS5 ? stoAt(h5, k5, m5, curHi, curLo) : na
rS6 := aS6 ? stoAt(h6, k6, m6, curHi, curLo) : na
rL1 := stoAt(h7, k7, m7, curHi, curLo)
rL2 := aL2 ? stoAt(h8, k8, m8, curHi, curLo) : na
rL3 := aL3 ? stoAt(h9, k9, m9, curHi, curLo) : na
rL4 := aL4 ? stoAt(h10, k10, m10, curHi, curLo) : na
rL5 := aL5 ? stoAt(h11, k11, m11, curHi, curLo) : na
rL6 := aL6 ? stoAt(h12, k12, m12, curHi, curLo) : na
else
rS1 := stoOnTf(t1, lenT)
if aS2
rS2 := stoOnTf(t2, lenT)
if aS3
rS3 := stoOnTf(t3, lenT)
if aS4
rS4 := stoOnTf(t4, lenT)
if aS5
rS5 := stoOnTf(t5, lenT)
if aS6
rS6 := stoOnTf(t6, lenT)
rL1 := stoOnTf(u1, lenT)
if aL2
rL2 := stoOnTf(u2, lenT)
if aL3
rL3 := stoOnTf(u3, lenT)
if aL4
rL4 := stoOnTf(u4, lenT)
if aL5
rL5 := stoOnTf(u5, lenT)
if aL6
rL6 := stoOnTf(u6, lenT)
float cS1 = stoK(s1)
float cS2 = stoK(s2)
float cS3 = stoK(s3)
float cS4 = stoK(s4)
float cS5 = stoK(s5)
float cS6 = stoK(s6)
float cL1 = stoK(l1)
float cL2 = stoK(l2)
float cL3 = stoK(l3)
float cL4 = stoK(l4)
float cL5 = stoK(l5)
float cL6 = stoK(l6)
if IS_LEN and not isHtf
rS1 := cS1
rS2 := aS2 ? cS2 : na
rS3 := aS3 ? cS3 : na
rS4 := aS4 ? cS4 : na
rS5 := aS5 ? cS5 : na
rS6 := aS6 ? cS6 : na
rL1 := cL1
rL2 := aL2 ? cL2 : na
rL3 := aL3 ? cL3 : na
rL4 := aL4 ? cL4 : na
rL5 := aL5 ? cL5 : na
rL6 := aL6 ? cL6 : na
array<int> keyS = IS_LEN ? array.from(s1, s2, s3, s4, s5, s6) : array.from(tfSec(t1), tfSec(t2), tfSec(t3), tfSec(t4), tfSec(t5), tfSec(t6))
array<int> keyL = IS_LEN ? array.from(l1, l2, l3, l4, l5, l6) : array.from(tfSec(u1), tfSec(u2), tfSec(u3), tfSec(u4), tfSec(u5), tfSec(u6))
array<string> nameS = IS_LEN ? array.from(str.tostring(s1), str.tostring(s2), str.tostring(s3), str.tostring(s4), str.tostring(s5), str.tostring(s6)) : array.from(tfLabel(t1), tfLabel(t2), tfLabel(t3), tfLabel(t4), tfLabel(t5), tfLabel(t6))
array<string> nameL = IS_LEN ? array.from(str.tostring(l1), str.tostring(l2), str.tostring(l3), str.tostring(l4), str.tostring(l5), str.tostring(l6)) : array.from(tfLabel(u1), tfLabel(u2), tfLabel(u3), tfLabel(u4), tfLabel(u5), tfLabel(u6))
drawTf(simple string tf) => IS_LEN or tfSec(tf) >= CHART_SEC
array<bool> drawS = array.from(drawTf(t1), drawTf(t2), drawTf(t3), drawTf(t4), drawTf(t5), drawTf(t6))
array<bool> drawL = array.from(drawTf(u1), drawTf(u2), drawTf(u3), drawTf(u4), drawTf(u5), drawTf(u6))
rankIn(array<int> keys, int n, int i) =>
int r = 0
for j = 0 to n - 1
if j != i and (keys.get(j) < keys.get(i) or (keys.get(j) == keys.get(i) and j < i))
r += 1
r
mixCol(color a, color b, int rank, int n) =>
float t = n <= 1 ? 0.0 : rank / (n - 1.0)
color.rgb(color.r(a) + (color.r(b) - color.r(a)) * t, color.g(a) + (color.g(b) - color.g(a)) * t, color.b(a) + (color.b(b) - color.b(a)) * t, color.t(a) + (color.t(b) - color.t(a)) * t)
colS(int i) => mixCol(shortDark, shortLight, rankIn(keyS, nS, i), nS)
colL(int i) => mixCol(longDark, longLight, rankIn(keyL, nL, i), nL)
hline(lvl, "Upper level", color=color.new(#787B86, 30), linestyle=hline.style_dotted)
hline(50, "Middle line", color=color.new(#787B86, 60), linestyle=hline.style_dotted)
hline(LO, "Lower level", color=color.new(#787B86, 30), linestyle=hline.style_dotted)
lineOf(float r, simple string tf) => drawTf(tf) ? r : na
plot(lineOf(rS1, t1), "Short 1", color=colS(0), linewidth=lineW)
plot(lineOf(rS2, t2), "Short 2", color=colS(1), linewidth=lineW)
plot(lineOf(rS3, t3), "Short 3", color=colS(2), linewidth=lineW)
plot(lineOf(rS4, t4), "Short 4", color=colS(3), linewidth=lineW)
plot(lineOf(rS5, t5), "Short 5", color=colS(4), linewidth=lineW)
plot(lineOf(rS6, t6), "Short 6", color=colS(5), linewidth=lineW)
plot(lineOf(rL1, u1), "Long 1", color=colL(0), linewidth=lineW)
plot(lineOf(rL2, u2), "Long 2", color=colL(1), linewidth=lineW)
plot(lineOf(rL3, u3), "Long 3", color=colL(2), linewidth=lineW)
plot(lineOf(rL4, u4), "Long 4", color=colL(3), linewidth=lineW)
plot(lineOf(rL5, u5), "Long 5", color=colL(4), linewidth=lineW)
plot(lineOf(rL6, u6), "Long 6", color=colL(5), linewidth=lineW)
array<float> valS = array.from(rS1, rS2, rS3, rS4, rS5, rS6)
array<float> valL = array.from(rL1, rL2, rL3, rL4, rL5, rL6)
sortedIdx(array<int> keys, int n) =>
array<int> k = keys.slice(0, n).copy()
k.sort_indices(order.ascending)
array<int> ordS = sortedIdx(keyS, nS)
array<int> ordL = sortedIdx(keyL, nL)
array<float> allV = array.new<float>()
array<string> allN = array.new<string>()
array<color> allC = array.new<color>()
array<bool> allD = array.new<bool>()
for i = 0 to nS - 1
int o = ordS.get(i)
allV.push(valS.get(o))
allN.push(nameS.get(o))
allC.push(colS(o))
allD.push(drawS.get(o))
for i = 0 to nL - 1
int o = ordL.get(i)
allV.push(valL.get(o))
allN.push(nameL.get(o))
allC.push(colL(o))
allD.push(drawL.get(o))
int nOk = 0
int nUp = 0
int nDn = 0
int nHi = 0
int nLo = 0
for v in allV
if not na(v)
nOk += 1
nUp += v > 50 ? 1 : 0
nDn += v < 50 ? 1 : 0
nHi += v >= lvl ? 1 : 0
nLo += v <= LO ? 1 : 0
bool okAll = nOk == N_ALL
bool allUp = okAll and nUp == N_ALL
bool allDn = okAll and nDn == N_ALL
bool allHi = okAll and nHi == N_ALL
bool allLo = okAll and nLo == N_ALL
var int lastPoUp = na
var int lastPoDn = na
var bool prevPoUp = false
var bool prevPoDn = false
var int lastCross = 0
bool evPoUp = false
bool evPoDn = false
bool evGC = false
bool evDC = false
if IS_LEN and barstate.isconfirmed
bool poUp = okAll and N_ALL >= 2
bool poDn = okAll and N_ALL >= 2
if okAll
array<int> keyAll = array.new<int>()
for i = 0 to nS - 1
keyAll.push(keyS.get(ordS.get(i)))
for i = 0 to nL - 1
keyAll.push(keyL.get(ordL.get(i)))
array<int> ordAll = keyAll.sort_indices(order.ascending)
for i = 0 to N_ALL - 2
float va = allV.get(ordAll.get(i))
float vb = allV.get(ordAll.get(i + 1))
poUp := poUp and va > vb
poDn := poDn and va < vb
evPoUp := poUp and not prevPoUp and (na(lastPoUp) or bar_index - lastPoUp >= poGap)
evPoDn := poDn and not prevPoDn and (na(lastPoDn) or bar_index - lastPoDn >= poGap)
if evPoUp
lastPoUp := bar_index
if evPoDn
lastPoDn := bar_index
prevPoUp := poUp
prevPoDn := poDn
int grp = 0
if okAll
float minS = allV.slice(0, nS).min()
float maxS = allV.slice(0, nS).max()
float minL = allV.slice(nS, N_ALL).min()
float maxL = allV.slice(nS, N_ALL).max()
grp := minS > maxL ? 1 : maxS < minL ? -1 : 0
evGC := grp == 1 and lastCross != 1
evDC := grp == -1 and lastCross != -1
if grp != 0
lastCross := grp
string upTxt = (showPO and evPoUp ? "PO" : "") + (showPO and evPoUp and showGC and evGC ? " · " : "") + (showGC and evGC ? "GC" : "")
string dnTxt = (showPO and evPoDn ? "PO" : "") + (showPO and evPoDn and showGC and evDC ? " · " : "") + (showGC and evDC ? "DC" : "")
if upTxt != ""
label.new(bar_index, low, "▲\n" + upTxt, yloc=yloc.belowbar, style=label.style_label_up, color=color.new(upCol, 100), textcolor=upCol, size=txtSize - 1, force_overlay=true,
tooltip=(evPoUp ? "Bullish perfect order: all lines are in order of length, the shortest on top." : "") + (evPoUp and evGC ? "\n" : "") + (evGC ? "Golden cross: all short lines moved above all long lines." : ""))
if dnTxt != ""
label.new(bar_index, high, dnTxt + "\n▼", yloc=yloc.abovebar, style=label.style_label_down, color=color.new(dnCol, 100), textcolor=dnCol, size=txtSize - 1, force_overlay=true,
tooltip=(evPoDn ? "Bearish perfect order: all lines are in order of length, the longest on top." : "") + (evPoDn and evDC ? "\n" : "") + (evDC ? "Death cross: all short lines moved below all long lines." : ""))
numText(float v) => na(v) ? "–" : str.tostring(v, "#")
listText() =>
string s = ""
for i = 0 to N_ALL - 1
s += (i == 0 ? "" : " · ") + allN.get(i) + " " + numText(allV.get(i))
s
allWord() => "All " + str.tostring(N_ALL)
headText() =>
string pre = IS_LEN and isHtf ? tfLabel(tfL) + " · " : ""
string tot = str.tostring(N_ALL)
string s = ""
if nOk < N_ALL
s := pre + "Not enough bars yet for " + str.tostring(N_ALL - nOk) + " of " + tot + " lines"
else if nUp >= nDn
s := pre + (nUp == N_ALL ? allWord() + " above 50" : str.tostring(nUp) + " of " + tot + " above 50") + (nHi > 0 ? " · " + str.tostring(nHi) + " above " + str.tostring(lvl) : "")
else
s := pre + (nDn == N_ALL ? allWord() + " below 50" : str.tostring(nDn) + " of " + tot + " below 50") + (nLo > 0 ? " · " + str.tostring(nLo) + " below " + str.tostring(LO) : "")
s
var table tbl = table.new(tblPos == "Top left" ? position.top_left : tblPos == "Bottom right" ? position.bottom_right : tblPos == "Bottom left" ? position.bottom_left : position.top_right, 2, 13, bgcolor=chart.bg_color, frame_color=color.new(chart.fg_color, 80), frame_width=1, border_color=chart.bg_color, border_width=2, force_overlay=true)
if barstate.islast and showTable
table.clear(tbl, 0, 0, 1, 12)
color hc = allUp ? upCol : allDn ? dnCol : normCol
table.cell(tbl, 0, 0, headText(), text_color=color.white, bgcolor=hc, text_size=txtSize, text_halign=text.align_left)
table.merge_cells(tbl, 0, 0, 1, 0)
for i = 0 to N_ALL - 1
float v = allV.get(i)
bool dr = allD.get(i)
color tc = na(v) ? chart.fg_color : v >= lvl ? upCol : v <= LO ? dnCol : chart.fg_color
string tt = dr ? na : "Lower than the chart: not drawn as a line."
table.cell(tbl, 0, i + 1, (dr ? "━ " : " ") + allN.get(i), text_color=dr ? color.new(allC.get(i), 0) : chart.fg_color, bgcolor=chart.bg_color, text_size=txtSize, text_halign=text.align_left, tooltip=tt)
table.cell(tbl, 1, i + 1, numText(v), text_color=tc, bgcolor=chart.bg_color, text_size=txtSize, text_halign=text.align_right, text_font_family=font.family_monospace, tooltip=tt)
var int pSide = 0
var int pLevel = 0
if barstate.isconfirmed
int side = allUp ? 1 : allDn ? -1 : 0
int level = allHi ? 1 : allLo ? -1 : 0
string head = "[Saikix-Stoch8] " + syminfo.ticker + " " + tfLabel(timeframe.period) + " "
if alLevel and level != 0 and level != pLevel
alert(head + allWord() + (level > 0 ? " above " + str.tostring(lvl) : " below " + str.tostring(LO)) + ": " + listText(), alert.freq_once_per_bar_close)
else if alSide and side != 0 and side != pSide
alert(head + allWord() + (side > 0 ? " above 50" : " below 50") + ": " + listText(), alert.freq_once_per_bar_close)
pSide := side
pLevel := level
if alPO and evPoUp
alert(head + "Bullish perfect order: " + listText(), alert.freq_once_per_bar_close)
if alPO and evPoDn
alert(head + "Bearish perfect order: " + listText(), alert.freq_once_per_bar_close)
if alGC and evGC
alert(head + "Golden cross: " + listText(), alert.freq_once_per_bar_close)
if alGC and evDC
alert(head + "Death cross: " + listText(), alert.freq_once_per_bar_close)