0% found this document useful (0 votes)
176 views2 pages

C

This document defines an indicator to plot Fibonacci retracement lines on a chart. It calculates the highest and lowest closing prices from the last 150 bars to determine the high-low range. It then plots lines at the common Fibonacci retracement levels of 0%, 23.6%, 38.2%, 50%, 61.8%, 78.6%, and 100% along with labels identifying each level.

Uploaded by

Rafael Rubio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
176 views2 pages

C

This document defines an indicator to plot Fibonacci retracement lines on a chart. It calculates the highest and lowest closing prices from the last 150 bars to determine the high-low range. It then plots lines at the common Fibonacci retracement levels of 0%, 23.6%, 38.2%, 50%, 61.8%, 78.6%, and 100% along with labels identifying each level.

Uploaded by

Rafael Rubio
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//@version=5

indicator('Fibonacci retracement lines', overlay=true)


per = input(150, 'Calculate for last bars')
hl = [Link](high, per)
ll = [Link](low, per)
dist = hl - ll

f0 = close[per] > close ? hl : ll + dist


f1 = close[per] > close ? hl - dist * 0.236 : ll + dist * 0.786
f2 = close[per] > close ? hl - dist * 0.382 : ll + dist * 0.618
f3 = close[per] > close ? hl - dist * 0.5 : ll + dist * 0.5
f4 = close[per] > close ? hl - dist * 0.618 : ll + dist * 0.382
f5 = close[per] > close ? hl - dist * 0.786 : ll + dist * 0.236
f6 = close[per] > close ? hl - dist : ll

plot(f0, style=plot.style_circles, color=[Link]([Link], 0))


plot(f6, style=plot.style_circles, color=[Link]([Link], 0))

// 0 a 1
plotshape(close[per] > close ? f0 : na, location=[Link],
color=[Link]([Link], 0), text='1', textcolor=[Link]([Link], 0),
style=[Link], show_last=1)
plotshape(close[per] < close ? f0 : na, location=[Link],
color=[Link]([Link], 0), text='0x', textcolor=[Link]([Link], 0),
style=[Link], show_last=1)
plotshape(close[per] > close ? f6 : na, location=[Link],
color=[Link]([Link], 0), text='0', textcolor=[Link]([Link], 0),
style=[Link], show_last=1)
plotshape(close[per] < close ? f6 : na, location=[Link],
color=[Link]([Link], 0), text='1', textcolor=[Link]([Link], 0),
style=[Link], show_last=1)

//0.5
plot(f3, style=plot.style_circles, color=[Link]([Link], 0))
plotshape(f3, location=[Link], color=[Link]([Link], 0),
text='0.5', textcolor=[Link]([Link], 0), style=[Link],
show_last=1)

// .236
plot(close[per] < close ? f1 : na, style=plot.style_circles,
color=[Link]([Link], 0))
plotshape(close[per] < close ? f1 : na, location=[Link],
color=[Link]([Link], 0), text='.236', textcolor=[Link]([Link], 0),
style=[Link], show_last=1)
plot(close[per] > close ? f5 : na, style=plot.style_circles,
color=[Link]([Link], 0))
plotshape(close[per] > close ? f5 : na, location=[Link],
color=[Link]([Link], 0), text='.236', textcolor=[Link]([Link], 0),
style=[Link], show_last=1)

// .382
plot(close[per] < close ? f2 : na, style=plot.style_circles,
color=[Link]([Link], 0))
plotshape(close[per] < close ? f2 : na, location=[Link],
color=[Link]([Link], 0), text='.382', textcolor=[Link]([Link], 0),
style=[Link], show_last=1)
plot(close[per] > close ? f4 : na, style=plot.style_circles,
color=[Link]([Link], 0))
plotshape(close[per] > close ? f4 : na, location=[Link],
color=[Link]([Link], 0), text='.382', textcolor=[Link]([Link], 0),
style=[Link], show_last=1)

// .618
plot(close[per] < close ? f4 : na, style=plot.style_circles,
color=[Link]([Link], 0))
plotshape(close[per] < close ? f4 : na, location=[Link],
color=[Link]([Link], 0), text='.618', textcolor=[Link]([Link], 0),
style=[Link], show_last=1)
plot(close[per] > close ? f2 : na, style=plot.style_circles,
color=[Link]([Link], 0))
plotshape(close[per] > close ? f2 : na, location=[Link],
color=[Link]([Link], 0), text='.618', textcolor=[Link]([Link], 0),
style=[Link], show_last=1)

// .786
plot(close[per] < close ? f5 : na, style=plot.style_circles,
color=[Link]([Link], 0))
plotshape(close[per] < close ? f5 : na, location=[Link],
color=[Link]([Link], 0), text='786', textcolor=[Link]([Link], 0),
style=[Link], show_last=1)
plot(close[per] > close ? f1 : na, style=plot.style_circles,
color=[Link]([Link], 0))
plotshape(close[per] > close ? f1 : na, location=[Link],
color=[Link]([Link], 0), text='.786', textcolor=[Link]([Link], 0),
style=[Link], show_last=1)

You might also like