Fibonacci Ranges (Real-Time) (LuxAlgo)
Fibonacci Ranges (Real-Time) (LuxAlgo)
0
International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/
// © LuxAlgo
//@version=5
indicator("Fibonacci Ranges (Real-Time) [LuxAlgo]", shorttitle='LuxAlgo - Fibonacci
Ranges (Real-Time)', max_lines_count=500, max_labels_count=500, overlay=true)
//------------------------------------------------------------------------------
//Settings
//-----------------------------------------------------------------------------{
z = ' '
y = ' '
x = ' '
L = input.int ( 5 , 'L' , minval =1
, group = 'Swing Settings' )
R = input.int ( 1 , 'R' , minval =1
, group = 'Swing Settings' )
c_ = input.string( 'Channel + Shadows' , 'Channel' ,
options=['Channel', 'Channel + Shadows', 'None'], group = 'Fibonacci Channel'
)
opt= input.string('0.000 - 1.000', 'Break level' ,
group = 'Fibonacci Channel'
, options= ['-
0.382 - 1.382', '0.000 - 1.000', '0.236 - 0.764', '0.382 - 0.618'] )
c = input.int ( 2 , 'Break count' , minval =0
, group = 'Fibonacci Channel' )
sb = input.bool ( true , z+x+ 'Show breaks'
, group = 'Fibonacci Channel' )
sF = input.bool ( false , z+y+ 'Latest Fibonacci' ,
group = 'Fibonacci' )
F0 = input.color ( #08998164 , ' ' , inline='f'
, group = 'Fibonacci' )
F_ = input.color ( #08998180 , '' , inline='f'
, group = 'Fibonacci' )
Fm = input.color ( #1e42b070 , '' , inline='f'
, group = 'Fibonacci' )
Fp = input.color ( #f2364580 , '' , inline='f'
, group = 'Fibonacci' )
F1 = input.color ( #f2364564 , '' , inline='f'
, group = 'Fibonacci' )
n = bar_index
//-----------------------------------------------------------------------------}
//User Defined Types
//-----------------------------------------------------------------------------{
type piv
int b
float p
int d
type fib
line n0_382
line _0_000
line _0_236
line _0_382
line _0_500
line _0_618
line _0_764
line _1_000
line _1_382
line diagon
label lab1
label lab2
bool active
int count
type fibLast
linefill lf_0
linefill lfM0
linefill lfM1
linefill lf_1
line ln_0_5
line diagon
label lab
//-----------------------------------------------------------------------------}
//Variables
//-----------------------------------------------------------------------------{
var piv[] pivs = array.new<piv>()
//-----------------------------------------------------------------------------}
//Execution
//-----------------------------------------------------------------------------{
ph = ta.pivothigh(L, R)
pl = ta.pivotlow (L, R)
a1 = switch opt
'-0.382 - 1.382' => -0.382
'0.000 - 1.000' => 0
'0.236 - 0.764' => 0.236
'0.382 - 0.618' => 0.382
a2 = switch opt
'-0.382 - 1.382' => 1.382
'0.000 - 1.000' => 1
'0.236 - 0.764' => 0.764
'0.382 - 0.618' => 0.618
if ph
if pivs.size() > 0
get = pivs.first()
if get.d > 0 and ph > get.p
get.b := n -R
get.p := high[R]
if get.d < 0 and ph > get.p
pivs.unshift(piv.new(n -R, high[R] , 1))
else
pivs .unshift(piv.new(n -R, high[R] , 1))
if pl
if pivs.size() > 0
get = pivs.first()
if get.d < 0 and pl < get.p
get.b := n -R
get.p := low [R]
if get.d > 0 and pl < get.p
pivs.unshift(piv.new(n -R, low [R] ,-1))
else
pivs .unshift(piv.new(n -R, low [R] ,-1))
if pivs.size() >= 2
max = math.max(pivs.first().p, pivs.get(1).p )
min = math.min(pivs.first().p, pivs.get(1).p )
dif = max - min
_0i = pivs.first( ).b, _0p = pivs.first( ).p
_1i = pivs.get (1).b, _1p = pivs.get (1).p
d = _0p < _1p ? -dif : dif
x2 = math.max(last_bar_index , _0i) + 8
l0_1 = fLast. lf_0.get_line1(), l0_2 = fLast.
lf_0.get_line2()
lM01 = fLast. lfM0.get_line1(), lM02 = fLast.
lfM0.get_line2()
lM11 = fLast. lfM1.get_line1(), lM12 = fLast.
lfM1.get_line2()
l1_1 = fLast. lf_1.get_line1(), l1_2 = fLast.
lf_1.get_line2()
if f.active
lv1 = opt == '0.000 - 1.000' ? f._0_000 : opt == '0.236 - 0.764' ? f._0_236 :
opt == '0.382 - 0.618' ? f._0_382 : f.n0_382
lv2 = opt == '0.000 - 1.000' ? f._1_000 : opt == '0.236 - 0.764' ? f._0_764 :
opt == '0.382 - 0.618' ? f._0_618 : f._1_382
else
f.n0_382.set_x2(n + 8)
f._0_000.set_x2(n + 8)
f._0_236.set_x2(n + 8)
f._0_382.set_x2(n + 8)
f._0_500.set_x2(n + 8)
f._0_618.set_x2(n + 8)
f._0_764.set_x2(n + 8)
f._1_000.set_x2(n + 8)
f._1_382.set_x2(n + 8)
f.lab1 .set_x (n + 8)
f.lab2 .set_x (n + 8)
//-----------------------------------------------------------------------------}
//Plots
//-----------------------------------------------------------------------------{
plotn0_382 = f.n0_382.get_y2()
plot_0_000 = f._0_000.get_y2()
plot_0_236 = f._0_236.get_y2()
plot_0_382 = f._0_382.get_y2()
plot_0_500 = f._0_500.get_y2()
plot_0_618 = f._0_618.get_y2()
plot_0_764 = f._0_764.get_y2()
plot_1_000 = f._1_000.get_y2()
plot_1_382 = f._1_382.get_y2()
ch = ta.change(plot_0_000)
//-----------------------------------------------------------------------------}
//Alerts
//-----------------------------------------------------------------------------{
alertcondition(brokeU and f.active[1], 'break Up' , 'break Up' )
alertcondition(brokeD and f.active[1], 'break Down', 'break Donw')
//-----------------------------------------------------------------------------}