本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © julzALGO
//@version=6
indicator("Institutional OB | julzALGO", shorttitle="julzALGO IOB", overlay=true, max_lines_count=500, max_labels_count=500, max_boxes_count=500, max_bars_back=5000)
//------------------------------------------------------------------------------
// Structure flags
//------------------------------------------------------------------------------
s_BOS = 0
s_CHoCH = 1
i_BOS = 2
i_CHoCH = 3
i_pp_CHoCH = 4
green_candle = 5
red_candle = 6
s_CHoCHP = 7
i_CHoCHP = 8
var bool[] boolean = array.from(false, false, false, false, false, false, false, false, false)
//------------------------------------------------------------------------------
// Inputs
//------------------------------------------------------------------------------
groupMS = "SWING STRUCTURE ENGINE"
groupVOB = "SWING ORDER BLOCKS"
groupRR = "RETEST RR SYSTEM"
swing_r_lookback = input.int(50, "Swing Lookback", group=groupMS, minval=2)
ms_mode = "Manual"
ob_num = input.int(5, "Show Last", group=groupVOB, minval=1, maxval=10)
ob_metrics_show = false
css_metric_up = color.new(color.white, 100)
css_metric_dn = color.new(color.white, 100)
ob_swings = true
css_swing_up = color.new(color.gray, 90)
css_swing_dn = color.new(color.silver, 90)
ob_filter = "None"
ob_mitigation = "Absolute"
ob_pos = "Full"
use_grayscale = false
use_middle_line = false
use_overlap = true
use_overlap_method = "Previous"
showRRSystem = input.bool(true, "Show RR On OB Retest", group=groupRR)
rrSideInput = input.string("Both", "RR Side", options=["Both", "Bull", "Bear"], group=groupRR)
rrEntryLevel = input.string("Near Edge", "RR Entry Level", options=["Near Edge", "Midline", "Far Edge"], group=groupRR, tooltip="Bull OB: Near Edge = top of OB, Far Edge = bottom of OB. Bear OB: Near Edge = bottom of OB, Far Edge = top of OB.")
rrTargetInput = input.string("3R", "Take Profit", options=["1R", "2R", "3R", "4R", "5R"], group=groupRR)
rrLineLength = input.int(25, "RR Line Length", minval=5, maxval=200, group=groupRR)
rrAtrLen = input.int(14, "SL ATR Length", minval=1, group=groupRR)
rrAtrBuffer = input.float(0.50, "SL ATR Clearance", minval=0.0, step=0.05, group=groupRR, tooltip="Adds ATR clearance beyond the OB box. Bull SL goes below the OB bottom; bear SL goes above the OB top.")
showRRZones = input.bool(true, "Show RR Zones", group=groupRR)
showRRLabels = input.bool(true, "Show RR Labels", group=groupRR)
rrLongColor = input.color(color.rgb(0, 150, 40), "Long RR Color", group=groupRR)
rrShortColor = input.color(color.rgb(220, 0, 0), "Short RR Color", group=groupRR)
color invcol = color.new(color.white, 100)
//------------------------------------------------------------------------------
// Types
//------------------------------------------------------------------------------
type bar_t
float o = open
float c = close
float h = high
float l = low
float v = volume
int n = bar_index
int t = time
type ms_t
float[] p
int[] n
float[] l
type msDraw
int n
float p
color css
string txt
bool bull
type obC
float[] top
float[] btm
int[] left
float[] avg
int[] wM
int[] blVP
int[] brVP
int[] dir
float[] h
float[] l
int[] n
type obD
box[] ob
box[] blB
box[] brB
line[] mL
type pattern
string found = "None"
bool isfound = false
int period = 0
bool bull = false
type alerts
bool chochswing = false
bool chochplusswing = false
bool swingbos = false
bool chochplus = false
bool choch = false
bool bos = false
bool swingob = false
bool obtouch = false
//------------------------------------------------------------------------------
// General setup
//------------------------------------------------------------------------------
bar_t b = bar_t.new()
var pattern p = pattern.new()
alerts blalert = alerts.new()
alerts bralert = alerts.new()
if p.isfound
p.period += 1
if p.period >= 50
p.period := 0
p.found := "None"
p.isfound := false
p.bull := false
switch
b.c > b.o => array.set(boolean, green_candle, true)
b.c < b.o => array.set(boolean, red_candle, true)
f_zscore(src, lookback) =>
st = ta.stdev(src, lookback)
st == 0.0 ? 0.0 : (src - ta.sma(src, lookback)) / st
var int iLen = 5
var int sLen = swing_r_lookback
vv = f_zscore(((close - nz(close[iLen], close)) / nz(close[iLen], close)) * 100, iLen)
iLen := ms_mode == "Dynamic" ? (math.abs(vv) >= 2.0 ? 5 : math.abs(vv) >= 1.9 ? 6 : math.abs(vv) >= 1.8 ? 7 : math.abs(vv) >= 1.7 ? 8 : math.abs(vv) >= 1.6 ? 9 : math.abs(vv) >= 1.5 ? 10 : iLen) : iLen
iH = ta.pivothigh(high, iLen, iLen)
sH = ta.pivothigh(high, sLen, sLen)
iL = ta.pivotlow(low, iLen, iLen)
sL = ta.pivotlow(low, sLen, sLen)
//------------------------------------------------------------------------------
// Market structure helpers
//------------------------------------------------------------------------------
var bool gObCrossLowBelowTop = false
var bool gObCrossHighAboveBtm = false
rrMultiple =
rrTargetInput == "1R" ? 1.0 :
rrTargetInput == "2R" ? 2.0 :
rrTargetInput == "3R" ? 3.0 :
rrTargetInput == "4R" ? 4.0 :
5.0
rrAtrValue = ta.atr(rrAtrLen)
var line[] rrLines = array.new<line>()
var box[] rrBoxes = array.new<box>()
var label[] rrLabels = array.new<label>()
var bool[] activeRRLive = array.new<bool>(2, false)
var bool[] activeRRBull = array.new<bool>(2, false)
var int[] activeRRStart = array.new<int>(2, na)
var int[] activeRRSource = array.new<int>(2, na)
var float[] activeRREntry = array.new<float>(2, na)
var float[] activeRRStop = array.new<float>(2, na)
var float[] activeRRTarget = array.new<float>(2, na)
clearRRObjects() =>
while array.size(rrLines) > 0
line.delete(array.pop(rrLines))
while array.size(rrBoxes) > 0
box.delete(array.pop(rrBoxes))
while array.size(rrLabels) > 0
label.delete(array.pop(rrLabels))
0
setActiveRR(bool bull, int source, float entry, float stopLoss, float takeProfit) =>
array.set(activeRRLive, 1, array.get(activeRRLive, 0))
array.set(activeRRBull, 1, array.get(activeRRBull, 0))
array.set(activeRRStart, 1, array.get(activeRRStart, 0))
array.set(activeRRSource, 1, array.get(activeRRSource, 0))
array.set(activeRREntry, 1, array.get(activeRREntry, 0))
array.set(activeRRStop, 1, array.get(activeRRStop, 0))
array.set(activeRRTarget, 1, array.get(activeRRTarget, 0))
array.set(activeRRLive, 0, true)
array.set(activeRRBull, 0, bull)
array.set(activeRRStart, 0, bar_index)
array.set(activeRRSource, 0, source)
array.set(activeRREntry, 0, entry)
array.set(activeRRStop, 0, stopLoss)
array.set(activeRRTarget, 0, takeProfit)
0
drawRetestRR(bool bull, float entry, float stopLoss, float takeProfit, int x1, int x2, color rrColor) =>
color riskCol = color.new(rrShortColor, 84)
color rewardCol = color.new(rrLongColor, 84)
color activeCol = color.new(rrColor, 0)
color softCol = color.new(rrColor, 55)
if showRRZones
box rewardBox = box.new(
left=x1,
top=math.max(entry, takeProfit),
right=x2,
bottom=math.min(entry, takeProfit),
xloc=xloc.bar_index,
bgcolor=rewardCol,
border_color=color.new(rrLongColor, 76),
border_width=1)
array.push(rrBoxes, rewardBox)
box riskBox = box.new(
left=x1,
top=math.max(entry, stopLoss),
right=x2,
bottom=math.min(entry, stopLoss),
xloc=xloc.bar_index,
bgcolor=riskCol,
border_color=color.new(rrShortColor, 76),
border_width=1)
array.push(rrBoxes, riskBox)
line entryLine = line.new(x1, entry, x2, entry, xloc=xloc.bar_index, color=activeCol, width=2, style=line.style_dashed)
line slLine = line.new(x1, stopLoss, x2, stopLoss, xloc=xloc.bar_index, color=color.new(rrShortColor, 0), width=1, style=line.style_solid)
line tpLine = line.new(x1, takeProfit, x2, takeProfit, xloc=xloc.bar_index, color=color.new(rrLongColor, 0), width=1, style=line.style_solid)
array.push(rrLines, entryLine)
array.push(rrLines, slLine)
array.push(rrLines, tpLine)
if showRRLabels
string sideText = bull ? "BUY RETEST" : "SELL RETEST"
label sideLabel = label.new(x1, entry, bull ? "B" : "S", xloc=xloc.bar_index, style=bull ? label.style_label_up : label.style_label_down, textcolor=color.white, color=activeCol, size=size.tiny)
label entryLabel = label.new(x2, entry, sideText, xloc=xloc.bar_index, style=label.style_label_left, textcolor=color.white, color=softCol, size=size.tiny)
label slLabel = label.new(x2, stopLoss, "SL", xloc=xloc.bar_index, style=label.style_label_left, textcolor=color.white, color=color.new(rrShortColor, 15), size=size.tiny)
label tpLabel = label.new(x2, takeProfit, rrTargetInput, xloc=xloc.bar_index, style=label.style_label_left, textcolor=color.white, color=color.new(rrLongColor, 15), size=size.tiny)
array.push(rrLabels, sideLabel)
array.push(rrLabels, entryLabel)
array.push(rrLabels, slLabel)
array.push(rrLabels, tpLabel)
0
//------------------------------------------------------------------------------
// Market structure core
//------------------------------------------------------------------------------
structure(bool mtf) =>
msDraw drw = na
bool isdrw = false
bool isdrwS = false
var color css = na
var color icss = na
var int itrend = 0
var int trend = 0
bool bull_ob = false
bool bear_ob = false
bool s_bull_ob = false
bool s_bear_ob = false
var ms_t up = ms_t.new(array.new<float>(), array.new<int>(), array.new<float>())
var ms_t dn = ms_t.new(array.new<float>(), array.new<int>(), array.new<float>())
var ms_t sup = ms_t.new(array.new<float>(), array.new<int>(), array.new<float>())
var ms_t sdn = ms_t.new(array.new<float>(), array.new<int>(), array.new<float>())
switch
not na(iH) =>
array.unshift(up.p, high[iLen])
array.unshift(up.l, high[iLen])
array.unshift(up.n, bar_index[iLen])
not na(iL) =>
array.unshift(dn.p, low[iLen])
array.unshift(dn.l, low[iLen])
array.unshift(dn.n, bar_index[iLen])
not na(sL) =>
array.unshift(sdn.p, low[sLen])
array.unshift(sdn.l, low[sLen])
array.unshift(sdn.n, bar_index[sLen])
not na(sH) =>
array.unshift(sup.p, high[sLen])
array.unshift(sup.l, high[sLen])
array.unshift(sup.n, bar_index[sLen])
upFirst = array.size(up.p) > 0 ? array.first(up.p) : na
dnFirst = array.size(dn.p) > 0 ? array.first(dn.p) : na
supFirst = array.size(sup.p) > 0 ? array.first(sup.p) : na
sdnFirst = array.size(sdn.p) > 0 ? array.first(sdn.p) : na
crossIntBull = ta.crossover(close, nz(upFirst, close + 1e10))
crossIntBear = ta.crossunder(close, nz(dnFirst, close - 1e10))
crossSwgBull = ta.crossover(close, nz(supFirst, close + 1e10))
crossSwgBear = ta.crossunder(close, nz(sdnFirst, close - 1e10))
if array.size(up.p) > 0 and array.size(dn.l) > 1 and crossIntBull
bool CHoCH = itrend < 0
string txt = CHoCH ? (array.first(dn.l) > array.get(dn.l, 1) ? "CHoCH+" : "CHoCH") : "BOS"
if not CHoCH
blalert.bos := true
else
condPlus = array.first(dn.l) > array.get(dn.l, 1)
blalert.chochplus := condPlus
blalert.choch := not condPlus
if not mtf
bull_ob := (ob_filter == "None") or (ob_filter == txt)
itrend := 1
array.clear(up.n), array.clear(up.p)
if array.size(dn.p) > 0 and array.size(up.l) > 1 and crossIntBear
bool CHoCH = itrend > 0
string txt = CHoCH ? (array.first(up.l) < array.get(up.l, 1) ? "CHoCH+" : "CHoCH") : "BOS"
if not CHoCH
bralert.bos := true
else
condPlus = array.first(up.l) < array.get(up.l, 1)
bralert.chochplus := condPlus
bralert.choch := not condPlus
if not mtf
bear_ob := (ob_filter == "None") or (ob_filter == txt)
itrend := -1
array.clear(dn.n), array.clear(dn.p)
if array.size(sup.p) > 0 and array.size(sdn.l) > 1 and crossSwgBull
bool CHoCH = trend < 0
string txt = CHoCH ? (array.first(sdn.l) > array.get(sdn.l, 1) ? "CHoCH+" : "CHoCH") : "BOS"
if not CHoCH
blalert.swingbos := true
else
condPlus = array.first(sdn.l) > array.get(sdn.l, 1)
blalert.chochplusswing := condPlus
blalert.chochswing := not condPlus
if not mtf
s_bull_ob := (ob_filter == "None") or (ob_filter == txt)
trend := 1
array.clear(sup.n), array.clear(sup.p)
if array.size(sdn.p) > 0 and array.size(sup.l) > 1 and crossSwgBear
bool CHoCH = trend > 0
string txt = CHoCH ? (array.first(sup.l) < array.get(sup.l, 1) ? "CHoCH+" : "CHoCH") : "BOS"
if not CHoCH
bralert.swingbos := true
else
condPlus = array.first(sup.l) < array.get(sup.l, 1)
bralert.chochplusswing := condPlus
bralert.chochswing := not condPlus
if not mtf
s_bear_ob := (ob_filter == "None") or (ob_filter == txt)
trend := -1
array.clear(sdn.n), array.clear(sdn.p)
[css, bear_ob, bull_ob, itrend, drw, isdrw, s_bear_ob, s_bull_ob, trend, icss, isdrwS]
[css, bear_ob, bull_ob, itrend, drw, isdrw, s_bear_ob, s_bull_ob, trend, icss, isdrwS] = structure(false)
method eB(box[] b, bool ext, color css, bool swing) =>
array.unshift(b, box.new(na, na, na, na, xloc=xloc.bar_time, text_font_family=font.family_monospace, extend=ext ? extend.right : extend.none, border_color=swing ? color.new(css, 0) : color.new(color.white, 100), bgcolor=css, border_width=1))
method eL(line[] l, bool ext, bool solid, color css) =>
array.unshift(l, line.new(na, na, na, na, width=1, color=css, xloc=xloc.bar_time, extend=ext ? extend.right : extend.none, style=line.style_solid))
//------------------------------------------------------------------------------
// Swing OB core, kept from the source script
//------------------------------------------------------------------------------
method drawVOB(bool cdn, bool bull, color css, int loc, bool swing) =>
[cC, oO, hH, lL] = request.security(syminfo.tickerid, "", [close, open, high, low], lookahead=barmerge.lookahead_off)
var obC obj = obC.new(array.new<float>(), array.new<float>(), array.new<int>(), array.new<float>(), array.new<int>(), array.new<int>(), array.new<int>(), array.new<int>(), array.new<float>(), array.new<float>(), array.new<int>())
var obD draw = obD.new(array.new<box>(), array.new<box>(), array.new<box>(), array.new<line>())
if barstate.isfirst
for i = 0 to ob_num - 1
draw.mL.eL(false, true, color.new(css, 100))
draw.ob.eB(false, use_grayscale ? color.new(color.gray, 90) : css, swing)
draw.blB.eB(false, css_metric_up, swing)
draw.brB.eB(false, css_metric_dn, swing)
float pos = ob_pos == "Full" ? (bull ? high : low) : ob_pos == "Middle" ? ohlc4 : hl2
if cdn and not na(loc)
array.clear(obj.h), array.clear(obj.l), array.clear(obj.n)
span = math.abs(loc - b.n)
spanBars = math.max(0, span - 1)
for i = 1 to spanBars
array.push(obj.h, hH[i])
array.push(obj.l, lL[i])
array.push(obj.n, (b[i]).t)
if array.size(obj.l) > 0
iU = array.indexof(obj.l, array.min(obj.l)) + 1
iD = array.indexof(obj.h, array.max(obj.h)) + 1
array.unshift(obj.dir, bull ? (cC[iU] > oO[iU] ? 1 : -1) : (cC[iD] > oO[iD] ? 1 : -1))
array.unshift(obj.top, bull ? pos[iU] : array.max(obj.h))
array.unshift(obj.btm, bull ? array.min(obj.l) : pos[iD])
leftIdx = bull ? array.get(obj.n, array.indexof(obj.l, array.min(obj.l))) : array.get(obj.n, array.indexof(obj.h, array.max(obj.h)))
array.unshift(obj.left, leftIdx)
array.unshift(obj.avg, math.avg(array.first(obj.top), array.first(obj.btm)))
if ob_pos == "Precise"
if bull
top0 = array.first(obj.top)
avg0 = array.first(obj.avg)
candleTop = hlcc4[iU]
edgeRef = (b[iU]).c < (b[iU]).o ? (b[iU]).c : (b[iU]).o
if avg0 < edgeRef and top0 > candleTop
array.set(obj.top, 0, avg0)
array.set(obj.avg, 0, math.avg(array.first(obj.top), array.first(obj.btm)))
else
btm0 = array.first(obj.btm)
avg0 = array.first(obj.avg)
candleBtm = hlcc4[iD]
edgeRef = (b[iD]).c < (b[iD]).o ? (b[iD]).o : (b[iD]).c
if avg0 > edgeRef and btm0 < candleBtm
array.set(obj.btm, 0, avg0)
array.set(obj.avg, 0, math.avg(array.first(obj.top), array.first(obj.btm)))
array.unshift(obj.blVP, 0)
array.unshift(obj.brVP, 0)
array.unshift(obj.wM, 1)
if use_overlap and array.size(obj.avg) > 1
int rmP = use_overlap_method == "Recent" ? 1 : 0
condOverlap = bull ? array.first(obj.btm) < array.get(obj.top, 1) : array.first(obj.top) > array.get(obj.btm, 1)
if condOverlap
array.remove(obj.wM, rmP)
array.remove(obj.dir, rmP)
array.remove(obj.top, rmP)
array.remove(obj.avg, rmP)
array.remove(obj.btm, rmP)
array.remove(obj.left, rmP)
array.remove(obj.blVP, rmP)
array.remove(obj.brVP, rmP)
if barstate.isconfirmed and array.size(obj.avg) > 0
isMiddle = ob_mitigation == "Middle"
for i = array.size(obj.avg) - 1 to 0
tgTop = isMiddle ? array.get(obj.avg, i) : (bull ? array.get(obj.btm, i) : array.get(obj.top, i))
broke = bull ? cC < tgTop : cC > tgTop
if broke
array.remove(obj.wM, i)
array.remove(obj.dir, i)
array.remove(obj.top, i)
array.remove(obj.avg, i)
array.remove(obj.btm, i)
array.remove(obj.left, i)
array.remove(obj.blVP, i)
array.remove(obj.brVP, i)
topS = array.size(obj.top) > 0 ? array.get(obj.top, 0) : na
btmS = array.size(obj.btm) > 0 ? array.get(obj.btm, 0) : na
bool crossLowBelowTop = ta.crossunder(low, nz(topS, low + 1e10))
bool crossHighAboveBtm = ta.crossover(high, nz(btmS, high - 1e10))
if showRRSystem and swing and barstate.isconfirmed and array.size(obj.avg) > 0
rrSeq = math.min(ob_num - 1, array.size(obj.avg) - 1)
if rrSeq >= 0
for ri = 0 to rrSeq
rrTop = array.get(obj.top, ri)
rrBtm = array.get(obj.btm, ri)
rrAvg = array.get(obj.avg, ri)
rrLeft = array.get(obj.left, ri)
rrSideAllowed = rrSideInput == "Both" or (rrSideInput == "Bull" and bull) or (rrSideInput == "Bear" and not bull)
touchUpperEdge = high >= rrTop and low <= rrTop
touchLowerEdge = high >= rrBtm and low <= rrBtm
validRetest = bull ? touchUpperEdge : touchLowerEdge
isSameSetup = array.get(activeRRLive, 0) and array.get(activeRRBull, 0) == bull and array.get(activeRRSource, 0) == rrLeft
if rrSideAllowed and validRetest and time > rrLeft and not isSameSetup and bar_index > nz(array.get(activeRRStart, 0), -1)
rrEntry = rrEntryLevel == "Midline" ? rrAvg : rrEntryLevel == "Far Edge" ? (bull ? rrBtm : rrTop) : (bull ? rrTop : rrBtm)
rrBuffer = nz(rrAtrValue, 0.0) * rrAtrBuffer
rrStop = bull ? rrBtm - rrBuffer : rrTop + rrBuffer
rrRisk = math.abs(rrEntry - rrStop)
if rrRisk > syminfo.mintick
rrTp = bull ? rrEntry + rrRisk * rrMultiple : rrEntry - rrRisk * rrMultiple
setActiveRR(bull, rrLeft, rrEntry, rrStop, rrTp)
break
if barstate.islast and array.size(obj.avg) > 0
touch = bull ? (not na(topS) and crossLowBelowTop) : (not na(btmS) and crossHighAboveBtm)
if touch
if bull
blalert.obtouch := true
else
bralert.obtouch := true
seq = math.min(ob_num - 1, array.size(obj.avg) - 1)
if seq >= 0
for i = 0 to seq
dmL = array.get(draw.mL, i)
dOB = array.get(draw.ob, i)
dblB = array.get(draw.blB, i)
dbrB = array.get(draw.brB, i)
topi = array.get(obj.top, i)
btmi = array.get(obj.btm, i)
avgi = array.get(obj.avg, i)
left = array.get(obj.left, i)
int barMs = math.max(1, b.t - (b[1]).t)
box.set_lefttop(dOB, left, topi)
box.set_rightbottom(dOB, b.t, btmi)
if use_middle_line
line.set_xy1(dmL, left, avgi)
line.set_xy2(dmL, b.t, avgi)
if ob_metrics_show
box.set_lefttop(dblB, left, topi)
box.set_lefttop(dbrB, left, avgi)
box.set_rightbottom(dblB, left, avgi)
box.set_rightbottom(dbrB, left, btmi)
rpBL = box.get_right(dblB)
rpBR = box.get_right(dbrB)
blvp = array.size(obj.blVP) > i ? array.get(obj.blVP, i) : 0
brvp = array.size(obj.brVP) > i ? array.get(obj.brVP, i) : 0
box.set_right(dbrB, math.min(b.t, rpBR + barMs * brvp))
box.set_right(dblB, math.min(b.t, rpBL + barMs * blvp))
if ob_metrics_show and barstate.isconfirmed and array.size(obj.wM) > 0
for i = 0 to array.size(obj.avg) - 1
dir = array.get(obj.dir, i)
wm = array.get(obj.wM, i)
if dir == 1
switch wm
1 => array.set(obj.blVP, i, array.get(obj.blVP, i) + 1), array.set(obj.wM, i, 2)
2 => array.set(obj.blVP, i, array.get(obj.blVP, i) + 1), array.set(obj.wM, i, 3)
3 => array.set(obj.brVP, i, array.get(obj.brVP, i) + 1), array.set(obj.wM, i, 1)
else if dir == -1
switch wm
1 => array.set(obj.brVP, i, array.get(obj.brVP, i) + 1), array.set(obj.wM, i, 2)
2 => array.set(obj.brVP, i, array.get(obj.brVP, i) + 1), array.set(obj.wM, i, 3)
3 => array.set(obj.blVP, i, array.get(obj.blVP, i) + 1), array.set(obj.wM, i, 1)
//------------------------------------------------------------------------------
// Swing OB trigger bars
//------------------------------------------------------------------------------
var int[] hS = array.new<int>(1, b.n)
var int[] lS = array.new<int>(1, b.n)
if not na(sH)
array.pop(hS), array.unshift(hS, int((b[sLen]).n))
if not na(sL)
array.pop(lS), array.unshift(lS, int((b[sLen]).n))
if barstate.islast
clearRRObjects()
if ob_swings
s_bull_ob.drawVOB(true, css_swing_up, array.first(hS), true)
s_bear_ob.drawVOB(false, css_swing_dn, array.first(lS), true)
if barstate.islast and showRRSystem
for rrIndex = 0 to 1
if array.get(activeRRLive, rrIndex)
rrBullActive = array.get(activeRRBull, rrIndex)
rrStartBar = nz(array.get(activeRRStart, rrIndex), bar_index)
rrSafeStart = math.max(rrStartBar, bar_index - 9990)
rrEndBar = rrIndex == 0 ? bar_index + rrLineLength : math.min(bar_index, nz(array.get(activeRRStart, 0), bar_index))
drawRetestRR(
rrBullActive,
array.get(activeRREntry, rrIndex),
array.get(activeRRStop, rrIndex),
array.get(activeRRTarget, rrIndex),
rrSafeStart,
math.max(rrSafeStart + 1, rrEndBar),
rrBullActive ? rrLongColor : rrShortColor)
if s_bull_ob or s_bear_ob
blalert.swingob := true
alertcondition(s_bull_ob, "Bull Swing OB", "Bull swing order block detected on {{ticker}}")
alertcondition(s_bear_ob, "Bear Swing OB", "Bear swing order block detected on {{ticker}}")
alertcondition(blalert.swingob, "Swing OB", "Swing order block detected on {{ticker}}")