本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// CISD & Liquidity Levels [OraxisHQ] v3.3.0
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © OraxisHQ
//
// Session liquidity (Asia, London, Overnight, Premarket, previous day and week),
// 1H and 15m swing highs/lows with equal highs/lows grouped, Midnight / 8:30 / 9:30
// opens, and CISD (change in state of delivery) setups that print when price
// reverses after taking one of those levels. Built for NQ and ES 1-minute.
indicator("CISD & Liquidity Levels [OraxisHQ]", shorttitle = "CISD+LIQ [OraxisHQ]", overlay = true, max_lines_count = 500, max_labels_count = 500, max_bars_back = 300)
tz = "America/New_York"
grpD = "Display"
daysBack = input.int(3, "Show last N days", minval = 1, group = grpD)
takenOpacity = input.int(30, "Taken draw opacity % (0 = hide)", minval = 0, maxval = 100, group = grpD)
lineAhead = input.int(15, "Live levels: extend N bars past price", minval = 1, maxval = 200, group = grpD,
tooltip = "Untaken levels stop this many candles to the right of the last candle, with their name beside the end of the line.")
lineW = input.int(1, "Level line width", minval = 1, maxval = 4, group = grpD)
showDate = input.bool(true, "Date on level labels", group = grpD,
tooltip = "Adds the date of the candle that made the level, e.g. London High 10/16. Taken levels are cleared at midnight.")
labelGap = input.int(24, "Fold draw names within N ticks", minval = 0, group = grpD,
tooltip = "When two level names would overlap on the chart they are combined into one label. Both lines stay drawn.")
mergeTicks = input.int(4, "Merge draws within N ticks", minval = 0, group = grpD,
tooltip = "Levels on the same side within this distance are treated as one. The stronger one wins (session / PD / PW > 1H > 15m); two of equal rank share one line and one label, e.g. Asia High/Prev Day High.")
drawCool = input.int(45, "A raided level stays spent for N minutes", minval = 0, maxval = 600, group = grpD,
tooltip = "After a level is taken, no new level is drawn at the same price for this many minutes.")
coolBars = math.max(1, int(drawCool * 60 / math.max(1, timeframe.in_seconds())))
grpS = "Session draws"
showAsia = input.bool(true, "Asia KZ H/L (1900-2200 prev eve)", group = grpS)
showLondon = input.bool(true, "London KZ H/L (0200-0500)", group = grpS)
showON = input.bool(true, "Overnight H/L (0000-0700)", group = grpS)
showPM = input.bool(true, "Premarket H/L (0700-0930)", group = grpS)
showPDHL = input.bool(true, "Prev-Day H/L", group = grpS)
showPWHL = input.bool(true, "Prev-Week H/L", group = grpS)
showMid = input.bool(true, "Midnight Open (00:00)", group = grpS)
show830 = input.bool(true, "8:30 Open (news)", group = grpS)
show930 = input.bool(true, "9:30 Open (NY open)", group = grpS)
grpH = "HTF swing draws"
show15 = input.bool(false, "15m swing H/L", group = grpH,
tooltip = "15m swings are always tracked as CISD targets; this only controls whether they are drawn.")
show1H = input.bool(true, "1H swing H/L", group = grpH)
eqOn = input.bool(true, "Group equal highs / lows (EQH / EQL)", group = grpH,
tooltip = "Swings of the same timeframe within the tolerance below become one draw at the most extreme of them, with a line connecting the swing points. Display only.")
eq15Nq = input.float(10, "EQH/EQL tolerance, 15m (points) NQ", minval = 0, step = 0.25, inline = "eq15", group = grpH)
eq15Es = input.float(2, "ES", minval = 0, step = 0.25, inline = "eq15", group = grpH)
eq1HNq = input.float(15, "EQH/EQL tolerance, 1H (points) NQ", minval = 0, step = 0.25, inline = "eq1h", group = grpH)
eq1HEs = input.float(3, "ES", minval = 0, step = 0.25, inline = "eq1h", group = grpH)
eqSwNq = input.float(1.0, "Taken swing still counts if run by at most NQ", minval = 0, step = 0.25, inline = "eqsw", group = grpH)
eqSwEs = input.float(0.25, "ES", minval = 0, step = 0.25, inline = "eqsw", group = grpH,
tooltip = "A swing that price has already traded through can only be part of an equal high/low if the newer swing ran it by this much or less. Above that, the old swing was taken and the new one stands alone. ES values are NQ's scaled to ES's smaller point moves (about 0.2x).")
h1Near = input.int(3, "1H: show nearest N per side", minval = 1, maxval = 20, group = grpH)
h1Way = input.bool(true, "1H: only on the way to a session level", group = grpH,
tooltip = "Show a 1H high only if a live session/PD/PW high sits above it, and a 1H low only if one sits below it -- the 1H swing is a stop on the way to the session level. Display only.")
grpX = "CISD"
showCISD = input.bool(true, "Show CISD lines", group = grpX)
maxLeg = input.int(240, "Max bars sweep->establish", minval = 10, group = grpX)
cisdW = input.int(1, "CISD line width", minval = 1, maxval = 4, group = grpX)
cisdLen = input.int(6, "CISD line length (bars past the print)", minval = 1, maxval = 50, group = grpX,
tooltip = "How far the CISD line is drawn past the candle that established it. "
+ "The setup is still tracked (fill, DONE, STOPPED, log) until it resolves; only "
+ "the drawing stops here.")
stopMode = input.string("Displacement swing", "Stop / invalidation level",
options = ["Displacement swing", "Reversal extreme"], group = grpX,
tooltip = "Displacement swing: behind the swing the displacement leg started from. Reversal extreme: behind the whole reversal. The stop is also the invalidation - a CISD whose stop is hit is marked STOPPED.")
showStop = input.bool(true, "Draw the stop line", group = grpX)
stopCol = input.color(color.new(#9598a1, 25), "Stop", group = grpX)
grpA = "Alerts"
maxAlertRisk = input.float(0.0, "Max risk for an alert (points, 0 = off)", minval = 0, group = grpA,
tooltip = "Skips the alert (not the line) when the distance from the CISD line to its stop is wider than this. 0 = alert on every CISD.")
grpG = "Chart guard"
showGuard = input.bool(true, "Warn if not NQ / ES 1-minute", group = grpG,
tooltip = "Shows a note when the chart is not NQ or ES (incl. MNQ / MES) on 1-minute, the charts this indicator was built and tested on.")
grpW = "Trading windows"
sessOn = input.bool(true, "Only print inside the windows below", group = grpW,
tooltip = "CISDs and their alerts only print when they confirm inside one of the windows switched on below (New York time).")
winNY = input.bool(true, "NY AM", inline = "wny", group = grpW)
winNYs = input.session("0930-1100", "", inline = "wny", group = grpW)
winLon = input.bool(true, "London KZ", inline = "wlo", group = grpW)
winLons = input.session("0200-0500", "", inline = "wlo", group = grpW)
winAsia = input.bool(true, "Asia KZ", inline = "was", group = grpW)
winAsias = input.session("1900-2200", "", inline = "was", group = grpW)
crossMdl = input.bool(true, "A later setup must beat the last one's extreme", group = grpW,
tooltip = "A later CISD in the same direction only prints if its reversal goes beyond the previous one's extreme. Resets once a day at 09:30.")
grpM = "SMT (NQ vs ES)"
smtOn = input.bool(true, "Tag CISDs that show 1m SMT", group = grpM,
tooltip = "Adds SMT to the CISD label when NQ and ES disagree at the 1m swing behind it. Information only - it never removes a CISD.")
symNq = input.symbol("CME_MINI:ES1!", "Compare on an NQ chart with", group = grpM)
symEs = input.symbol("CME_MINI:NQ1!", "Compare on an ES chart with", group = grpM)
smtTol = input.int(4, "Tolerance (ticks)", minval = 0, group = grpM,
tooltip = "How many ticks one index must fail to follow the other by to count as SMT.")
symRoot = str.upper(syminfo.root)
isESsym = symRoot == "ES" or symRoot == "MES"
esSym = isESsym ? symEs : symNq
eq15Tol = isESsym ? eq15Es : eq15Nq
eq1HTol = isESsym ? eq1HEs : eq1HNq
eqSweep = isESsym ? eqSwEs : eqSwNq
grpP = "LH Proxy CISD"
showModel = input.string("Both", "Show which model", options = ["Both", "LH CISD only", "LH Proxy only"], group = grpP,
tooltip = "Choose which CISD type is drawn and alerted. Both are always calculated, because the Proxy depends on the regular CISD. To see each on its own, add the indicator twice.")
proxyOn = input.bool(true, "Proxy: ES takes its swing after NQ took a draw", group = grpP,
tooltip = "LH Proxy: after NQ takes a level, price pushes again, ES takes its own 1m swing and NQ fails to follow (SMT). The CISD that forms from that is labelled LH PROXY.")
grpF = "HTF FVG seeding"
fvgSeed = input.bool(true, "An HTF bearish/bullish FVG counts as a draw taken", group = grpF,
tooltip = "Price tapping back into an unfilled 15m, 1H or 4H fair value gap counts like a level being taken, and can start a CISD in the direction that gap delivers.")
fvg15 = input.bool(true, "15m", inline = "fvgtf", group = grpF)
fvg60 = input.bool(true, "1H", inline = "fvgtf", group = grpF)
fvg240 = input.bool(true, "4H", inline = "fvgtf", group = grpF)
oneFvg = input.bool(true, "One CISD per FVG unless a new low/high is swept", group = grpF,
tooltip = "After a CISD from an FVG, another one from the same delivery only prints if price first takes the previous one's extreme. Resets each day.")
showFvg = input.bool(false, "DEBUG: draw the FVG zones the engine found", group = grpF,
tooltip = "Draws the FVG zones the indicator is tracking, for checking what it sees.")
grpC = "Colors"
bslCol = input.color(#000000, "Liquidity highs", group = grpC)
sslCol = input.color(#000000, "Liquidity lows", group = grpC)
midCol = input.color(#000000, "Midnight Open", group = grpC)
o830Col = input.color(#F23645, "8:30 Open", group = grpC)
o930Col = input.color(#089981, "9:30 Open", group = grpC)
cbCol = input.color(#FF9800, "CISD bullish line", group = grpC)
csCol = input.color(#FF9800, "CISD bearish line", group = grpC)
inWindow = time >= last_bar_time - daysBack * 86400000
f_inWin(on, sess) =>
on and not na(time(timeframe.period, sess, tz))
sessRaw = f_inWin(winNY, winNYs) or f_inWin(winLon, winLons) or f_inWin(winAsia, winAsias)
inSess = not sessOn or sessRaw
var float lastBearExt = na
var float lastBullExt = na
rthOpen = not na(time(timeframe.period, "0930-0931", tz))
if rthOpen and not rthOpen[1]
lastBearExt := na
lastBullExt := na
f_sess(sess) =>
inS = not na(time(timeframe.period, sess, tz))
var float hi = na
var float lo = na
var int hiT = na
var int loT = na
started = inS and not inS[1]
ended = not inS and inS[1]
if started
hi := high
lo := low
hiT := time
loT := time
else if inS
if high > hi
hi := high
hiT := time
if low < lo
lo := low
loT := time
[hi, lo, started, ended, hiT, loT]
[asiaH_r, asiaL_r, asiaS, asiaE, asiaHT, asiaLT] = f_sess("1900-2201")
[lonH_r, lonL_r, lonS, lonE, lonHT, lonLT] = f_sess("0200-0501")
[onH_r, onL_r, onS, onE, onHT, onLT] = f_sess("0000-0700")
[pmH_r, pmL_r, pmS, pmE, pmHT, pmLT] = f_sess("0700-0930")
pdh = request.security(syminfo.tickerid, "D", high[1], lookahead = barmerge.lookahead_on)
pdl = request.security(syminfo.tickerid, "D", low[1], lookahead = barmerge.lookahead_on)
pwh = request.security(syminfo.tickerid, "W", high[1], lookahead = barmerge.lookahead_on)
pwl = request.security(syminfo.tickerid, "W", low[1], lookahead = barmerge.lookahead_on)
newDay = ta.change(time("D")) != 0
newWeek = ta.change(time("W")) != 0
f_extT(isNew) =>
var float rH = na
var float rL = na
var int rHT = na
var int rLT = na
var int pHT = na
var int pLT = na
if isNew
pHT := rHT
pLT := rLT
rH := high
rL := low
rHT := time
rLT := time
else
if na(rH) or high > rH
rH := high
rHT := time
if na(rL) or low < rL
rL := low
rLT := time
[pHT, pLT]
[pdhT, pdlT] = f_extT(newDay)
[pwhT, pwlT] = f_extT(newWeek)
isMid = not na(time(timeframe.period, "0000-0001", tz))
f_swHigh() =>
l = high[3]
p = high[2]
r = high[1]
ok = p >= l and p >= r and (p > l or p > r)
[ok ? p : na, ok ? time[2] : na]
f_swLow() =>
l = low[3]
p = low[2]
r = low[1]
ok = p <= l and p <= r and (p < l or p < r)
[ok ? p : na, ok ? time[2] : na]
[ph15, pt15] = request.security(syminfo.tickerid, "15", f_swHigh(), lookahead = barmerge.lookahead_on)
[pl15, qt15] = request.security(syminfo.tickerid, "15", f_swLow(), lookahead = barmerge.lookahead_on)
[ph60, pt60] = request.security(syminfo.tickerid, "60", f_swHigh(), lookahead = barmerge.lookahead_on)
[pl60, qt60] = request.security(syminfo.tickerid, "60", f_swLow(), lookahead = barmerge.lookahead_on)
f_exactT(t0, tfSec, price, isHigh) =>
int r = t0
if not na(t0) and not na(price)
tEnd = t0 + tfSec * 1000
for k = 0 to 299
if time[k] < t0
break
if time[k] < tEnd and math.abs((isHigh ? high[k] : low[k]) - price) < syminfo.mintick / 2
r := time[k]
r
fresh_ph15 = not na(pt15) and (na(pt15[1]) or pt15 != pt15[1])
fresh_pl15 = not na(qt15) and (na(qt15[1]) or qt15 != qt15[1])
fresh_ph60 = not na(pt60) and (na(pt60[1]) or pt60 != pt60[1])
fresh_pl60 = not na(qt60) and (na(qt60[1]) or qt60 != qt60[1])
RANK_SESSION = 3
RANK_1H = 2
RANK_15M = 1
var array<line> dLine = array.new<line>()
var array<label> dLabel = array.new<label>()
var array<float> dPrice = array.new_float()
var array<bool> dIsLow = array.new_bool()
var array<bool> dTaken = array.new_bool()
var array<int> dTakenB = array.new_int()
var array<color> dCol = array.new<color>()
var array<int> dForm = array.new_int()
var array<int> dRank = array.new_int()
var array<string> dTxt = array.new<string>()
var array<bool> dVis = array.new_bool()
var array<int> dId = array.new_int()
var array<string> dDate = array.new_string()
var array<int> dTakenT = array.new_int()
var array<bool> dEqMem = array.new_bool()
var array<int> dEqN = array.new_int()
var array<float> dEqBot = array.new_float()
var array<int> dNextId = array.from(0)
var array<line> cnLine = array.new<line>()
var array<int> cnTop = array.new_int()
var array<bool> cnDone = array.new_bool()
f_dropDraw(i) =>
ln = array.get(dLine, i)
lb = array.get(dLabel, i)
line.delete(ln)
if not na(lb)
label.delete(lb)
array.remove(dLine, i)
array.remove(dLabel, i)
array.remove(dPrice, i)
array.remove(dIsLow, i)
array.remove(dTaken, i)
array.remove(dTakenB, i)
array.remove(dCol, i)
array.remove(dForm, i)
array.remove(dRank, i)
array.remove(dTxt, i)
array.remove(dVis, i)
array.remove(dId, i)
array.remove(dDate, i)
array.remove(dTakenT, i)
array.remove(dEqMem, i)
array.remove(dEqN, i)
array.remove(dEqBot, i)
f_newDraw(cond, price, isLow, txt, baseCol, rank, t0) =>
line result = na
if cond and not na(price) and inWindow
tol = mergeTicks * syminfo.mintick
int bestIdx = -1
int bestRank = 0
if array.size(dLine) > 0
for i = 0 to array.size(dLine) - 1
if not array.get(dTaken, i) and array.get(dIsLow, i) == isLow and math.abs(array.get(dPrice, i) - price) <= tol
if array.get(dRank, i) > bestRank
bestRank := array.get(dRank, i)
bestIdx := i
bool spent = false
if array.size(dLine) > 0
for i = 0 to array.size(dLine) - 1
if array.get(dTaken, i) and array.get(dIsLow, i) == isLow and math.abs(array.get(dPrice, i) - price) <= tol
tb = array.get(dTakenB, i)
if not na(tb) and bar_index - tb <= coolBars
spent := true
int eqTop = -1
int eqSwp = -1
eqT = rank == RANK_15M ? eq15Tol : rank == RANK_1H ? eq1HTol : 0.0
if eqOn and rank < RANK_SESSION and not spent and array.size(dLine) > 0
float bestD = na
for i = 0 to array.size(dLine) - 1
if array.get(dRank, i) == rank and array.get(dIsLow, i) == isLow and not array.get(dEqMem, i) and not array.get(dTaken, i)
pi = array.get(dPrice, i)
top = isLow ? math.min(pi, price) : math.max(pi, price)
bot = isLow ? math.max(array.get(dEqBot, i), price) : math.min(array.get(dEqBot, i), price)
if math.abs(top - bot) <= eqT and (na(bestD) or math.abs(pi - price) < bestD)
bestD := math.abs(pi - price)
eqTop := i
if eqTop < 0 and not na(t0)
tfMs = rank == RANK_15M ? 900000 : 3600000
tLeft = t0 - t0 % tfMs - tfMs
for i = array.size(dLine) - 1 to 0
if array.get(dRank, i) == rank and array.get(dIsLow, i) == isLow and array.get(dTaken, i) and not array.get(dEqMem, i) and array.get(dEqN, i) == 1
beyond = isLow ? array.get(dPrice, i) - price : price - array.get(dPrice, i)
tt = array.get(dTakenT, i)
if beyond > 0 and beyond <= math.min(eqT, eqSweep) and not na(tt) and tt >= tLeft and tt <= time
eqSwp := i
break
eqId = eqTop >= 0 ? array.get(dId, eqTop) : eqSwp >= 0 ? array.get(dId, eqSwp) : -1
bool make = true
if spent
make := false
else if bestIdx >= 0 and bestRank > rank
make := false
else if eqTop >= 0 or eqSwp >= 0
make := true
else if bestIdx >= 0
if bestRank > rank
make := false
else if bestRank == rank
make := false
merged = array.get(dTxt, bestIdx) + "/" + txt
array.set(dTxt, bestIdx, merged)
lb = array.get(dLabel, bestIdx)
if not na(lb)
label.set_text(lb, merged)
if make
if array.size(dLine) > 0
for i = array.size(dLine) - 1 to 0
if not array.get(dTaken, i) and array.get(dIsLow, i) == isLow and array.get(dRank, i) < rank and math.abs(array.get(dPrice, i) - price) <= tol
f_dropDraw(i)
x1 = na(t0) or t0 > time ? time : t0
xEnd = time + lineAhead * timeframe.in_seconds() * 1000
ln = line.new(x1, price, xEnd, price, xloc = xloc.bar_time, color = baseCol, width = lineW, style = line.style_solid)
lb = label.new(xEnd, price, txt, xloc = xloc.bar_time, style = label.style_label_left, textcolor = baseCol, color = color.new(color.black, 100), size = size.small)
array.push(dLine, ln)
array.push(dLabel, lb)
array.push(dPrice, price)
array.push(dIsLow, isLow)
array.push(dTaken, false)
array.push(dTakenB, na)
array.push(dCol, baseCol)
array.push(dForm, bar_index)
array.push(dRank, rank)
array.push(dTxt, txt)
array.push(dVis, true)
array.push(dId, array.get(dNextId, 0))
array.push(dDate, str.format_time(x1, "MM/dd", tz))
array.push(dTakenT, na)
array.push(dEqMem, false)
array.push(dEqN, 1)
array.push(dEqBot, price)
array.set(dNextId, 0, array.get(dNextId, 0) + 1)
k = array.size(dLine) - 1
eqName = (rank == RANK_15M ? "15m " : "1H ") + (isLow ? "EQL" : "EQH")
if eqTop >= 0 or eqSwp >= 0
int g = -1
for i = 0 to k - 1
if array.get(dId, i) == eqId
g := i
if g >= 0
if eqTop >= 0
array.set(dEqMem, k, true)
array.set(dEqN, g, array.get(dEqN, g) + 1)
array.set(dEqBot, g, isLow ? math.max(array.get(dEqBot, g), price) : math.min(array.get(dEqBot, g), price))
array.set(dTxt, g, eqName)
label.set_text(array.get(dLabel, g), eqName)
array.push(cnLine, line.new(x1, price, line.get_x1(array.get(dLine, g)), array.get(dPrice, g), xloc = xloc.bar_time, color = baseCol, width = lineW))
array.push(cnTop, array.get(dId, g))
array.push(cnDone, false)
else
qx = line.get_x1(array.get(dLine, g))
line.delete(array.get(dLine, g))
lq = array.get(dLabel, g)
if not na(lq)
label.delete(lq)
array.set(dEqMem, g, true)
array.set(dEqN, k, 2)
array.set(dEqBot, k, array.get(dPrice, g))
array.set(dTxt, k, eqName)
label.set_text(lb, eqName)
array.push(cnLine, line.new(qx, array.get(dPrice, g), x1, price, xloc = xloc.bar_time, color = baseCol, width = lineW))
array.push(cnTop, array.get(dId, k))
array.push(cnDone, false)
result := ln
result
f_newDraw(showAsia and asiaE, asiaL_r, true, "Asia Low", sslCol, RANK_SESSION, asiaLT)
f_newDraw(showAsia and asiaE, asiaH_r, false, "Asia High", bslCol, RANK_SESSION, asiaHT)
f_newDraw(showLondon and lonE, lonL_r, true, "London Low", sslCol, RANK_SESSION, lonLT)
f_newDraw(showLondon and lonE, lonH_r, false, "London High", bslCol, RANK_SESSION, lonHT)
f_newDraw(showON and onE, onL_r, true, "Overnight Low", sslCol, RANK_SESSION, onLT)
f_newDraw(showON and onE, onH_r, false, "Overnight High", bslCol, RANK_SESSION, onHT)
f_newDraw(showPM and pmE, pmL_r, true, "Premarket Low", sslCol, RANK_SESSION, pmLT)
f_newDraw(showPM and pmE, pmH_r, false, "Premarket High", bslCol, RANK_SESSION, pmHT)
f_newDraw(showPDHL and newDay, pdl, true, "Prev Day Low", sslCol, RANK_SESSION, pdlT)
f_newDraw(showPDHL and newDay, pdh, false, "Prev Day High", bslCol, RANK_SESSION, pdhT)
f_newDraw(showPWHL and newWeek, pwl, true, "Prev Week Low", sslCol, RANK_SESSION, pwlT)
f_newDraw(showPWHL and newWeek, pwh, false, "Prev Week High", bslCol, RANK_SESSION, pwhT)
pl60T = f_exactT(qt60, 3600, pl60, false)
ph60T = f_exactT(pt60, 3600, ph60, true)
pl15T = f_exactT(qt15, 900, pl15, false)
ph15T = f_exactT(pt15, 900, ph15, true)
f_newDraw(fresh_pl60, pl60, true, "1H Low", sslCol, RANK_1H, pl60T)
f_newDraw(fresh_ph60, ph60, false, "1H High", bslCol, RANK_1H, ph60T)
f_newDraw(fresh_pl15, pl15, true, "15m Low", sslCol, RANK_15M, pl15T)
f_newDraw(fresh_ph15, ph15, false, "15m High", bslCol, RANK_15M, ph15T)
if isMid and not isMid[1] and array.size(dLine) > 0
for i = array.size(dLine) - 1 to 0
if array.get(dTaken, i)
tb = array.get(dTakenB, i)
if na(tb) or bar_index - tb > coolBars
f_dropDraw(i)
fadeT = 100 - takenOpacity
barMs = timeframe.in_seconds() * 1000
aheadX = time + lineAhead * barMs
f_openLine(isT, txt, show, col) =>
var line ln = na
var label lb = na
if isT and not isT[1]
if not na(ln)
line.set_x2(ln, time)
if not na(lb)
label.delete(lb)
ln := na
lb := na
if show and inWindow
ln := line.new(time, open, aheadX, open, xloc = xloc.bar_time, color = col, width = lineW, style = line.style_dashed)
lb := label.new(aheadX, open, txt + (showDate ? " " + str.format_time(time, "MM/dd", tz) : ""),
xloc = xloc.bar_time, style = label.style_label_left, textcolor = col,
color = color.new(color.black, 100), size = size.small)
if not na(ln)
line.set_x2(ln, aheadX)
label.set_x(lb, aheadX)
is830 = not na(time(timeframe.period, "0830-0831", tz))
is930 = not na(time(timeframe.period, "0930-0931", tz))
f_openLine(isMid, "Midnight Open", showMid, midCol)
f_openLine(is830, "8:30 Open", show830, o830Col)
f_openLine(is930, "9:30 Open", show930, o930Col)
if array.size(dLine) > 0
for i = 0 to array.size(dLine) - 1
if not array.get(dTaken, i)
p = array.get(dPrice, i)
isLow = array.get(dIsLow, i)
ln = array.get(dLine, i)
lb = array.get(dLabel, i)
taken = bar_index > array.get(dForm, i) and (isLow ? low < p : high > p)
if taken
if takenOpacity <= 0 or not array.get(dVis, i)
line.delete(ln)
if not na(lb)
label.delete(lb)
else
line.set_x2(ln, time)
line.set_color(ln, color.new(array.get(dCol, i), fadeT))
if not na(lb)
label.set_x(lb, int((line.get_x1(ln) + time) / 2))
label.set_style(lb, isLow ? label.style_label_up : label.style_label_down)
label.set_textcolor(lb, color.new(array.get(dCol, i), fadeT))
array.set(dTaken, i, true)
array.set(dTakenB, i, bar_index)
array.set(dTakenT, i, time)
else
line.set_x2(ln, aheadX)
if not na(lb)
label.set_x(lb, aheadX)
if array.size(dLine) > 0
hidLn = array.new_bool(array.size(dLine), false)
hidLb = array.new_bool(array.size(dLine), false)
txt = array.new_string(array.size(dLine), "")
for i = 0 to array.size(dLine) - 1
array.set(txt, i, array.get(dTxt, i))
for i = 0 to array.size(dLine) - 1
if not array.get(dTaken, i) and array.get(dEqMem, i)
array.set(hidLn, i, true)
array.set(hidLb, i, true)
for i = 0 to array.size(dLine) - 1
if not array.get(dTaken, i) and array.get(dRank, i) == RANK_15M and not show15
array.set(hidLn, i, true)
array.set(hidLb, i, true)
for sIdx = 0 to 1
isLowS = sIdx == 0
float sess = na
for i = 0 to array.size(dLine) - 1
if not array.get(dTaken, i) and array.get(dIsLow, i) == isLowS and array.get(dRank, i) >= RANK_SESSION
pi = array.get(dPrice, i)
if (isLowS ? pi < close : pi > close) and (na(sess) or (isLowS ? pi < sess : pi > sess))
sess := pi
cand = array.new_int()
dist = array.new_float()
for i = 0 to array.size(dLine) - 1
if not array.get(dTaken, i) and array.get(dIsLow, i) == isLowS and array.get(dRank, i) == RANK_1H
pi = array.get(dPrice, i)
onWay = not h1Way or (not na(sess) and (isLowS ? pi > sess : pi < sess))
if show1H and onWay and not array.get(hidLn, i)
array.push(cand, i)
array.push(dist, math.abs(pi - close))
else
array.set(hidLn, i, true)
array.set(hidLb, i, true)
if array.size(cand) > h1Near
ord = array.sort_indices(dist, order.ascending)
for k = h1Near to array.size(ord) - 1
hIdx = array.get(cand, array.get(ord, k))
array.set(hidLn, hIdx, true)
array.set(hidLb, hIdx, true)
if labelGap > 0 and array.size(dLine) > 1
gap = labelGap * syminfo.mintick
for i = 0 to array.size(dLine) - 2
if not array.get(dTaken, i) and not array.get(hidLb, i)
for j = i + 1 to array.size(dLine) - 1
if not array.get(dTaken, j) and not array.get(hidLb, j)
and array.get(dIsLow, j) == array.get(dIsLow, i)
and math.abs(array.get(dPrice, j) - array.get(dPrice, i)) <= gap
strong = array.get(dRank, i) >= array.get(dRank, j) ? i : j
weak = strong == i ? j : i
array.set(txt, strong, array.get(txt, strong) + " / " + array.get(txt, weak))
array.set(hidLb, weak, true)
for i = 0 to array.size(dLine) - 1
if not array.get(dTaken, i)
ln = array.get(dLine, i)
line.set_color(ln, array.get(hidLn, i) ? color.new(color.black, 100)
: array.get(dCol, i))
array.set(dVis, i, not array.get(hidLn, i))
lb = array.get(dLabel, i)
if not na(lb)
label.set_text(lb, array.get(hidLb, i) ? "" : array.get(txt, i)
+ (showDate ? " " + array.get(dDate, i) : ""))
if array.size(cnLine) > 0
for z = array.size(cnLine) - 1 to 0
if not array.get(cnDone, z)
int g = -1
for i = 0 to array.size(dId) - 1
if array.get(dId, i) == array.get(cnTop, z)
g := i
break
cl = array.get(cnLine, z)
if g < 0
line.delete(cl)
array.remove(cnLine, z)
array.remove(cnTop, z)
array.remove(cnDone, z)
else if array.get(dTaken, g)
if takenOpacity <= 0 or not array.get(dVis, g)
line.delete(cl)
else
line.set_color(cl, color.new(array.get(dCol, g), 100 - takenOpacity))
array.set(cnDone, z, true)
else
line.set_color(cl, array.get(dVis, g) ? array.get(dCol, g) : color.new(color.black, 100))
var array<float> sslArr = array.new_float()
var array<float> bslArr = array.new_float()
f_pushLow(arr, cond, p) =>
if cond and not na(p) and close > p
array.push(arr, p)
f_pushHigh(arr, cond, p) =>
if cond and not na(p) and close < p
array.push(arr, p)
f_pushLow(sslArr, asiaE, asiaL_r)
f_pushHigh(bslArr, asiaE, asiaH_r)
f_pushLow(sslArr, lonE, lonL_r)
f_pushHigh(bslArr, lonE, lonH_r)
f_pushLow(sslArr, onE, onL_r)
f_pushHigh(bslArr, onE, onH_r)
f_pushLow(sslArr, pmE, pmL_r)
f_pushHigh(bslArr, pmE, pmH_r)
f_pushLow(sslArr, newDay, pdl)
f_pushHigh(bslArr, newDay, pdh)
f_pushLow(sslArr, newDay, pwl)
f_pushHigh(bslArr, newDay, pwh)
f_pushLow(sslArr, fresh_pl15, pl15)
f_pushHigh(bslArr, fresh_ph15, ph15)
f_pushLow(sslArr, fresh_pl60, pl60)
f_pushHigh(bslArr, fresh_ph60, ph60)
f_sweepLow(arr) =>
hit = false
i = array.size(arr) - 1
while i >= 0
if low < array.get(arr, i)
hit := true
array.remove(arr, i)
i -= 1
hit
f_sweepHigh(arr) =>
hit = false
i = array.size(arr) - 1
while i >= 0
if high > array.get(arr, i)
hit := true
array.remove(arr, i)
i -= 1
hit
sweptSSL = f_sweepLow(sslArr)
sweptBSL = f_sweepHigh(bslArr)
f_trigBull() =>
re = -1
for k = 0 to 240
if close[k] < open[k]
re := k
break
float trig = na
int orig = re
if re >= 0
rs = re
for k = re to 240
if close[k] < open[k]
rs := k
else
break
t = open[re]
for k = re to rs
t := math.max(t, open[k])
trig := t
orig := rs
[trig, orig]
f_trigBear() =>
re = -1
for k = 0 to 240
if close[k] > open[k]
re := k
break
float trig = na
int orig = re
if re >= 0
rs = re
for k = re to 240
if close[k] > open[k]
rs := k
else
break
t = open[re]
for k = re to rs
t := math.min(t, open[k])
trig := t
orig := rs
[trig, orig]
f_fvg() =>
bullG = low[1] > high[3]
bearG = high[1] < low[3]
[bullG ? high[3] : na, bullG ? low[1] : na, bearG ? high[1] : na, bearG ? low[3] : na]
[bl15, bh15, sl15, sh15] = request.security(syminfo.tickerid, "15", f_fvg(), lookahead = barmerge.lookahead_on)
[bl60, bh60, sl60, sh60] = request.security(syminfo.tickerid, "60", f_fvg(), lookahead = barmerge.lookahead_on)
[bl240, bh240, sl240, sh240] = request.security(syminfo.tickerid, "240", f_fvg(), lookahead = barmerge.lookahead_on)
var array<float> zLo = array.new_float()
var array<float> zHi = array.new_float()
var array<bool> zBear = array.new_bool()
var array<box> zBox = array.new<box>()
var array<bool> zSpent = array.new_bool()
var array<bool> zIn = array.new_bool()
var array<float> zMark = array.new_float()
MAXZONE = 40
f_pushZone(lo, hi, bear, fresh, col) =>
if fresh and not na(lo) and not na(hi)
dup = false
if array.size(zLo) > 0
for i = 0 to array.size(zLo) - 1
if array.get(zBear, i) == bear and array.get(zLo, i) == lo
and array.get(zHi, i) == hi
dup := true
if not dup
array.push(zLo, lo)
array.push(zHi, hi)
array.push(zBear, bear)
array.push(zSpent, false)
array.push(zIn, false)
array.push(zMark, na)
array.push(zBox, showFvg ? box.new(bar_index, hi, bar_index + 1, lo,
border_color = col, bgcolor = color.new(col, 92),
extend = extend.right) : na)
if array.size(zLo) > MAXZONE
ob = array.shift(zBox)
if not na(ob)
box.delete(ob)
array.shift(zLo)
array.shift(zHi)
array.shift(zBear)
array.shift(zSpent)
array.shift(zIn)
array.shift(zMark)
fs15 = not na(sl15) and (na(sl15[1]) or sl15 != sl15[1] or sh15 != sh15[1])
fs60 = not na(sl60) and (na(sl60[1]) or sl60 != sl60[1] or sh60 != sh60[1])
fs240 = not na(sl240) and (na(sl240[1]) or sl240 != sl240[1] or sh240 != sh240[1])
fb15 = not na(bl15) and (na(bl15[1]) or bl15 != bl15[1] or bh15 != bh15[1])
fb60 = not na(bl60) and (na(bl60[1]) or bl60 != bl60[1] or bh60 != bh60[1])
fb240 = not na(bl240) and (na(bl240[1]) or bl240 != bl240[1] or bh240 != bh240[1])
f_pushZone(sl15, sh15, true, fs15 and fvg15, csCol)
f_pushZone(sl60, sh60, true, fs60 and fvg60, csCol)
f_pushZone(sl240, sh240, true, fs240 and fvg240, csCol)
f_pushZone(bl15, bh15, false, fb15 and fvg15, cbCol)
f_pushZone(bl60, bh60, false, fb60 and fvg60, cbCol)
f_pushZone(bl240, bh240, false, fb240 and fvg240, cbCol)
bool bearFvgTap = false
bool bullFvgTap = false
bool bearBlock = false
bool bullBlock = false
if array.size(zLo) > 0
zi = array.size(zLo) - 1
while zi >= 0
bear = array.get(zBear, zi)
zl = array.get(zLo, zi)
zh = array.get(zHi, zi)
touch = bear ? high >= zl : low <= zh
fill = bear ? close > zh : close < zl
mk = array.get(zMark, zi)
if not array.get(zSpent, zi)
if touch
if bear
bearFvgTap := true
else
bullFvgTap := true
array.set(zSpent, zi, true)
array.set(zIn, zi, true)
array.set(zMark, zi, bear ? high : low)
else if array.get(zIn, zi)
if touch
array.set(zMark, zi, bear ? math.max(mk, high) : math.min(mk, low))
else
array.set(zIn, zi, false)
else
swept = na(mk) or (bear ? high > mk : low < mk)
reman = swept or not oneFvg
if touch and not swept
if bear
bearBlock := true
else
bullBlock := true
if touch and reman
if bear
bearFvgTap := true
else
bullFvgTap := true
array.set(zIn, zi, true)
array.set(zMark, zi, bear ? high : low)
if fill
bxf = array.get(zBox, zi)
if not na(bxf)
box.set_extend(bxf, extend.none)
box.set_right(bxf, bar_index)
array.remove(zLo, zi)
array.remove(zHi, zi)
array.remove(zBear, zi)
array.remove(zSpent, zi)
array.remove(zIn, zi)
array.remove(zMark, zi)
array.remove(zBox, zi)
zi -= 1
bullFvgSeed = fvgSeed and bullFvgTap
bearFvgSeed = fvgSeed and bearFvgTap
bullSeed = sweptSSL or bullFvgSeed
bearSeed = sweptBSL or bearFvgSeed
esLow = request.security(esSym, timeframe.period, low)
esHigh = request.security(esSym, timeframe.period, high)
smtTolP = smtTol * syminfo.mintick
pvH = high[1] >= high[2] and high[1] >= high and (high[1] > high[2] or high[1] > high)
pvL = low[1] <= low[2] and low[1] <= low and (low[1] < low[2] or low[1] < low)
var float lastSwHigh = na
var float lastSwLow = na
var float lastSwHighEs = na
var float lastSwLowEs = na
if pvH
lastSwHigh := high[1]
lastSwHighEs := esHigh[1]
if pvL
lastSwLow := low[1]
lastSwLowEs := esLow[1]
pvHes = esHigh[1] >= esHigh[2] and esHigh[1] >= esHigh
and (esHigh[1] > esHigh[2] or esHigh[1] > esHigh)
pvLes = esLow[1] <= esLow[2] and esLow[1] <= esLow
and (esLow[1] < esLow[2] or esLow[1] < esLow)
var float esSwHigh = na
var float esSwLow = na
if pvHes
esSwHigh := esHigh[1]
if pvLes
esSwLow := esLow[1]
var bool inBull = false
var bool inBear = false
proxyBear = proxyOn and inBear and not na(esSwHigh) and not na(lastSwHigh) and not bearBlock
and esHigh > esSwHigh + smtTolP and high <= lastSwHigh + smtTolP
proxyBull = proxyOn and inBull and not na(esSwLow) and not na(lastSwLow) and not bullBlock
and esLow < esSwLow - smtTolP and low >= lastSwLow - smtTolP
h31 = ta.highest(high, 31)
l31 = ta.lowest(low, 31)
var array<line> cLine = array.new<line>()
var array<label> cLbl = array.new<label>()
var array<float> cStop = array.new_float()
var array<int> cDir = array.new_int()
var array<line> cStpLn = array.new<line>()
var array<float> cTgt = array.new_float()
var array<string> cTgtNm = array.new<string>()
var array<float> cEntry = array.new_float()
var array<bool> cDone = array.new_bool()
var array<bool> cFill = array.new_bool()
var array<int> cT = array.new_int()
var array<bool> cSmt = array.new_bool()
var array<bool> cPxy = array.new_bool()
f_findDOL(trig, dir) =>
float best = na
string nm = ""
if array.size(dPrice) > 0
for i = 0 to array.size(dPrice) - 1
if not array.get(dTaken, i) and array.get(dVis, i)
px = array.get(dPrice, i)
isLow = array.get(dIsLow, i)
ok = dir == 1 ? (not isLow and px > trig) : (isLow and px < trig)
if ok and (na(best) or (dir == 1 ? px < best : px > best))
best := px
nm := array.get(dTxt, i)
[best, nm]
f_stopFor(ext, trig, dir) =>
float s = ext
if stopMode == "Displacement swing"
if dir == 1
if not na(lastSwLow) and lastSwLow > ext and lastSwLow < trig
s := lastSwLow
else
if not na(lastSwHigh) and lastSwHigh < ext and lastSwHigh > trig
s := lastSwHigh
s
f_addCisd(orig, trig, ext, dir, col, smt, proxy) =>
modelOK = showModel == "Both" or (proxy ? showModel == "LH Proxy only" : showModel == "LH CISD only")
if showCISD and inWindow and inSess and modelOK
stop = f_stopFor(ext, trig, dir)
cEnd = bar_index + cisdLen
array.push(cLine, line.new(orig, trig, cEnd, trig, color = col, width = cisdW))
array.push(cLbl, label.new(int((orig + bar_index) / 2), trig, (proxy ? "LH PROXY" : "LH CISD") + (smt ? " SMT" : ""), style = dir == 1 ? label.style_label_down : label.style_label_up, textcolor = col, color = color.new(color.black, 100), size = size.small))
array.push(cStop, stop)
array.push(cDir, dir)
array.push(cStpLn, showStop ? line.new(orig, stop, cEnd, stop, color = stopCol, width = 1, style = line.style_dotted) : na)
[tgt, tnm] = f_findDOL(trig, dir)
array.push(cTgt, tgt)
array.push(cTgtNm, tnm)
array.push(cEntry, trig)
array.push(cDone, false)
array.push(cFill, false)
array.push(cT, time)
array.push(cSmt, smt)
array.push(cPxy, proxy)
bullFire = false
bearFire = false
pxyFire = false
float alLine = na
float alStop = na
var float bExtLow = na
var int bExtBar = na
var bool bFromFvg = false
var bool bFromProxy = false
var float bRefNq = na
var float bRefEs = na
var float bEsMin = na
var float bTrig = na
var int bOrig = na
var float bPriorHi = na
var bool bConf = false
if (bullSeed or proxyBull) and (not inBull or not bConf or (proxyBull and not bFromProxy))
inBull := true
bFromFvg := bullFvgSeed and not sweptSSL
bFromProxy := proxyBull and not sweptSSL and not bullFvgSeed
bExtBar := bar_index
bExtLow := low
bRefNq := lastSwLow
bRefEs := lastSwLowEs
bEsMin := esLow
[tg, og] = f_trigBull()
bTrig := tg
bOrig := bar_index - og
bPriorHi := na(lastSwHigh) ? h31 : lastSwHigh
bConf := false
if inBull
bEsMin := na(bEsMin) ? esLow : math.min(bEsMin, esLow)
if low < bExtLow
bExtBar := bar_index
bExtLow := low
bRefNq := lastSwLow
bRefEs := lastSwLowEs
bEsMin := esLow
[tg, og] = f_trigBull()
bTrig := tg
bOrig := bar_index - og
bPriorHi := na(lastSwHigh) ? h31 : lastSwHigh
bConf := false
else
if not bConf and not na(bTrig) and bar_index > bExtBar and close > bTrig
bConf := true
if bConf and not na(bPriorHi) and close > bPriorHi
smtB = smtOn and not na(bRefNq) and not na(bRefEs)
and bExtLow < bRefNq - smtTolP and not (bEsMin < bRefEs - smtTolP)
okNewB = not crossMdl or na(lastBullExt) or bExtLow < lastBullExt
if okNewB
lastBullExt := na(lastBullExt) ? bExtLow : math.min(lastBullExt, bExtLow)
f_addCisd(bOrig, bTrig, bExtLow, 1, cbCol, smtB, bFromProxy)
bullFire := true
pxyFire := bFromProxy
alLine := bTrig
alStop := f_stopFor(bExtLow, bTrig, 1)
inBull := false
if inBull and bar_index - bExtBar > maxLeg
inBull := false
var float sExtHigh = na
var int sExtBar = na
var bool sFromFvg = false
var bool sFromProxy = false
var float sRefNq = na
var float sRefEs = na
var float sEsMax = na
var float sTrig = na
var int sOrig = na
var float sPriorLo = na
var bool sConf = false
if (bearSeed or proxyBear) and (not inBear or not sConf or (proxyBear and not sFromProxy))
inBear := true
sFromFvg := bearFvgSeed and not sweptBSL
sFromProxy := proxyBear and not sweptBSL and not bearFvgSeed
sExtBar := bar_index
sExtHigh := high
sRefNq := lastSwHigh
sRefEs := lastSwHighEs
sEsMax := esHigh
[tg, og] = f_trigBear()
sTrig := tg
sOrig := bar_index - og
sPriorLo := na(lastSwLow) ? l31 : lastSwLow
sConf := false
if inBear
sEsMax := na(sEsMax) ? esHigh : math.max(sEsMax, esHigh)
if high > sExtHigh
sExtBar := bar_index
sExtHigh := high
sRefNq := lastSwHigh
sRefEs := lastSwHighEs
sEsMax := esHigh
[tg, og] = f_trigBear()
sTrig := tg
sOrig := bar_index - og
sPriorLo := na(lastSwLow) ? l31 : lastSwLow
sConf := false
else
if not sConf and not na(sTrig) and bar_index > sExtBar and close < sTrig
sConf := true
if sConf and not na(sPriorLo) and close < sPriorLo
smtS = smtOn and not na(sRefNq) and not na(sRefEs)
and sExtHigh > sRefNq + smtTolP and not (sEsMax > sRefEs + smtTolP)
okNewS = not crossMdl or na(lastBearExt) or sExtHigh > lastBearExt
if okNewS
lastBearExt := na(lastBearExt) ? sExtHigh : math.max(lastBearExt, sExtHigh)
f_addCisd(sOrig, sTrig, sExtHigh, -1, csCol, smtS, sFromProxy)
bearFire := true
pxyFire := sFromProxy
alLine := sTrig
alStop := f_stopFor(sExtHigh, sTrig, -1)
inBear := false
if inBear and bar_index - sExtBar > maxLeg
inBear := false
if array.size(cLine) > 0
ci = array.size(cLine) - 1
while ci >= 0
if not array.get(cFill, ci) and time > array.get(cT, ci)
entF = array.get(cEntry, ci)
if (array.get(cDir, ci) == 1 ? low <= entF : high >= entF)
array.set(cFill, ci, true)
dead = (array.get(cDir, ci) == 1 ? low < array.get(cStop, ci) : high > array.get(cStop, ci))
or (isMid and not isMid[1])
if dead
array.remove(cLine, ci)
array.remove(cLbl, ci)
array.remove(cStop, ci)
array.remove(cDir, ci)
array.remove(cStpLn, ci)
array.remove(cTgt, ci)
array.remove(cTgtNm, ci)
array.remove(cEntry, ci)
array.remove(cDone, ci)
array.remove(cFill, ci)
array.remove(cT, ci)
array.remove(cSmt, ci)
array.remove(cPxy, ci)
ci -= 1
riskPts = math.abs(alLine - alStop)
passRisk = maxAlertRisk <= 0 or (not na(riskPts) and riskPts <= maxAlertRisk)
alertModelOK = showModel == "Both" or (pxyFire ? showModel == "LH Proxy only" : showModel == "LH CISD only")
bullAlert = bullFire and passRisk and alertModelOK and inSess
bearAlert = bearFire and passRisk and alertModelOK and inSess
cisdBull = bullAlert and not pxyFire
cisdBear = bearAlert and not pxyFire
pxyBull = bullAlert and pxyFire
pxyBear = bearAlert and pxyFire
alertcondition(cisdBull, "LH CISD - bullish",
"Bullish LH CISD on {{ticker}} {{interval}} at {{close}}")
alertcondition(cisdBear, "LH CISD - bearish",
"Bearish LH CISD on {{ticker}} {{interval}} at {{close}}")
alertcondition(cisdBull or cisdBear, "LH CISD - any",
"LH CISD on {{ticker}} {{interval}} at {{close}}")
alertcondition(pxyBull, "LH Proxy CISD - bullish",
"Bullish LH PROXY on {{ticker}} {{interval}} at {{close}}")
alertcondition(pxyBear, "LH Proxy CISD - bearish",
"Bearish LH PROXY on {{ticker}} {{interval}} at {{close}}")
alertcondition(pxyBull or pxyBear, "LH Proxy CISD - any",
"LH PROXY on {{ticker}} {{interval}} at {{close}}")
if bullAlert or bearAlert
alert((bullAlert ? "Bullish" : "Bearish") + (pxyFire ? " LH PROXY " : " LH CISD ") + syminfo.ticker + " " +
timeframe.period + " line " + str.tostring(alLine, format.mintick) +
" stop " + str.tostring(alStop, format.mintick) +
" risk " + str.tostring(riskPts, "#.##") + " pts",
alert.freq_once_per_bar_close)
isNQsym = str.contains(symRoot, "NQ")
is1min = timeframe.isminutes and timeframe.multiplier == 1
badChart = not (isNQsym or isESsym) or not is1min
var label guardLbl = na
if showGuard and badChart and barstate.islast
label.delete(guardLbl)
guardLbl := label.new(bar_index, high,
"This indicator is built for NQ / ES 1-minute (extended session on).\n" +
"This chart is " + syminfo.ticker + " " + timeframe.period +
" - the draws and the detection are NOT validated here.",
style = label.style_label_down, color = color.new(color.red, 15),
textcolor = color.white, size = size.normal)