Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
- // © djmad
- //@version=5
- indicator('[MAD] Fib retracement', overlay=true)
- int Starttime = input.time(timestamp("2020-02-19"),title= "B O T T O M - L E F T", inline="B O T T O M - L E F T", confirm = true,group='Line 1')
- var Bottom = input.price(defval=100, title= "B O T T O M L E F T", inline="B O T T O M - L E F T", confirm = true,group='Line 1')
- var Top = input.price(defval=100, title='T O P',confirm = true)
- var decimals_price = input.int(2,"Price decimals",group="decimals trimming",inline="1")
- var decimals_percent = input.int(2,"Percent decimals",group="decimals trimming",inline="1")
- channels = array.from(
- input.float(1.0 ,"Level",group="Fiblevels",step=0.001)
- ,input.float(0.786 ,"Level",group="Fiblevels",step=0.001)
- ,input.float(0.65 ,"Level",group="Fiblevels",step=0.001)
- ,input.float(0.618 ,"Levea",group="Fiblevels",step=0.001)
- ,input.float(0.5 ,"Level",group="Fiblevels",step=0.001)
- ,input.float(0.382 ,"Level",group="Fiblevels",step=0.001)
- ,input.float(0.35 ,"Level",group="Fiblevels",step=0.001)
- ,input.float(0.236 ,"Level",group="Fiblevels",step=0.001)
- ,input.float(0.0 ,"Level",group="Fiblevels",step=0.001)
- )
- textcolor1=input.color(color.white,"Textcolor")
- size1=input.string(size.tiny,options = [size.tiny,size.small,size.normal,size.large])
- linearray = array.new_line(0,na)
- f_round(_val, decimals) =>
- // Rounds _val to _decimals places.
- _p = math.pow(10, decimals)
- math.round(math.abs(_val) * _p) / _p * math.sign(_val)
- f_fibcalc(Top, Bottom, channels) =>
- output = array.new<float>()
- Diff = Top-Bottom
- for i = 0 to array.size(channels) -1
- array.push(output, Bottom + Diff * array.get(channels,i))
- output
- output = f_fibcalc(Top,Bottom, channels)
- cleareverything() =>
- a_allLines = line.all
- if array.size(a_allLines) > 0
- for i = 0 to array.size(a_allLines) - 1
- line.delete(array.get(a_allLines, i))
- a_allLabel = label.all
- if array.size(a_allLabel) > 0
- for i = 0 to array.size(a_allLabel) - 1
- label.delete(array.get(a_allLabel, i))
- a_allFills = linefill.all
- if array.size(a_allFills) > 0
- for i = 0 to array.size(a_allFills) - 1
- linefill.delete(array.get(a_allFills, i))
- drawout() =>
- for i = 0 to array.size(channels)-1
- line line1 = na
- linefill fill1 = na
- label label1 = na
- label label2 = na
- line1 := line.new(x1= Starttime, y1= array.get(output,i),x2 = time, y2 = array.get(output,i), xloc=xloc.bar_time, style=line.style_solid, extend=extend.right,color=input.color(color.white,"Linecolor"))
- array.insert(linearray,i,line1)
- if i == 1
- fill1 := linefill.new(array.get(linearray,0),array.get(linearray,1),color=input.color(color.rgb(175, 76, 76, 60),"Fill-Color"))
- if i == 3
- fill1 := linefill.new(array.get(linearray,2),array.get(linearray,3),color=input.color(color.rgb(175, 172, 76, 60),"Fill-Color"))
- if i == 6
- fill1 := linefill.new(array.get(linearray,5),array.get(linearray,6),color=input.color(color.rgb(175, 172, 76, 60),"Fill-Color"))
- if i == 8
- fill1 := linefill.new(array.get(linearray,7),array.get(linearray,8),color=input.color(color.rgb(76, 175, 79, 60),"Fill-Color"))
- label1 := label.new(x=time <= chart.right_visible_bar_time?time:chart.right_visible_bar_time, y= array.get(output,i),
- text = time <= chart.right_visible_bar_time?
- " " + str.tostring(array.get(channels,i)) + ' (' + str.tostring(f_round(array.get(output,i),decimals_price)) + ') ' + str.tostring(f_round(array.get(output,i)/close*100-100,decimals_percent)) + '% = ' + str.tostring(f_round(array.get(output,i)-close,decimals_price)) :
- "" + str.tostring(array.get(channels,i)) + ' (' + str.tostring(f_round(array.get(output,i),decimals_price)) + ') ',
- xloc=xloc.bar_time,
- yloc=yloc.price,
- color=color.white,
- style=label.style_none,
- textcolor=textcolor1,
- size=size1,
- textalign=text.align_left)
- if i == 8
- label2 := label.new(x=time <= chart.right_visible_bar_time?time:chart.right_visible_bar_time, y= array.get(output,i),
- text = time <= chart.right_visible_bar_time?
- " Range-Up = " + str.tostring(f_round(array.get(output,0)/array.get(output,8)*100-100,decimals_percent)) + '%\n Range-Down = ' + str.tostring(f_round(array.get(output,8)/array.get(output,0)*100-100,decimals_percent)) + '%\n':
- "",
- xloc=xloc.bar_time,
- yloc=yloc.price,
- color=color.white,
- style=label.style_none,
- textcolor=textcolor1,
- size=size1,
- textalign=text.align_left)
- cleareverything()
- drawout()
Advertisement
Add Comment
Please, Sign In to add comment