ProRealCode - Trading & Coding with ProRealTime™
Please can someone help to convert this indicator. I found it very powerful.
// This work is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International
// https://creativecommons.org/licenses/by-nc-sa/4.0/
// © BigBeluga
//@version=5
indicator("Fibonacci Bands [BigBeluga]", overlay=true, max_lines_count = 500)
// INPUTS ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
int period = input.int(20, title="Period")
float width = input.float(1, title="Width", step = 0.1, minval = 0.5, maxval =3)
float price = input.source(close, title="Source")
bool hide_ch = input.bool(false, "Hide Fibonacci Lines", group = "Fibonacci")
float fibRatio1 = input.float(1.618, title="Fibonacci Ratio 1", step = 0.001)
float fibRatio2 = input.float(2.618, title="Fibonacci Ratio 2", step = 0.001)
float fibRatio3 = input.float(4.236, title="Fibonacci Ratio 3", step = 0.001)
int extend = input.int(30, "Extend Bands", step = 10, minval = 10, maxval = 350)
bool liq_sweep = input.bool(true, "Liquidity Sweep")
color col_top = input.color(#e60060, "top", inline = "c", group = "Color")
color col_bot = input.color(color.lime, "bottom", inline = "c", group = "Color")
var l1 = line(na)
var l2 = line(na)
// }
// CALCULATIONS――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
draw_label(n, y, txt1, txt2)=>
lbl = label.new(n, y, str.tostring(txt1, format.percent) + str.tostring(txt2, " (#.##)"),
color = color(na),
style = label.style_label_left,
textcolor = color.new(chart.fg_color, 10),
text_font_family = font.family_monospace)
label.delete(lbl[1])
smma(src, length) =>
var float smma_value = na
series float sma = ta.sma(src, length)
if na(smma_value[1])
smma_value := sma // Start with SMA for the initial value
else
smma_value := (smma_value[1] * (length - 1) + src) / length // Smooth the value iteratively
smma_value
series float ATR = smma(ta.atr(200), 100)
series float smma = smma(price, period)
// Calculate Fibonacci Levels
series float r1 = ATR * fibRatio1 * width
series float r2 = ATR * fibRatio2 * width
series float r3 = ATR * fibRatio3 * width
// Calculate Fibonacci Bands
series float fibTop1 = smma + r1
series float fibTop2 = smma + r2
series float fibTop3 = smma + r3
series float fibBott1 = smma - r1
series float fibBott2 = smma - r2
series float fibBott3 = smma - r3
int slop_i = math.round(extend/10)
series float slope = (smma-smma[slop_i]) / slop_i
series bool mid_trend = smma > smma[1]
sig_dn = mid_trend and ta.pivothigh(4, 1) and high > fibTop3 and ta.crossunder(high, high[1]) and barstate.isconfirmed
sig_up = not mid_trend and ta.pivotlow(4, 1) and low < fibBott3 and ta.crossover(low, low[1]) and barstate.isconfirmed
// }
// PLOT ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――{
color mid_color= mid_trend ? chart.fg_color : (bar_index % 2 == 0 ? chart.fg_color : na)
color top3_col = color.new(col_top, 50)
color top2_col = color.new(col_top, 50)
color top1_col = color.new(col_top, 80)
color bot3_col = color.new(col_bot, 50)
color bot2_col = color.new(col_bot, 50)
color bot1_col = color.new(col_bot, 80)
display = hide_ch ? display.none : display.all
pt3 = plot(fibTop3, title="Fib Top 3", color=top3_col, linewidth=1, display = display)
pt2 = plot(fibTop2, title="Fib Top 2", color=top2_col, linewidth=1, display = display),
plot(fibTop1, title="Fib Top 1", color=top1_col, linewidth=1, display = display),
plot(smma, title="Middle SMMA", color=mid_color, linewidth=1),
plot(fibBott1, title="Fib Bottom 1", color=bot1_col, linewidth=1, display = display)
pb2 = plot(fibBott2, title="Fib Bottom 2", color=bot2_col, linewidth=1, display = display)
pb3 = plot(fibBott3, title="Fib Bottom 3", color=bot3_col, linewidth=1, display = display)
fill(pt2, pt3, color.new(col_top, 90))
fill(pb2, pb3, color.new(col_bot, 90))
if barstate.islast
int n1 = bar_index
int n2 = bar_index + extend
float ym1 = smma
float ym2 = ym1 + slope * extend
float y11 = fibTop1
float y22 = y11 + slope * extend
float y111 = fibTop2
float y222 = y111 + slope * extend
float y1111 = fibTop3
float y2222 = y1111 + slope * extend
float y_11 = fibBott1
float y_22 = y_11 + slope * extend
float y_111 = fibBott2
float y_222 = y_111 + slope * extend
float y_1111 = fibBott3
float y_2222 = y_1111 + slope * extend
// -------------------
line l_t3 = line.new(n1, y1111, n2, y2222, color = hide_ch ? na : top3_col)
line l_t2 = line.new(n1, y111, n2, y222, color = hide_ch ? na : top2_col)
line l_t1 = line.new(n1, y11, n2, y22, color = hide_ch ? na : top1_col)
line l_m = line.new(n1, ym1, n2, ym2, color = chart.fg_color, style = mid_trend ? line.style_solid : line.style_dashed)
line l_b3 = line.new(n1, y_1111, n2, y_2222, color = hide_ch ? na : bot3_col)
line l_b2 = line.new(n1, y_111, n2, y_222, color = hide_ch ? na : bot2_col)
line l_b1 = line.new(n1, y_11, n2, y_22, color = hide_ch ? na : bot1_col)
linefill.new(l_t3, l_t2, color.new(col_top, 90))
linefill.new(l_b3, l_b2, color.new(col_bot, 90))
// -------------------
style_lbl = label.style_label_left
label.delete(label.new(n2, ym2, str.tostring(ym2, "#.##"), color = color(na), style = style_lbl, textcolor = color.new(chart.fg_color, 40))[1])
if not hide_ch
draw_label(n2, y2222, 100, y2222)
draw_label(n2, y222, 61.80, y222)
draw_label(n2, y22, 38.2, y22)
draw_label(n2, y_22, 38.2, y_22)
draw_label(n2, y_222, 61.80, y_222)
draw_label(n2, y_2222, 100, y_2222)
// --------------------
// -->
line.delete(l_t3[1])
line.delete(l_t2[1])
line.delete(l_t1[1])
line.delete(l_m[1])
line.delete(l_b3[1])
line.delete(l_b2[1])
line.delete(l_b1[1])
if liq_sweep
if sig_dn
l1 := line.new(bar_index-1, high[1], bar_index-1, high[1])
if close < open ? high > l1.get_y2() and open < l1.get_y2() : high > l1.get_y2() and close < l1.get_y2()
l1.set_x2(bar_index)
l1.set_color(chart.fg_color)
l1 := line(na)
if ta.crossover(close, l1.get_y2())
l1 := line(na)
// ----------
if sig_up
l2 := line.new(bar_index-1, low[1], bar_index-1, low[1])
if close < open ? low < l2.get_y2() and close > l2.get_y2() : low < l2.get_y2() and open > l2.get_y2()
l2.set_x2(bar_index)
l2.set_color(chart.fg_color)
l2 := line(na)
if ta.crossunder(close, l2.get_y2())
l2 := line(na)
plotchar(sig_dn, "Signal Down", "∘", location.abovebar, col_top, size = size.tiny)
plotchar(sig_up, "Signal Up", "•", location.belowbar, col_bot, size = size.small)
// }
Hi. Here you have the code.
If you want see signals and sweeps just comment first line and Extension block.
defparam drawonlastbaronly=true
//---------------------------------------------//
//PRC_Fibonacci + bands
//version = 0
//01.07.24
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//---------------------------------------------//
//-----Inputs
//---------------------------------------------//
period=20
width=1
fibratio1=1.618
fibratio2=2.618
fibratio3=4.236
extend=30
//---------------------------------------------//
//------ Calculate fibonacci bands
//---------------------------------------------//
// Calculate ATR
myatr=averagetruerange[200]
src1=myatr
length1=100
sma1=average[length1](src1)
if barindex<=300 then
atr=sma1
else
atr=(atr*(length1-1)+src1)/length1
endif
// Calculate SMMA
src=close
sma=average[period](src)
if barindex<=period then
smma=sma
else
smma=(smma*(period-1)+src)/period
endif
midTrend1=smma
midTrend2=smma
if close>=smma then
a1=255
a2=0
else
a1=0
a2=255
endif
// Calculate Fibonacci levels
lev1=atr*fibratio1*width
lev2=atr*fibratio2*width
lev3=atr*fibratio3*width
// Calculate Fibonacci bands
fibtop1=smma+lev1
fibtop2=smma+lev2
fibtop3=smma+lev3
fibbot1=smma-lev1
fibbot2=smma-lev2
fibbot3=smma-lev3
colorbetween(fibtop2,fibtop3,"red",45)
colorbetween(fibbot2,fibbot3,"green",45)
//---------------------------------------------//
//------ Calculate liquidation sweep
//---------------------------------------------//
leftbars=4
rightbars=1
// Pivots low
src1 = low
if src1 > src1[rightbars] and lowest[rightbars](src1) >= src1[rightbars] and src1[rightbars] < lowest[leftbars](src1)[rightbars+1] then
z=z+1
endif
// Pivot high
src2 = high
if src2 < src2[rightbars] and highest[rightbars](src2)<=src2[rightbars] and src2[rightbars]>highest[leftbars](src2)[rightbars+1] then
t=t+1
endif
// Calculate signal Up and Down
midtrend=smma>smma[1]
signDn = midtrend and t<>t[1] and high>fibtop3 and high crosses under high[1]
signUp = midtrend=0 and z<>z[1] and low<fibbot3 and low crosses over low[1]
if signDn then
drawpoint(barindex,high+myatr,2)coloured("red")
hx1=barindex[1]
hy1=high[1]
checksweepDn=1
elsif signUp then
drawpoint(barindex,low-myatr,2)coloured("green")
lx1=barindex[1]
ly1=low[1]
checksweepUp=1
endif
if checksweepDn then
if close<open and high>hy1 and open<hy1 then
hx2=barindex
drawsegment(hx1,hy1,hx2,hy1)
checksweepDn=0
elsif close>=open and high>hy1 and close<hy1 then
hx2=barindex
checksweepDn=0
drawsegment(hx1,hy1,hx2,hy1)
endif
endif
if checksweepUp then
if close<open and low<ly1 and close>ly1 then
lx2=barindex
drawsegment(lx1,ly1,lx2,ly1)
checksweepUp=0
elsif close>=open and low<ly1 and open>ly1 then
lx2=barindex
checksweepUp=0
drawsegment(lx1,ly1,lx2,ly1)
endif
endif
//---------------------------------------------//
//------ Calculate Extension
//---------------------------------------------//
slopi=round(extend/10)
slope=(smma-smma[slopi])/slopi
if islastbarupdate then
n1=barindex
n2=n1+extend
ym1=smma
ym2=ym1+slope*extend
drawsegment(n1,ym1,n2,ym2)
drawtext("0.0% (#ym2#)",n2+7,ym2)
y11=fibtop1
y22=y11+slope*extend
drawsegment(n1,y11,n2,y22)coloured("red",80)
drawtext("38.20% (#y22#)",n2+7,y22)
y111=fibtop2
y222=y111+slope*extend
drawsegment(n1,y111,n2,y222)coloured("red",155)
drawtext("61.80% (#y222#)",n2+7,y222)
y1111=fibtop3
y2222=y1111+slope*extend
drawsegment(n1,y1111,n2,y2222)coloured("red",155)
drawtext("100.00% (#y2222#)",n2+7,y2222)
yb11=fibbot1
yb22=yb11+slope*extend
drawsegment(n1,yb11,n2,yb22)coloured("green",80)
drawtext("38.20% (#yb22#)",n2+7,yb22)
yb111=fibbot2
yb222=yb111+slope*extend
drawsegment(n1,yb111,n2,yb222)coloured("green",155)
drawtext("61.80% (#yb222#)",n2+7,yb222)
yb1111=fibbot3
yb2222=yb1111+slope*extend
drawsegment(n1,yb1111,n2,yb2222)coloured("green",155)
drawtext("100.00% (#yb2222#)",n2+7,yb2222)
endif
//---------------------------------------------//
return midTrend1 style(line)coloured("black",a1),midTrend2 style(dottedline)coloured("black",a2), fibtop1 coloured("red",80),fibtop2 coloured("red",155),fibtop3 coloured("red",155), fibbot1 coloured("green",80), fibbot2 coloured("green",155), fibbot3 coloured("green",155)
Ivan this is great thanks you so much.
Sorry please can you clarify what you mean by “just comment first line and Extension block.?” What do I need to change?
Hi.
Comment line means write // at the beggining of each line you want to hide.
Here you have the code to show signals and sweeps:
//defparam drawonlastbaronly=true
//---------------------------------------------//
//PRC_Fibonacci bands
//version = 0
//01.07.24
//Iván González @ www.prorealcode.com
//Sharing ProRealTime knowledge
//---------------------------------------------//
//-----Inputs
//---------------------------------------------//
period=20
width=1
fibratio1=1.618
fibratio2=2.618
fibratio3=4.236
extend=30
//---------------------------------------------//
//------ Calculate fibonacci bands
//---------------------------------------------//
// Calculate ATR
myatr=averagetruerange[200]
src1=myatr
length1=100
sma1=average[length1](src1)
if barindex<=300 then
atr=sma1
else
atr=(atr*(length1-1)+src1)/length1
endif
// Calculate SMMA
src=close
sma=average[period](src)
if barindex<=period then
smma=sma
else
smma=(smma*(period-1)+src)/period
endif
midTrend1=smma
midTrend2=smma
if close>=smma then
a1=255
a2=0
else
a1=0
a2=255
endif
// Calculate Fibonacci levels
lev1=atr*fibratio1*width
lev2=atr*fibratio2*width
lev3=atr*fibratio3*width
// Calculate Fibonacci bands
fibtop1=smma+lev1
fibtop2=smma+lev2
fibtop3=smma+lev3
fibbot1=smma-lev1
fibbot2=smma-lev2
fibbot3=smma-lev3
colorbetween(fibtop2,fibtop3,"red",45)
colorbetween(fibbot2,fibbot3,"green",45)
//---------------------------------------------//
//------ Calculate liquidation sweep
//---------------------------------------------//
leftbars=4
rightbars=1
// Pivots low
src1 = low
if src1 > src1[rightbars] and lowest[rightbars](src1) >= src1[rightbars] and src1[rightbars] < lowest[leftbars](src1)[rightbars+1] then
z=z+1
endif
// Pivot high
src2 = high
if src2 < src2[rightbars] and highest[rightbars](src2)<=src2[rightbars] and src2[rightbars]>highest[leftbars](src2)[rightbars+1] then
t=t+1
endif
// Calculate signal Up and Down
midtrend=smma>smma[1]
signDn = midtrend and t<>t[1] and high>fibtop3 and high crosses under high[1]
signUp = midtrend=0 and z<>z[1] and low<fibbot3 and low crosses over low[1]
if signDn then
drawpoint(barindex,high+myatr,2)coloured("red")
hx1=barindex[1]
hy1=high[1]
checksweepDn=1
elsif signUp then
drawpoint(barindex,low-myatr,2)coloured("green")
lx1=barindex[1]
ly1=low[1]
checksweepUp=1
endif
if checksweepDn then
if close<open and high>hy1 and open<hy1 then
hx2=barindex
drawsegment(hx1,hy1,hx2,hy1)
checksweepDn=0
elsif close>=open and high>hy1 and close<hy1 then
hx2=barindex
checksweepDn=0
drawsegment(hx1,hy1,hx2,hy1)
endif
endif
if checksweepUp then
if close<open and low<ly1 and close>ly1 then
lx2=barindex
drawsegment(lx1,ly1,lx2,ly1)
checksweepUp=0
elsif close>=open and low<ly1 and open>ly1 then
lx2=barindex
checksweepUp=0
drawsegment(lx1,ly1,lx2,ly1)
endif
endif
//---------------------------------------------//
//------ Calculate Extension
//---------------------------------------------//
//slopi=round(extend/10)
//slope=(smma-smma[slopi])/slopi
//
//if islastbarupdate then
//n1=barindex
//n2=n1+extend
//
//ym1=smma
//ym2=ym1+slope*extend
//drawsegment(n1,ym1,n2,ym2)
//drawtext("0.0% (#ym2#)",n2+7,ym2)
//
//y11=fibtop1
//y22=y11+slope*extend
//drawsegment(n1,y11,n2,y22)coloured("red",80)
//drawtext("38.20% (#y22#)",n2+7,y22)
//
//y111=fibtop2
//y222=y111+slope*extend
//drawsegment(n1,y111,n2,y222)coloured("red",155)
//drawtext("61.80% (#y222#)",n2+7,y222)
//
//y1111=fibtop3
//y2222=y1111+slope*extend
//drawsegment(n1,y1111,n2,y2222)coloured("red",155)
//drawtext("100.00% (#y2222#)",n2+7,y2222)
//
//yb11=fibbot1
//yb22=yb11+slope*extend
//drawsegment(n1,yb11,n2,yb22)coloured("green",80)
//drawtext("38.20% (#yb22#)",n2+7,yb22)
//
//yb111=fibbot2
//yb222=yb111+slope*extend
//drawsegment(n1,yb111,n2,yb222)coloured("green",155)
//drawtext("61.80% (#yb222#)",n2+7,yb222)
//
//yb1111=fibbot3
//yb2222=yb1111+slope*extend
//drawsegment(n1,yb1111,n2,yb2222)coloured("green",155)
//drawtext("100.00% (#yb2222#)",n2+7,yb2222)
//endif
//---------------------------------------------//
return midTrend1 style(line)coloured("black",a1),midTrend2 style(dottedline)coloured("black",a2), fibtop1 coloured("red",80),fibtop2 coloured("red",155),fibtop3 coloured("red",155), fibbot1 coloured("green",80), fibbot2 coloured("green",155), fibbot3 coloured("green",155)
Fibonacci Bands [BigBeluga] – Conversion
This topic contains 3 replies,
has 2 voices, and was last updated by
Iván González
7 months, 1 week ago.
| Forum: | ProBuilder: Indicators & Custom Tools |
| Language: | English |
| Started: | 06/25/2025 |
| Status: | Active |
| Attachments: | No files |
The information collected on this form is stored in a computer file by ProRealCode to create and access your ProRealCode profile. This data is kept in a secure database for the duration of the member's membership. They will be kept as long as you use our services and will be automatically deleted after 3 years of inactivity. Your personal data is used to create your private profile on ProRealCode. This data is maintained by SAS ProRealCode, 407 rue Freycinet, 59151 Arleux, France. If you subscribe to our newsletters, your email address is provided to our service provider "MailChimp" located in the United States, with whom we have signed a confidentiality agreement. This company is also compliant with the EU/Swiss Privacy Shield, and the GDPR. For any request for correction or deletion concerning your data, you can directly contact the ProRealCode team by email at privacy@prorealcode.com If you would like to lodge a complaint regarding the use of your personal data, you can contact your data protection supervisory authority.