CONVERSION INDICADOR TRADINGVIEW:”Trend Lines “
Forums › ProRealTime foro Español › Soporte ProBuilder › CONVERSION INDICADOR TRADINGVIEW:”Trend Lines “
- This topic has 1 reply, 2 voices, and was last updated 11 months ago by Iván. 
- 
	
		
- 
		
			
				
11/08/2024 at 2:10 PM #240137Solicito, si es posible, convertir el indicador adjunto:https://www.tradingview.com/script/vE8YNVgM-Trend-Lines-LuxAlgo/ El indicador “Líneas de tendencia” detecta y resalta las líneas de tendencia relevantes en el gráfico del usuario, al mismo tiempo que lo mantiene libre de desorden en la medida de lo posible. El indicador está pensado para su uso en tiempo real e incluye varios filtros, así como la capacidad de estimar los ángulos de las líneas de tendencia. A ver si Iván el moderador tiene un hueco libre y lo puede traducir. 
 Muchas gracias.// This work is licensed under a Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) https://creativecommons.org/licenses/by-nc-sa/4.0/ 
 // © LuxAlgo//@version=5 
 indicator(“Trend Lines [LuxAlgo]”, shorttitle= “LuxAlgo – Trend Lines”, max_lines_count = 500, max_labels_count = 500, overlay = true)//—————————————————————————— 
 //Settings
 //—————————————————————————–{
 NN = “Disabled”
 AB = “Point A – Point B”
 AC = “Point A – Current bar”
 length = input.int ( 50 , minval = 2 , group= “Swings” )
 toggle = input.string( NN , ‘Check breaks between:’ , options= [ AB, AC, NN ] , group= “Trendline validation” )
 source = input.string( “close” , ‘source (breaks)’ , options= [“close”, “H/L”] , group= “Trendline validation” )
 count = input.int ( 3 , ‘Minimal bars’ , minval = 0 , group= “Trendline breaks”
 , tooltip= ‘Uninterrupted Trendline for at least x bars’)
 showA = input.bool ( true , ‘show Angles’ , group= “Angles” )
 ratio = input.float ( 3 , ‘Ratio X-Y axis’ , step =0.1 , group= “Angles” )
 anglA = input.float ( 0.1 ,’Only Trendlines between:’, minval =0.1, inline= ‘angle’, group= “Angles” )
 anglB = input.float ( 90 , ‘ – ‘ , minval =0.1, inline= ‘angle’, group= “Angles” )
 upCss = input.color (#2962ff, ‘Up’ , group= “Colours” )
 dnCss = input.color (#f23645, ‘Down’ , group= “Colours” )//—————————————————————————–} 
 //Variables
 //—————————————————————————–{
 //Downtrendline
 var int phx1 = na
 var float phslope = na
 var float phy1 = na
 var float upper = na
 var float plotH = na
 var bool isOnH = false//Uptrendline 
 var int plx1 = na
 var float plslope = na
 var float ply1 = na
 var float lower = na
 var float plotL = na
 var bool isOnL = falsevar line testLine = line.new(na, na, na, na, color=color.new(color.blue, 100)) //—————————————————————————–} 
 //Calculations
 //—————————————————————————–{
 n = bar_index
 bg = chart.bg_color
 fg = chart.fg_color
 ph = ta.pivothigh (length, length)
 pl = ta.pivotlow (length, length)
 bars = 500 , height = bars / ratio
 Xaxis = math.min(math.max(1, n), bars)
 Yaxis = ta.highest(Xaxis) – ta.lowest(Xaxis)
 srcBl = source == “close” ? close : high
 srcBr = source == “close” ? close : low//—————————————————————————–} 
 //Function
 //—————————————————————————–{
 calculate_slope(x1, x2, y1, y2) =>
 diffX = x2 – x1, diffY = y2 – y1
 diffY_to_Yaxis = Yaxis / diffY
 normalised_slope = (height / diffY_to_Yaxis) / diffX
 slope = diffY / diffX
 angle = math.round(math.atan(normalised_slope) * 180 / math.pi, 2)
 [normalised_slope, slope, angle]//—————————————————————————–} 
 //Execution
 //—————————————————————————–{
 if not na(ph)
 if ph < phy1
 [normalised_slope, slope, angle]= calculate_slope(phx1, n-length, phy1, ph)
 testLine.set_xy1(phx1, phy1), testLine.set_xy2(n, ph + slope * length)
 src = source == “close” ? close : high, max_bars_back(src, 2000)
 isOnH := false
 broken = false
 if math.abs(angle) > anglA and math.abs(angle) < anglB
 if toggle != NN
 for i = (toggle == AB ? length : 0) to n – phx1
 if src[i] > testLine.get_price(n – i)
 broken := true
 break
 if not broken
 phslope := slope, isOnH := true, upper := ph + slope * length
 line.new(phx1, phy1, n, ph + slope * length
 , color= dnCss, style= line.style_dotted)
 if showA
 label.new(phx1, phy1, text= str.tostring(angle)
 , style = label.style_label_down
 , color = color.new(bg, 100)
 , textcolor = dnCss)phy1 := ph 
 phx1 := n-lengthupper += phslope 
 plotH := not na(ph) and ta.change(phslope) ? na : srcBl[1] > upper[1] ? na : upper
 bs_H = ta.barssince (na(plotH ))if not na(pl) 
 if pl > ply1
 [normalised_slope, slope, angle]= calculate_slope(plx1, n-length, ply1, pl)
 testLine.set_xy1(plx1, ply1), testLine.set_xy2(n, pl + slope * length)
 src = source == “close” ? close : low , max_bars_back(src, 2000)
 isOnL := false
 broken = false
 if angle > anglA and angle < anglB
 if toggle != NN
 for i = (toggle == AB ? length : 0) to n – plx1
 if src[i] < testLine.get_price(n – i)
 broken := true
 break
 if not broken
 plslope := slope, isOnL := true, lower := pl + slope * length
 line.new(plx1, ply1, n, pl + slope * length
 , color= upCss, style= line.style_dotted)
 if showA
 label.new(plx1, ply1, text= str.tostring(angle)
 , style = label.style_label_up
 , color = color.new(bg, 100)
 , textcolor = upCss)ply1 := pl 
 plx1 := n-lengthlower += plslope 
 plotL := not na(pl) and ta.change(plslope) ? na : srcBr[1] < lower[1] ? na : lower
 bs_L = ta.barssince (na(plotL ))//—————————————————————————–} 
 //Plots
 //—————————————————————————–{
 plot(plotH, ‘Down Trendline’
 , dnCss
 , 1
 , plot.style_linebr)plot(plotL, ‘Up Trendline’ 
 , upCss
 , 1
 , plot.style_linebr)plotshape( 
 bs_H > count and srcBl > upper and srcBl[1] <= upper[1]
 , ‘Bullish break’
 , shape.labelup
 , location.belowbar
 , dnCss
 , size = size.tiny)plotshape( 
 bs_L > count and srcBr < lower and srcBr[1] >= lower[1]
 , ‘Bearish break’
 , shape.labeldown
 , location.abovebar
 , upCss
 , size = size.tiny)//—————————————————————————–} 11/13/2024 at 9:29 AM #240301Buenas! Aún me falta pulirlo un poco pero ya se parece bastante. 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697defparam drawonlastbaronly=true//----------------------------------------------////PRC_Trend Lines//version = 0//13.11.2024//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge//----------------------------------------------//// Inputs//----------------------------------------------//length=50ratio=3anglA=0.1anglB=90ShowA=1showpivot=1//----------------------------------------------//// Calculations//----------------------------------------------//n=barindex//Pivots lowsrc1 = lowif src1 > src1[length] and lowest[length](src1) > src1[length] and src1[length] < lowest[length](src1)[length+1] thenpl=src1[length]$pl[z+1] = src1[length]$plidx[z+1] = barindex[length]z=z+1endif//Pivots highsrc2 = highif src2 < src2[length] and highest[length](src2)<src2[length] and src2[length]>highest[length](src2)[length+1] thenph=src2[length]$ph[t+1]=src2[length]$phidx[t+1]=barindex[length]t=t+1endifbars=500height=bars/ratioXaxis=min(max(1,n),bars)Yaxis=highest[Xaxis](high)-lowest[Xaxis](low)//----------------------------------------------//// Execution//----------------------------------------------//if t>0 and islastbarupdate thenfor i=t downto 3 doif $ph[i-1]<$ph[i-2] then//Calculate slope (x1=phx1,x2=n-length,y1=phy1,y2=ph)diffXh=$phidx[i-1]-$phidx[i-2]diffYh=$ph[i-1]-$ph[i-2]diffYtoYaxish=Yaxis/diffYhnormalisedSlopeh=(height/diffYtoYaxish)/diffXhslopeh=diffYh/diffXhangleh=round((atan(normalisedSlopeh)),2)//(x-x1)/(x2-x1) = (y-y1)/(y2-y1)upperx1=$phidx[i-1]+lengthupper1=$ph[i-2]+(upperx1-$phidx[i-2])*($ph[i-1]-$ph[i-2])/($phidx[i-1]-$phidx[i-2])drawsegment($phidx[i-2],$ph[i-2],upperx1,upper1)style(dottedline)coloured("red")upperx2=$phidx[i]+lengthupper2=$ph[i-2]+(upperx2-$phidx[i-2])*($ph[i-1]-$ph[i-2])/($phidx[i-1]-$phidx[i-2])drawsegment(upperx2,upper2,upperx1,upper1)style(line)coloured("red")if showA thendrawtext("#angleh#",$phidx[i-2],$ph[i-2])coloured("red")endifendifdrawpoint($phidx[i],$ph[i],2)coloured("red",100*showpivot)nextendifif z>0 and islastbarupdate thenfor i=z downto 3 doif $pl[i]>$pl[i-1] then//Calculate slope (x1=phx1,x2=n-length,y1=phy1,y2=ph)diffXl=$plidx[i]-$plidx[i-1]diffYl=$pl[i]-$pl[i-1]diffYtoYaxisl=Yaxis/diffYlnormalisedSlopel=(height/diffYtoYaxisl)/diffXlslopel=diffYl/diffXlanglel=round((atan(normalisedSlopel)),2)//(x-x1)/(x2-x1) = (y-y1)/(y2-y1)//y = y1+(x-x1)*(y2-y1)/(x2-x1)lowerx=$plidx[i]+lengthlower=$pl[i-1]+(lowerx-$plidx[i-1])*($pl[i]-$pl[i-1])/($plidx[i]-$plidx[i-1])drawsegment($plidx[i-1],$pl[i-1],lowerx,lower)style(dottedline)coloured("blue")if showA thendrawtext("#anglel#",$plidx[i-1],$pl[i-1])coloured("blue")endifendifdrawpoint($plidx[i],$pl[i],2)coloured("blue",100*showpivot)nextendif//----------------------------------------------//return1 user thanked author for this post.
- 
		AuthorPosts
			Find exclusive trading pro-tools on 


 
		 
		 
		