D-Shape Breakout Signals (LuxAlgo)
D-Shape Breakout Signals (LuxAlgo)
0
International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo
//@version=5
indicator('D-Shape Breakout Signals [LuxAlgo]', shorttitle='LuxAlgo - D-Shape
Breakout Signals', max_labels_count=500, max_lines_count=200,
max_polylines_count=100, max_bars_back=5000, overlay=true)
//---------------------------------------------------------------------------------
------------------------------------}
// Settings
//---------------------------------------------------------------------------------
------------------------------------{
left = input.int ( 50, 'Swing Length' , minval= 1 )
binSize = input.int ( 1, 'Minumum Patterns' , minval= 1, maxval= 100 ,
group='D-Patterns'
, tooltip ='Minimal Amount Of Visible D-Patterns\n (Active Patterns
won\'t be deleted)') -1
cWidth = input.int ( 100, 'D-Width' , minval=50, maxval= 1500 ,
group='D-Patterns'
, tooltip ='% Distance Swings'
) / 50
swings = input.string('Swing High/Low', 'Included Swings'
, options =[ 'Swing High', 'Swing Low', 'Swing High/Low'
])
styleD = input.string('Arc', 'Style Historical Patterns', options=['Arc',
'Midline', 'Both' ])
size = str.lower(input.string( 'Small', 'Label Size' ,
group='Style'
, options =[ 'Tiny', 'Small', 'Normal','Large'
]) )
cBull = input.color (#089981, 'Bull ' ,
group='Style' )
cBear = input.color (#f23645, 'Bear' ,
group='Style' )
cNeut = input.color (#085def, 'Neutral' ,
group='Style' )
origine = input.bool ( true, 'Connecting Swing Level' ,
group='Style' )
iFill = input.bool ( true, 'Color Fill' ,
group='Style' )
//---------------------------------------------------------------------------------
------------------------------------}
//LuxAlgo Defined Types
//---------------------------------------------------------------------------------
------------------------------------{
type D
bool bear
array<chart.point>cp1
array<chart.point>cp2
array<chart.point>cp3
polyline poly1
polyline poly2
line mid
line orig
bool act
= true
//---------------------------------------------------------------------------------
------------------------------------}
//Constants and general variables
//---------------------------------------------------------------------------------
------------------------------------{
n = bar_index
INV = color(na)
pi = math.pi
pi2 = pi / 2
//---------------------------------------------------------------------------------
------------------------------------}
//Variables
//---------------------------------------------------------------------------------
------------------------------------{
breakOut = false
var float tsl = close
var float tslU = na
var float tslD = na
var int trend = 0
var array<D>aD = array.new< D >()
//---------------------------------------------------------------------------------
------------------------------------}
//Methods
//---------------------------------------------------------------------------------
------------------------------------{
method set_Historical_D(D D, color col) =>
D.poly1.delete(), D.poly2.delete(), D.act := false
switch styleD
'Arc' =>
if D.bear
D.cp1.pop()
D.cp2.shift()
else
D.cp1.shift(), D.cp1.pop()
D.cp2.shift(), D.cp2.pop()
'Midline' =>
D.mid .set_color( color.new(col,
65))
if origine
D.orig .set_color( color.new(col,
35))
=>
D.cp1.unshift (D.cp2.last()
)
D.poly1 := polyline.new(D.cp1, closed=false, line_color=color.new(col,
65))
D.poly2 := polyline.new(D.cp2, closed=false, line_color=color.new(col,
65))
D.mid .set_color( color.new(col,
65))
if origine
D.orig .set_color( color.new(col,
35))
//---------------------------------------------------------------------------------
------------------------------------}
//Exec
//---------------------------------------------------------------------------------
------------------------------------{
if barstate.isfirst
for i = 0 to binSize
aD.push(
D.new(
na
, array.new<chart.point>()
, array.new<chart.point>()
, array.new<chart.point>()
, polyline.new(na)
, polyline.new(na)
, line(na)
, line(na)
, false)
)
ph = ta.pivothigh(left , 1 )
vwPh_bix = ta.valuewhen(not na(ph), n-1, 0)
vwPh_prc = ta.valuewhen(not na(ph), ph , 0)
pl = ta.pivotlow (left , 1 )
vwPl_bix = ta.valuewhen(not na(pl), n-1, 0)
vwPl_prc = ta.valuewhen(not na(pl), pl , 0)
//swing H -> L
if swingHL and not na(pl) and na(ph) and pl < vwPh_prc
points1= array.new<chart.point>()
points2= array.new<chart.point>()
points3= array.new<chart.point>()
Dnew = D.new()
points2.unshift(chart.point.from_index(x , avg))
points2.unshift(chart.point.from_index(n-1, avg))
Dnew.cp2 := points2
Dnew.poly2 := polyline.new(points2, closed=true, line_color=cBull)
Dnew.mid := line.new(n-1, math.avg(vwPh_prc, pl), n-1+w2, math.avg(vwPh_prc,
pl), color=INV)
points3 := points1.copy()
points3.concat(points2)
Dnew.cp3 := points3
Dnew.bear := false
if origine
Dnew.orig := line.new(vwPh_bix, vwPh_prc, n-1, vwPh_prc, color=cBull,
style=line.style_dotted)
aD.unshift(Dnew)
//Swing L -> H
if swingLH and not na(ph) and na(pl) and ph > vwPl_prc
points1= array.new<chart.point>()
points2= array.new<chart.point>()
points3= array.new<chart.point>()
Dnew = D.new()
points2.unshift(chart.point.from_index(x , avg))
points2.unshift(chart.point.from_index(n-1, avg))
Dnew.cp2 := points2
points3 := points1.copy()
points3.concat(points2)
Dnew.cp3 := points3
Dnew.bear := true
if origine
Dnew.orig := line.new(vwPl_bix, vwPl_prc, n-1, vwPl_prc, color=cBear,
style=line.style_dotted)
aD.unshift(Dnew)
aDsz = aD.size()
if aDsz > 0
for i = aDsz -1 to 0
get = aD.get(i)
if get.act and get.cp3.size() > 0
if n > get.mid.get_x2()
label.new(n, high, color=INV, text='●', textcolor=color.blue,
style=label.style_label_down, size=size)
get.set_Historical_D(cNeut)
else
//get Upper Half of Arc
for j = 0 to math.round(get.cp3.size() /2) -1
point = get.cp3.get(j)
if point.index == n
//Add Arc- & Midline price to pointsU when close is lower
price = point.price
l_prc = get.mid.get_y2()
if point.index == n
//Add Arc- & Midline price to pointsD when close is higher
price = point.price
l_prc = get.mid.get_y2()
if breakOut
tsl := trend == 1 ? tslD : trend == -1 ? tslU : close < tsl ? -1 : 1
//---------------------------------------------------------------------------------
------------------------------------}
//Plot
//---------------------------------------------------------------------------------
------------------------------------{
t = plot(tsl
, color=ta.change(trend) != 0 ? color(na) : trend < 1 ? cBear : cBull
, style=plot.style_linebr, display=display.all - display.status_line)
fill(c, t
, not iFill ? na : trend == 1 ? tsl : close
, not iFill ? na : trend == 1 ? close : tsl
, not iFill ? na : trend == 1 ? color.new(cBull, 80)
: color(na)
, not iFill ? na : trend == 1 ? color(na)
: color.new(cBear, 80)
)
//---------------------------------------------------------------------------------
------------------------------------}