Algo
Algo
//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')
//-----------------------------------------------------------------------------}
//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)
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]
//-----------------------------------------------------------------------------}
//Detect Swings
//-----------------------------------------------------------------------------{
n = bar_index
//-----------------------------------------------------------------------------}
//Bullish OB
//-----------------------------------------------------------------------------{
var bullish_ob = array.new<ob>(0)
bull_break_conf = 0
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
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
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
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)
//
// 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])
//
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]
//
if noRepainting
buyCond := buyCond and barstate.isconfirmed
strongBuyCond1 := strongBuyCond1 and barstate.isconfirmed
sellCond := sellCond and barstate.isconfirmed
strongSellCond1 := strongSellCond1 and barstate.isconfirmed
//
//
// ------------------------------------------------ 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
//
//
// ------------------------------------------------ Reversal Cloud
--------------------------------------------------
//
//
// ------------------------------------------------- Trend Catcher
--------------------------------------------------
//
//
// ------------------------------------------------ Frquency Cloud
--------------------------------------------------
//
//
// ---------------------------------------------- Long Trend Average
------------------------------------------------
//
//
//
//#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)
//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)
//#endregion
//#region Functions
esma(source, length, _exp)=>
s = ta.sma(source, length)
e = ta.ema(source, length)
_exp ? e : s
//#endregion
//#region MA
//#endregion
//#region Signals
//#endregion
gradient_up_sig = ta.barssince(close<ma)
gradient_lo_sig = ta.barssince(close>ma)
//#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")
//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
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)
// { <CONSTANTS>
// } <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>
type flipLevelManager
array<string> variation
array<line> lineArray
array<int> lineAge
array<int> lineFlips
array<int> linePhase
// { <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)
newTestedSupport = false
newTestedResistance = false
supportBrokeDownside = false
supportBrokeUpside = false
resistanceBrokeDownside = false
resistanceBrokeUpside = false
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])
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
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
linePrice = line.get_y1(lineObject)
line.set_x2(lineObject, bar_index + 1)
array.set(flipManager.lineAge, i, lineAge + 1)
if lineType == "Support"
if lineType == "Resistance"
lineFlips := array.get(flipManager.lineFlips, 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>