//@version=5
indicator("DuxAlgo", overlay = true
, max_lines_count = 500
, max_labels_count = 500
, max_boxes_count = 500)
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
length = input.int(10, 'Swing Lookback' , minval = 3)
showBull = input.int(3, 'Show Last Bullish OB', minval = 0)
showBear = input.int(3, 'Show Last Bearish OB', minval = 0)
useBody = input(false, 'Use Candle Body')
//Style
bullCss = input(color.rgb(33, 243, 47, 80), 'Bullish OB' , inline =
'bullcss', group = 'Style')
bullBreakCss = input(color.rgb(255, 0, 0, 80), 'Bullish Break', inline = 'bullcss',
group = 'Style')
bearCss = input(color.rgb(255, 0, 0, 80), 'Bearish OB' , inline = 'bearcss',
group = 'Style')
bearBreakCss = input(color.rgb(0, 255, 21, 80), 'Bearish Break', inline =
'bearcss', group = 'Style')
showLabels = input(false, 'Show Historical Polarity Changes')
//-----------------------------------------------------------------------------}
//UDT's
//-----------------------------------------------------------------------------{
type ob
float top = na
float btm = na
int loc = bar_index
bool breaker = false
int break_loc = na
type swing
float y = na
int x = na
bool crossed = false
//-----------------------------------------------------------------------------}
//Functions
//-----------------------------------------------------------------------------{
swings(len)=>
var os = 0
var swing top = swing.new(na, na)
var swing btm = swing.new(na, na)
upper = ta.highest(len)
lower = ta.lowest(len)
os := high[len] > upper ? 0
: low[len] < lower ? 1 : os
if os == 0 and os[1] != 0
top := swing.new(high[length], bar_index[length])
if os == 1 and os[1] != 1
btm := swing.new(low[length], bar_index[length])
[top, btm]
method notransp(color css) => color.rgb(color.r(css), color.g(css), color.b(css))
method display(ob id, css, break_css)=>
if id.breaker
box.new(id.loc, id.top, id.break_loc, id.btm, css.notransp()
, bgcolor = css
, xloc = xloc.bar_time)
box.new(id.break_loc, id.top, time+1, id.btm, na
, bgcolor = break_css
, extend = extend.right
, xloc = xloc.bar_time)
line.new(id.loc, id.top, id.break_loc, id.top, xloc.bar_time, color =
css.notransp())
line.new(id.loc, id.btm, id.break_loc, id.btm, xloc.bar_time, color =
css.notransp())
line.new(id.break_loc, id.top, time+1, id.top, xloc.bar_time, extend.right,
break_css.notransp(), line.style_dashed)
line.new(id.break_loc, id.btm, time+1, id.btm, xloc.bar_time, extend.right,
break_css.notransp(), line.style_dashed)
else
box.new(id.loc, id.top, time, id.btm, na
, bgcolor = css
, extend = extend.right
, xloc = xloc.bar_time)
line.new(id.loc, id.top, time, id.top, xloc.bar_time, extend.right,
css.notransp())
line.new(id.loc, id.btm, time, id.btm, xloc.bar_time, extend.right,
css.notransp())
//-----------------------------------------------------------------------------}
//Detect Swings
//-----------------------------------------------------------------------------{
n = bar_index
[top, btm] = swings(length)
max = useBody ? math.max(close, open) : high
min = useBody ? math.min(close, open) : low
//-----------------------------------------------------------------------------}
//Bullish OB
//-----------------------------------------------------------------------------{
var bullish_ob = array.new<ob>(0)
bull_break_conf = 0
if close > top.y and not top.crossed
top.crossed := true
minima = max[1]
maxima = min[1]
loc = time[1]
for i = 1 to (n - top.x)-1
minima := math.min(min[i], minima)
maxima := minima == min[i] ? max[i] : maxima
loc := minima == min[i] ? time[i] : loc
bullish_ob.unshift(ob.new(maxima, minima, loc))
if bullish_ob.size() > 0
for i = bullish_ob.size()-1 to 0
element = bullish_ob.get(i)
if not element.breaker
if math.min(close, open) < element.btm
element.breaker := true
element.break_loc := time
else
if close > element.top
bullish_ob.remove(i)
else if i < showBull and top.y < element.top and top.y > element.btm
bull_break_conf := 1
//Set label
if bull_break_conf > bull_break_conf[1] and showLabels
label.new(top.x, top.y, '▼', color = na
, textcolor = bearCss.notransp()
, style = label.style_label_down
, size = size.tiny)
//-----------------------------------------------------------------------------}
//Bearish OB
//-----------------------------------------------------------------------------{
var bearish_ob = array.new<ob>(0)
bear_break_conf = 0
if close < btm.y and not btm.crossed
btm.crossed := true
minima = min[1]
maxima = max[1]
loc = time[1]
for i = 1 to (n - btm.x)-1
maxima := math.max(max[i], maxima)
minima := maxima == max[i] ? min[i] : minima
loc := maxima == max[i] ? time[i] : loc
bearish_ob.unshift(ob.new(maxima, minima, loc))
if bearish_ob.size() > 0
for i = bearish_ob.size()-1 to 0
element = bearish_ob.get(i)
if not element.breaker
if math.max(close, open) > element.top
element.breaker := true
element.break_loc := time
else
if close < element.btm
bearish_ob.remove(i)
else if i < showBear and btm.y > element.btm and btm.y < element.top
bear_break_conf := 1
//Set label
if bear_break_conf > bear_break_conf[1] and showLabels
label.new(btm.x, btm.y, '▲', color = na
, textcolor = bullCss.notransp()
, style = label.style_label_up
, size = size.tiny)
//-----------------------------------------------------------------------------}
//Set Order Blocks
//-----------------------------------------------------------------------------{
for bx in box.all
bx.delete()
for l in line.all
l.delete()
if barstate.islast
//Bullish
if showBull > 0
for i = 0 to math.min(showBull-1, bullish_ob.size())
get_ob = bullish_ob.get(i)
get_ob.display(bullCss, bullBreakCss)
//Bearish
if showBear > 0
for i = 0 to math.min(showBear-1, bearish_ob.size())
get_ob = bearish_ob.get(i)
get_ob.display(bearCss, bearBreakCss)
//
signalMode = input.string('Simple Entry + Exits', 'Signal
Stragety⠀⠀⠀⠀⠀⠀⠀⠀⠀', ['Simple Entry + Exits'],
group='basic settings', tooltip='Change Your Signal Appearance And
Strategies')
sensitivity = input.float(2.3, "Sensitivity⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀", 0.6, 15.1,
step=0.1,
group="basic settings", tooltip='Change Your Signal Sensitivity And
Accuracy')
strongSignalOnly = input(false, "STRONG Only⠀⠀⠀⠀⠀⠀ ⠀ ⠀⠀⠀", group="basic
settings", inline='BasicFilters')
noRepainting = input(false, 'No Repainting', group='basic settings',
inline='BasicFilters',
tooltip='Disables All Signals Except Strong Signals \n \nDisables Repainting
For Signals')
// basic chart features
ReversalCloud = input(false, 'Reversal C⠀⠀⠀', group='basic chart features',
inline='feature [R, 1]')
LongTrendAverage = input(false, 'Long Trend Average', group='basic chart
features', inline='feature [R, 1]',
tooltip='Places A Reversal Channel In Which Reversals Can Be Predicted \n \
nTrend Cloud Line (EMA), Will Be Shown On The Chart')
ReversalBands = input(false, 'Reversal Bands⠀⠀⠀', group='basic chart
features', inline='feature [R, 2]')
TrendTracer = input(false, 'Trend Tracer', group='basic chart features',
inline='feature [R, 2]',
tooltip='Displays Revesal Bands Similar To Reversal Cloud \n \nA Line Will Be
Placed On The Chart Which Is Used To Confirm Signals')
frequencyCloud = input(false, 'Frequency Cloud⠀⠀', 'Displays Short Trend
Cloud', group='basic chart features')
CandleColor = input.string('Trend Confirmation', 'Candle Stick Coloring',
['Trend Confirmation',
'Off'], group='basic chart features')
// leading features
LTAsensitivity = input.int(160, 'Long Trend Average Sensitivity⠀',
group='leading features')
//
//
src = close
smoothrng(x, t, m) =>
wper = t * 2 - 1
avrng = ta.ema(math.abs(x - x[1]), t)
smoothrng = ta.ema(avrng, wper) * m
smoothrng
smrng = smoothrng(close, 100, sensitivity)
rngfilt(x, r) =>
rngfilt = x
rngfilt := x > nz(rngfilt[1]) ? x - r < nz(rngfilt[1]) ? nz(rngfilt[1]) : x - r
: x + r > nz(rngfilt[1]) ? nz(rngfilt[1]) : x + r
rngfilt
filt = rngfilt(src, smrng)
//
upward = 0.0
upward := filt > filt[1] ? nz(upward[1]) + 1 : filt < filt[1] ? 0 : nz(upward[1])
downward = 0.0
downward := filt < filt[1] ? nz(downward[1]) + 1 : filt > filt[1] ? 0 :
nz(downward[1])
[mi, u, lo] = ta.kc(close, 90, 6.8)
[mid, upp, loww] = ta.kc(close, 90, 5.3)
[midd, ups, lowe] = ta.kc(close, 90, 4)
shorttop = ta.sma(close, 13)
longtop = ta.ema(close, 65)
eq_cloud_is_bullish = shorttop > longtop
//
hband = filt + smrng
lband = filt - smrng
longCond = bool(na)
shortCond = bool(na)
longCond := src > filt and src > src[1] and upward > 0 or src > filt and src <
src[1] and upward > 0
shortCond := src < filt and src < src[1] and downward > 0 or src < filt and src
> src[1] and downward > 0
CondIni = 0
CondIni := longCond ? 1 : shortCond ? -1 : CondIni[1]
//
buyCond = longCond and CondIni[1] == -1 and close[2] > lowe
strongBuyCond1 = longCond and CondIni[1] == -1 and close[2] <= lowe
sellCond = shortCond and CondIni[1] == 1 and open[4] < ups
strongSellCond1 = shortCond and CondIni[1] == 1 and open[4] >= ups
if noRepainting
buyCond := buyCond and barstate.isconfirmed
strongBuyCond1 := strongBuyCond1 and barstate.isconfirmed
sellCond := sellCond and barstate.isconfirmed
strongSellCond1 := strongSellCond1 and barstate.isconfirmed
plotshape(signalMode == 'Simple Entry + Exits' ? buyCond and not strongSignalOnly :
na,
'Buy', shape.labelup, location.belowbar, color.new(#21ff30, 0),
size=size.normal, textcolor=color.white, text='BUY')
plotshape(signalMode == 'Simple Entry + Exits' ? strongBuyCond1 : na, 'STRONG BUY',
shape.labelup, location.belowbar, color.new(#09ff00, 0), size=size.normal,
textcolor=color.white, text='STRONG BUY')
plotshape(signalMode == 'Simple Entry + Exits' ? sellCond and not
strongSignalOnly : na, 'SELL',
shape.labeldown, location.abovebar, color.new(#ff0000, 0), size=size.normal,
textcolor=color.white, text='SELL')
plotshape(signalMode == 'Simple Entry + Exits' ? strongSellCond1 : na, 'STRONG
SELL',
shape.labeldown, location.abovebar, color.new(#ff0000, 0), size=size.normal,
textcolor=color.white, text='STRONG SELL')
//
//
// ------------------------------------------------ Candle Color
----------------------------------------------------
barcolor = src > filt and src > src[1] and upward > 0 ? color.new(#00db0a, 5) : src
> filt and src <
src[1] and upward > 0 ? color.new(#00db05, 5) : src < filt and src < src[1]
and downward > 0 ? color.new(#c90505, 5) :
src < filt and src > src[1] and downward > 0 ? color.new(#ff0000 , 5) :
color.new(#3ebe48, 5) // 442886
barcolor(CandleColor == 'Trend Confirmation' ? barcolor : na, title='Candle
Colors')
//
//
// ------------------------------------------------ Reversal Cloud
--------------------------------------------------
u1 = plot(ReversalCloud ? ta.sma(u, 1) : na, transp=100, editable=false)
u2 = plot(ReversalCloud ? ta.sma(upp, 5) : na, transp=100, editable=false)
u3 = plot(ReversalCloud ? ta.sma(ups, 10) : na, transp=100, editable=false)
l1 = plot(ReversalCloud ? ta.sma(lo, 1) : na, transp=100, editable=false)
l2 = plot(ReversalCloud ? ta.sma(loww, 5) : na, transp=100, editable=false)
l3 = plot(ReversalCloud ? ta.sma(lowe, 10) : na, transp=100, editable=false)
plot(ReversalBands ? ta.sma(u, 1) : na, transp=50, editable=false, offset=2,
color=color.new(#f23645, 60))
plot(ReversalBands ? ta.sma(upp, 5) : na, transp=50, editable=false, offset=3,
color=color.new(#f23645, 70))
plot(ReversalBands ? ta.sma(ups, 10) : na, transp=50, editable=false, offset=3,
color=color.new(#f23645, 65))
plot(ReversalBands ? ta.sma(lowe, 10) : na, transp=50, editable=false, offset=3,
color=color.new(#089981, 65))
plot(ReversalBands ? ta.sma(loww, 5) : na, transp=50, editable=false, offset =3,
color=color.new(#089981, 70))
plot(ReversalBands ? ta.sma(lo, 1) : na, transp=50, editable=false, offset =2 ,
color=color.new(#089981, 60))
fill(u1, u2, color=color.new(#f23645, 65), title='Reversal Zones [R3, R2]')
fill(u2, u3, color=color.new(#f23645, 75), title='Reversal Zones [R2, R1]')
fill(l2, l3, color=color.new(#089981, 75), title='Reversal Zones [S2, S1]')
fill(l1, l2, color=color.new(#089981, 65), title='Reversal Zones [S3, S2]')
//
//
// ------------------------------------------------- Trend Catcher
--------------------------------------------------
filtcolor = upward > 0 ? color.rgb(0, 255, 85) : downward > 0 ? color.new(#ff0000,
0) : color.new(#56328f, 0)
plot(TrendTracer ? filt : na, color=filtcolor, linewidth=3, title='Trend Tracer')
//
//
// ------------------------------------------------ Frquency Cloud
--------------------------------------------------
plot_eq_closing_price = plot(frequencyCloud ? shorttop : na, transp=100,
editable=false)
plot_eq_external_value = plot(frequencyCloud ? longtop : na, transp=100,
editable=false)
eqCloudColor = ta.sma(close, 26) < ta.sma(close, 48) ? color.new(#ff0d00, 80) :
shorttop < longtop ? color.new(#ff1100, 80) :
ta.sma(close, 26) > ta.sma(close, 48) ? color.new(#007bff, 80) :
shorttop > longtop ? color.new(#0080ff, 80) : ta.sma(close, 34) >
ta.sma(close, 56) ? color.new(#0080ff, 80) : na
fill(plot_eq_closing_price, plot_eq_external_value, color = eqCloudColor,
title='Frequency Cloud Fill')
//
//
// ---------------------------------------------- Long Trend Average
------------------------------------------------
plot(LongTrendAverage ? ta.ema(close, LTAsensitivity) : na, 'Long Trend Average',
linewidth=5, color=close[8] > ta.ema(close, LTAsensitivity) ?
color.new(#0d67c2, 65) : color.new(#ff1100, 65))
//
//
//
atrPeriod = input.int(1, "ATR Length", minval = 1)
factor = input.float(4, "Factor", minval = 0.01, step = 0.01)
[supertrend, direction] = ta.supertrend(factor, atrPeriod)
supertrend := barstate.isfirst ? na : supertrend
upTrend = plot(direction < 0 ? supertrend : na, "Up Trend", color =
color.green, style = plot.style_linebr)
downTrend = plot(direction < 0 ? na : supertrend, "Down Trend", color = color.red,
style = plot.style_linebr)
bodyMiddle = plot(barstate.isfirst ? na : (open + close) / 2, "Body Middle",display
= display.none)
fill(bodyMiddle, upTrend, color.new(color.green, 90), fillgaps = false)
fill(bodyMiddle, downTrend, color.new(color.red, 90), fillgaps = false)
alertcondition(direction[1] > direction, title='Downtrend to Uptrend', message='The
Supertrend value switched from Downtrend to Uptrend ')
alertcondition(direction[1] < direction, title='Uptrend to Downtrend', message='The
Supertrend value switched from Uptrend to Downtrend')
alertcondition(direction[1] != direction, title='Trend Change', message='The
Supertrend value switched from Uptrend to Downtrend or vice versa')
//#region Inputs
inside_band_group = "=== Inside Band ==="
on_1 = input.bool(true,"",
inline="0",group=inside_band_group)
src_1 = input(high, title="Source",
inline="0",group=inside_band_group)
inside_col = input.color(color.new(color.white,100),
"",inline="0",group=inside_band_group)
length_1 = input.int(77, "Length", minval=1,
inline="0.1",group=inside_band_group)
mult_1 = input(4.0, "Multi",
inline="0.1",group=inside_band_group)
//If you want to add option to let used choose how the bands are calculated unblock
these options
atrLength_1 = 10//input(10, "ATR ",
inline="0",group=inside_band_group)
exp_1 = true//input(true, "Use EMA",
inline="0.2",group=inside_band_group)
BandsStyle_1 = "Range"//input.string("Range", options = ["Average
True Range", "True Range", "Range"], title="Bands Style",
inline="0.2",group=inside_band_group)
outside_band_group = "=== Outside Band ==="
on_2 = input.bool(true,"",
inline="0",group=outside_band_group)
src_2 = input(high, title="Source",
inline="0",group=outside_band_group)
outside_col = input.color(color.new(color.gray,90),
"",inline="0",group=outside_band_group)
length_2 = input.int(36, "Length", minval=1,
inline="0.1",group=outside_band_group)
mult_2 = input(8.0, "Multi",
inline="0.1",group=outside_band_group)
//If you want to add option to let used choose how the bands are calculated unblock
these options
atrLength_2 = 10//input(10, "ATR ",
inline="0",group=outside_band_group)
exp_2 = true//input(true, "Use EMA",
inline="0.2",group=outside_band_group)
BandsStyle_2 = "Range"//input.string("Range", options = ["Average
True Range", "True Range", "Range"], title="Bands Style",
inline="0.2",group=outside_band_group)
alert_group = "=== Alerts ==="
inside_alert = input.bool(true, title="Alert for inside Band
Touch", group=alert_group, tooltip="To set alert, click on the 3 dots next to the
indicators name, click 'Add Alert', You can name the alert what you want but then
just click create")
outside_alert = input.bool(true, title="Alert for Outside Band
Touch", group=alert_group, tooltip="To set alert, click on the 3 dots next to the
indicators name, click 'Add Alert', You can name the alert what you want but then
just click create")
old_group = "=== Show Old Signals ==="
inside_old = input.bool(true, title="Show where Alerts triggered
for Inside touches", group=old_group)
outside_old = input.bool(true, title="Show where Alerts triggered
for Outside touches", group=old_group)
divergence_group = "=== Divergence ==="
show_divergence = input.bool(true, title="Show Divergence",
group=divergence_group, inline="0")
div_line_col = input.color(color.black, title="Colour",
group=divergence_group, inline="0")
rsi_length = input.int(14, title="RSI Length",
group=divergence_group, inline="1")
show_rsi_val = input.bool(false, title="Show RSI Values",
group=divergence_group, inline="1")
gradient_group = "=== Band Gradients ==="
band_gradients = input.bool(true, title="Band Gradients",
group=gradient_group, inline="1")
band_bull_Input = input.color(#00E600, title="", group=gradient_group,
inline="1")
band_bear_Input = input.color(#FF0000, title="", group=gradient_group,
inline="1")
//#endregion
//#region Functions
esma(source, length, _exp)=>
s = ta.sma(source, length)
e = ta.ema(source, length)
_exp ? e : s
//#endregion
//#region MA
ma = esma(src_2, length_2, exp_2)
//#endregion
//#region Inside Band Calc
rangema_1 = BandsStyle_1 == "True Range" ? ta.tr(true) : BandsStyle_1 == "Average
True Range" ? ta.atr(atrLength_1) : ta.rma(high - low, length_1)
upper_1 = ma + rangema_1 * mult_1
lower_1 = ma - rangema_1 * mult_1
//#endregion
//#region Outside Band Calc
rangema_2 = BandsStyle_2 == "True Range" ? ta.tr(true) : BandsStyle_2 == "Average
True Range" ? ta.atr(atrLength_2) : ta.rma(high - low, length_2)
upper_2 = ma + rangema_2 * mult_2
lower_2 = ma - rangema_2 * mult_2
//#endregion
//#region Signals
inside_touch = ta.crossunder(low,lower_1) or ta.crossover(high,upper_1)
outside_touch = ta.crossunder(low,lower_2) or ta.crossover(high,upper_2)
//#endregion
//#region Colour Calculation
gradient_up_sig = ta.barssince(close<ma)
gradient_lo_sig = ta.barssince(close>ma)
gradient_up_col = band_gradients ? color.from_gradient(gradient_up_sig, 0, 250,
outside_col,band_bear_Input) : outside_col
gradient_lo_col = band_gradients ? color.from_gradient(gradient_lo_sig, 0, 250,
outside_col,band_bull_Input) : outside_col
//#endregion
//#region plots
plot(ma, color=#311b9200, title="Basis")
//Inside Band Plots and fillsu1 = plot(on_1 ? upper_1 : na, color=inside_col,
title="Upper")l1 = plot(on_1 ? lower_1 : na, color=inside_col, title="Lower")
fill(u1, l1, color=inside_col, title="Background")
//Outside Band Plots and Fillsu2 = plot(on_2 ? upper_2 : na, color=outside_col,
title="Outside Upper")l2 = plot(on_2 ?lower_2 : na, color=outside_col,
title="Outside Lower")
fill(l1, l2, color=gradient_lo_col, title="Outside Lower Background")
fill(u1, u2, color=gradient_up_col, title="Outside Upper Background")
//Signal Plots
low_col = #00E600
high_col = #FF0000
plotshape(inside_old ? ta.crossunder(low,lower_1) : na ,
location=location.belowbar, color=low_col, style=shape.triangleup)
plotshape(outside_old ? ta.crossunder(low,lower_2) : na ,
location=location.belowbar, color=low_col, style=shape.triangleup)
plotshape(inside_old ? ta.crossover(high,upper_1) : na ,
location=location.abovebar, color=high_col, style=shape.triangledown)
plotshape(outside_old ? ta.crossover(high,upper_2) : na ,
location=location.abovebar, color=high_col, style=shape.triangledown)
//#endregion
//#region Alerts
if inside_touch
inside_msg = ta.crossunder(low,lower_1) ? "Inside band Low Touch on " +
str.tostring(syminfo.tickerid) : "Inside band High Touch on " +
str.tostring(syminfo.tickerid)
alert(inside_msg, alert.freq_once_per_bar)
if outside_touch
outside_msg = ta.crossunder(low,lower_2) ? "Inside band Low Touch on " +
str.tostring(syminfo.tickerid) : "Inside band High Touch on " +
str.tostring(syminfo.tickerid)
alert(outside_msg, alert.freq_once_per_bar)
//#endregion
//#region Divergence
rsi = ta.rsi(close,rsi_length)
offset = 2
rsi_low = ta.pivotlow(rsi,3,offset)
price_low = ta.pivotlow(close,3,offset)
rsi_high = ta.pivothigh(rsi,3,offset)
price_high = ta.pivothigh(close,3,offset)
//Low Arrays
var float [] rsi_recent_low = array.new_float()
var float [] price_recent_low = array.new_float()
var int [] rsi_recent_low_i = array.new_int()
var int [] price_recent_low_i = array.new_int()
//High Arrays
var float [] rsi_recent_high = array.new_float()
var float [] price_recent_high = array.new_float()
var int [] rsi_recent_high_i = array.new_int()
var int [] price_recent_high_i = array.new_int()
if price_low
array.unshift(price_recent_low, price_low)
array.unshift(price_recent_low_i, bar_index-offset)
array.unshift(rsi_recent_low, rsi_low)
array.unshift(rsi_recent_low_i, bar_index-offset)
if price_high
array.unshift(price_recent_high, price_high)
array.unshift(price_recent_high_i, bar_index-offset)
array.unshift(rsi_recent_high, rsi_high)
array.unshift(rsi_recent_high_i, bar_index-offset)
div(osc_array,price_array,index_array,direction)=>
if array.size(osc_array)>1 and array.size(price_array)>1
bull_osc_sig = array.get(osc_array,0) > array.get(osc_array,1)
bull_price_sig = array.get(price_array,0) < array.get(price_array,1)
bear_osc_sig = array.get(osc_array,0) < array.get(osc_array,1)
bear_price_sig = array.get(price_array,0) > array.get(price_array,1)
sig = direction == "Bull" ? bull_osc_sig and bull_price_sig :
bear_osc_sig and bear_price_sig
if sig
//Line Drawing
x1 = array.get(index_array,1)
x2 = array.get(index_array,0)
y1 = array.get(price_array,1)
y2 = array.get(price_array,0)
line.new(x1,y1,x2,y2, color=div_line_col)
if show_rsi_val
//Label direction
label_style = direction == "Bull" ? label.style_label_up :
label.style_label_down
//Label Drawings
label_x1 = array.get(index_array,1)
label_x2 = array.get(index_array,0)
//
label.new(label_x1, y1,
text=str.tostring(math.round(array.get(osc_array,1),2)), style=label_style,
color=color.new(#FFFFFF,0), textcolor = color.black)
label.new(label_x2, y2,
text=str.tostring(math.round(array.get(osc_array,0),2)), style=label_style,
color=color.new(#FFFFFF,0), textcolor = color.black)
if price_low and show_divergence
div(rsi_recent_low,price_recent_low,price_recent_low_i, "Bull")
if price_high and show_divergence
div(rsi_recent_high,price_recent_high,price_recent_high_i, "Bear")
//#endregion
// { <CONSTANTS>
MAIN_GROUP = "Main Settings"
DELETE_GROUP = "Deletion Settings"
COSMETIC_GROUP = "Cosmetic Settings"
// } <CONSTANTS>
// { <INPUTS>
levelMethod = input.string(
title = "Detection Method",
defval = "Wick",
options = ["Wick", "Body"],
group = MAIN_GROUP)
leftBars = input.int(
title = "Left Bars",
defval = 20,
group = MAIN_GROUP,
inline = "pivot")
rightBars = input.int(
title = "Right Bars",
defval = 20,
group = MAIN_GROUP,
inline = "pivot")
retestLogic = input.bool(
title = "Retest Weaker",
defval = false,
tooltip = "Retest makes level weaker vs retest makes level stronger",
group = MAIN_GROUP)
definitionOfDelete = input.string(
title = "Delete Definition",
defval = "Stop Updating Level",
options = ["Stop Updating Level", "Completely Delete Level", "Stop Updating
Level & Turn Level Unique Color"],
group = DELETE_GROUP)
flipsUntilDeletion = input.int(
title = "Breakouts Until Level Deletes",
defval = 1,
group = DELETE_GROUP)
ageUntilDeletion = input.int(
title = "Bars Until Level Deletes",
defval = 300,
group = DELETE_GROUP)
supportColor = input.color(
title = "Initial Support Re-Test Color",
defval = color.rgb(76, 175, 79, 50),
group = COSMETIC_GROUP)
resistanceColor = input.color(
title = "Initial Resistance Re-Test Color",
defval = color.rgb(255, 82, 82, 50),
group = COSMETIC_GROUP)
uniqueDeleteColor = input.color(
title = "Unique Deletion Color",
defval = color.rgb(120, 123, 134, 50),
group = COSMETIC_GROUP)
changeColorMethod = input.string(
title = "Change Color Method",
defval = "Price Above/Below",
options = ["Price Above/Below", "Fade Out Based On Age"],
group = COSMETIC_GROUP)
lineWidth = input.int(
title = "Line Width",
defval = 10,
group = COSMETIC_GROUP)
// } <INPUTS>
// { <USER DEFINED TYPES>
type flipLevelManager
array<string> variation
array<line> lineArray
array<int> lineAge
array<int> lineFlips
array<int> linePhase
// } <USER DEFINED TYPES>
// { <CALCULATIONS>
pivotHigh = ta.pivothigh(
levelMethod == "Wick" ?
high : close > open ? close : open,
leftBars,
rightBars)
pivotLow = ta.pivotlow(
levelMethod == "Wick" ?
low : close < open ? close : open,
leftBars,
rightBars)
newHigh = not na(pivotHigh)
newLow = not na(pivotLow)
newTestedSupport = false
newTestedResistance = false
supportBrokeDownside = false
supportBrokeUpside = false
resistanceBrokeDownside = false
resistanceBrokeUpside = false
var firstPhaseHigh = array.new_float()
var firstPhaseHighI = array.new_int()
var firstPhaseLow = array.new_float()
var firstPhaseLowI = array.new_int()
var secondPhaseHigh = array.new_float()
var secondPhaseHighI = array.new_int()
var secondPhaseLow = array.new_float()
var secondPhaseLowI = array.new_int()
var flipManager = flipLevelManager.new(
array.new_string(),
array.new_line(),
array.new_int(),
array.new_int(),
array.new_int())
if barstate.isconfirmed
if newHigh
array.push(firstPhaseHigh, pivotHigh)
array.push(firstPhaseHighI, bar_index[rightBars])
if newLow
array.push(firstPhaseLow, pivotLow)
array.push(firstPhaseLowI, bar_index[rightBars])
for i = array.size(secondPhaseHigh) > 0 ? array.size(secondPhaseHigh) - 1 : na
to 0
price = array.get(secondPhaseHigh, i)
index = array.get(secondPhaseHighI, i)
if low <= price and close > price and close > open
newLine = line.new(
x1 = index, y1 = price,
x2 = bar_index, y2 = price,
xloc = xloc.bar_index, extend = extend.none,
color = supportColor, width = lineWidth)
array.push(flipManager.lineArray, newLine)
array.push(flipManager.variation, "Support")
array.push(flipManager.lineAge, 0)
array.push(flipManager.lineFlips, 0)
array.push(flipManager.linePhase, 1)
array.remove(secondPhaseHigh, i)
array.remove(secondPhaseHighI, i)
newTestedSupport := true
else if bar_index - index > 1000 or close < price
array.remove(secondPhaseHigh, i)
array.remove(secondPhaseHighI, i)
for i = array.size(secondPhaseLow) > 0 ? array.size(secondPhaseLow) - 1 : na to
0
price = array.get(secondPhaseLow, i)
index = array.get(secondPhaseLowI, i)
if high >= price and close < price and close < open
newLine = line.new(
x1 = index, y1 = price,
x2 = bar_index, y2 = price,
xloc = xloc.bar_index, extend = extend.none,
color = resistanceColor, width = lineWidth)
array.push(flipManager.lineArray, newLine)
array.push(flipManager.variation, "Resistance")
array.push(flipManager.lineAge, 0)
array.push(flipManager.lineFlips, 0)
array.push(flipManager.linePhase, -1)
array.remove(secondPhaseLow, i)
array.remove(secondPhaseLowI, i)
newTestedResistance := true
else if bar_index - index > 1000 or close > price
array.remove(secondPhaseLow, i)
array.remove(secondPhaseLowI, i)
for i = array.size(firstPhaseHigh) > 0 ? array.size(firstPhaseHigh) - 1 : na to
0
price = array.get(firstPhaseHigh, i)
index = array.get(firstPhaseHighI, i)
if low > price
array.push(secondPhaseHigh, price)
array.push(secondPhaseHighI, index)
array.remove(firstPhaseHigh, i)
array.remove(firstPhaseHighI, i)
else if bar_index - index > 1000
array.remove(firstPhaseHigh, i)
array.remove(firstPhaseHighI, i)
for i = array.size(firstPhaseLow) > 0 ? array.size(firstPhaseLow) - 1 : na to 0
price = array.get(firstPhaseLow, i)
index = array.get(firstPhaseLowI, i)
if high < price
array.push(secondPhaseLow, price)
array.push(secondPhaseLowI, index)
array.remove(firstPhaseLow, i)
array.remove(firstPhaseLowI, i)
else if bar_index - index > 1000
array.remove(firstPhaseLow, i)
array.remove(firstPhaseLowI, i)
for i = array.size(flipManager.lineArray) > 0 ?
array.size(flipManager.lineArray) - 1 : na to 0
lineObject = array.get(flipManager.lineArray, i)
lineAge = array.get(flipManager.lineAge, i)
lineType = array.get(flipManager.variation, i)
lineFlips = array.get(flipManager.lineFlips, i)
linePhase = array.get(flipManager.linePhase, i)
linePrice = line.get_y1(lineObject)
line.set_x2(lineObject, bar_index + 1)
lineColor = lineType == "Support" ? supportColor : resistanceColor
gradientLineColor = color.from_gradient(lineAge, 0, ageUntilDeletion,
lineColor, color.new(lineColor, 100))
newLineColor = changeColorMethod == "Fade Out Based On Age" ?
gradientLineColor : close > linePrice ? supportColor : resistanceColor
line.set_color(lineObject, newLineColor)
array.set(flipManager.lineAge, i, lineAge + 1)
if lineType == "Support"
if linePhase == 1 and close < linePrice
array.set(flipManager.lineFlips, i, lineFlips + 1)
array.set(flipManager.linePhase, i, -1)
supportBrokeDownside := true
else if linePhase == -1 and close > linePrice
array.set(flipManager.lineFlips, i, lineFlips + 1)
array.set(flipManager.linePhase, i, 1)
supportBrokeUpside := true
if lineType == "Resistance"
if linePhase == -1 and close > linePrice
array.set(flipManager.lineFlips, i, lineFlips + 1)
array.set(flipManager.linePhase, i, 1)
resistanceBrokeUpside := true
else if linePhase == 1 and close < linePrice
array.set(flipManager.lineFlips, i, lineFlips + 1)
array.set(flipManager.linePhase, i, -1)
resistanceBrokeDownside := true
lineFlips := array.get(flipManager.lineFlips, i)
if lineFlips >= flipsUntilDeletion or lineAge >= ageUntilDeletion
if definitionOfDelete == "Completely Delete Level"
line.delete(lineObject)
array.remove(flipManager.lineArray, i)
array.remove(flipManager.lineAge, i)
array.remove(flipManager.lineFlips, i)
array.remove(flipManager.variation, i)
array.remove(flipManager.linePhase, i)
else if definitionOfDelete == "Stop Updating Level"
array.remove(flipManager.lineArray, i)
array.remove(flipManager.lineAge, i)
array.remove(flipManager.lineFlips, i)
array.remove(flipManager.variation, i)
array.remove(flipManager.linePhase, i)
else if definitionOfDelete == "Stop Updating Level & Turn Level Unique
Color"
line.set_color(lineObject, uniqueDeleteColor)
array.remove(flipManager.lineArray, i)
array.remove(flipManager.lineAge, i)
array.remove(flipManager.lineFlips, i)
array.remove(flipManager.variation, i)
array.remove(flipManager.linePhase, i)
// } <CALCULATIONS>
// { <VISUALS>
plotshape(
series = newTestedSupport,
title = "New Support Re-Test X",
style = retestLogic ? shape.labeldown : shape.labelup,
text = "R",
textcolor = color.white,
location = retestLogic ? location.abovebar : location.belowbar,
color = retestLogic ? color.red :color.green,
size = size.tiny,
show_last = 20000)
plotshape(
series = newTestedResistance,
title = "New Resistance Re-Test X",
style = retestLogic ? shape.labelup : shape.labeldown,
text = "R",
textcolor = color.white,
location = retestLogic ? location.belowbar : location.abovebar,
color = retestLogic ? color.green : color.red,
size = size.tiny,
show_last = 20000)
// } <VISUALS>
// { <ALERTS>
alertcondition(
condition = newTestedSupport,
title = "New Support Re-Test")
alertcondition(
condition = newTestedResistance,
title = "New Resistance Re-Test")
alertcondition(
condition = supportBrokeDownside,
title = "Support Re-Test Downside Break")
alertcondition(
condition = supportBrokeUpside,
title = "Support Re-Test Upside Break")
alertcondition(
condition = resistanceBrokeDownside,
title = "Resistance Re-Test Downside Break")
alertcondition(
condition = resistanceBrokeUpside,
title = "Resistance Re-Test Upside Break")
alertcondition(
condition = supportBrokeDownside or resistanceBrokeDownside,
title = "Any Downside Break")
alertcondition(
condition = supportBrokeUpside or resistanceBrokeUpside,
title = "Any Upside Break")
// } <ALERTS>