Code 2231
Code 2231
Code 2231
get_line_style(style) =>
switch style
'⎯⎯⎯' => line.style_solid
'----' => line.style_dashed
'····' => line.style_dotted
float ob = na
if condition
avg = math.avg(top, btm)
array.unshift(ob_top, top)
array.unshift(ob_btm, btm)
array.unshift(ob_avg, avg)
array.unshift(ob_left, time[length])
ob := ob_val
mitigated
if barstate.isfirst
for i = 0 to ext_last-1
array.unshift(ob_box, box.new(na,na,na,na, xloc = xloc.bar_time, extend
= extend.right, bgcolor = bg_css, border_color = color.new(border_css, 70)))
array.unshift(ob_lvl, line.new(na,na,na,na, xloc = xloc.bar_time,
extend = extend.right, color = lvl_css, style = get_line_style(line_style), width =
line_width))
if barstate.islast
if array.size(ob_top) > 0
for i = 0 to math.min(ext_last-1, array.size(ob_top)-1)
get_box = array.get(ob_box, i)
get_lvl = array.get(ob_lvl, i)
box.set_lefttop(get_box, array.get(ob_left, i), array.get(ob_top,
i))
box.set_rightbottom(get_box, array.get(ob_left, i),
array.get(ob_btm, i))
line.set_xy1(get_lvl, array.get(ob_left, i), array.get(ob_avg, i))
line.set_xy2(get_lvl, array.get(ob_left, i)+1, array.get(ob_avg,
i))
n = bar_index
upper = ta.highest(length)
lower = ta.lowest(length)
if mitigation == 'Close'
target_bull := ta.lowest(close, length)
target_bear := ta.highest(close, length)
else
target_bull := lower
target_bear := upper
// UNTESTED
// Fractals
isRegularFractal(mode) =>
ret = mode == 'Buy' ? high[0] < high[1] and (high[2] < high[1] or high[2] ==
high[1] and high[3] < high[2]) : mode == 'Sell' ? low[0] > low[1] and (low[2] >
low[1] or low[2] == low[1] and low[3] > low[2]) : false
ret
isBWFractal(mode) =>
ret = mode == 'Buy' ? high[0] < high[2] and high[1] < high[2] and high[3] <
high[2] and high[4] < high[2] : mode == 'Sell' ? low[0] > low[2] and low[1] >
low[2] and low[3] > low[2] and low[4] > low[2] : false
ret
isFractalHigh() =>
filterFractal == '3' ? isRegularFractal('Buy') : isBWFractal('Buy')
isFractalLow() =>
filterFractal == '3' ? isRegularFractal('Sell') : isBWFractal('Sell')
resolutionInMinutes() =>
resInMinutes = timeframe.multiplier * (timeframe.isseconds ? 1. / 60 :
timeframe.isminutes ? 1. : timeframe.isdaily ? 60. * 24 : timeframe.isweekly ? 60.
* 24 * 7 : timeframe.ismonthly ? 60. * 24 * 30.4375 : na)
resInMinutes
if isFractalLow()
if filterFractal == '3'
array.push(fractal_lows, low[1])
array.push(fractal_low_times, time[1])
fractal_low_val := low[1]
else
array.push(fractal_lows, low[2])
array.push(fractal_low_times, time[2])
fractal_low_val := low[2]
// -------------------- Fractals --------------------
// Bearish loop
if array.size(fractal_lows) > 0
for i = array.size(fractal_lows) - 1 to 0
if (findObType == 'Close' ? close : low) < array.get(fractal_lows, i)
idx = 0
max = low //current low
gapIndex = 0
for k = 0 to bars_back
bearishGap = (close[k+1] < low[k+2]) and (high[k] < low[k+2])
_filterFvg = filterFvgs ? gapIndex > 0 and idx - gapIndex >= 0 and idx
- gapIndex <= fvgDistance : true
// Line on OB
if idx != 0 and _filterFvg
// label.new(bar_index, high, str.tostring(idx) + "\n" +
str.tostring(gapIndex))
TimeTo = f_timeFrom('bar', line_length, 'chart', idx)
loc = lineHeight == 'Body' ? open[idx] : low[idx]
array.remove(fractal_lows, i)
array.remove(fractal_low_times, i)
// Bullish loop
if array.size(fractal_highs) > 0
for i = array.size(fractal_highs) - 1 to 0
if (findObType == 'Close' ? close : high) > array.get(fractal_highs, i)
idx = 0
min = low
gapIndex = 0
for k = 0 to bars_back
bullishGap = (close[k+1] > high[k+2]) and (low[k] > high[k+2])
// if bearish candle
if close[k] < open[k] and low[k] < min
idx := k
min := low[k]
if bullishGap
gapIndex := k+2
_filterFvg = filterFvgs ? gapIndex > 0 and idx - gapIndex >= 0 and idx
- gapIndex <= fvgDistance : true
// Line on OB
if idx != 0 and _filterFvg
// label.new(bar_index, high, str.tostring(idx) + "\n" +
str.tostring(gapIndex))
TimeTo = f_timeFrom('bar', line_length, 'chart', idx)
loc = lineHeight == 'Body' ? open[idx] : high[idx]
array.remove(fractal_highs, i)
array.remove(fractal_high_times, i)
// Delete Lines/Labels
if array.size(line1) > 0
var int i = array.size(line1) - 1
while i >= 0
if high >= line.get_y1(array.get(line1, i)) and high >=
line.get_y1(array.get(line2, i))
if delLines
line.delete(array.get(line1, i))
line.delete(array.get(line2, i))
//label.delete(array.get(label1, i))
array.remove(line1, i)
array.remove(line2, i)
//array.remove(label1,i)
i -= 1
if array.size(line3) > 0
var int j = array.size(line3) - 1
while j >= 0
if low <= line.get_y1(array.get(line3, j)) and low <=
line.get_y1(array.get(line4, j))
if delLines
line.delete(array.get(line3, j))
line.delete(array.get(line4, j))
//label.delete(array.get(label2, j))
array.remove(line3, j)
array.remove(line4, j)
//array.remove(label2,j)
j -= 1