CONVERSION INDICADOR TRADINGVIEW:”Trend Lines “

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #240137 quote
    Fr7
    Participant
    Master

    Solicito, 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 = false

    var 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-length

    upper += 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-length

    lower += 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)

    //—————————————————————————–}

    #240301 quote
    Iván González
    Moderator
    Master

    Buenas! Aún me falta pulirlo un poco pero ya se parece bastante.

    defparam drawonlastbaronly=true
    //----------------------------------------------//
    //PRC_Trend Lines
    //version = 0
    //13.11.2024
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //----------------------------------------------//
    // Inputs
    //----------------------------------------------//
    length=50
    ratio=3
    anglA=0.1
    anglB=90
    ShowA=1
    showpivot=1
    //----------------------------------------------//
    // Calculations
    //----------------------------------------------//
    n=barindex
    //Pivots low
    src1 = low
    if src1 > src1[length] and lowest[length](src1) > src1[length] and src1[length] < lowest[length](src1)[length+1] then
    pl=src1[length]
    $pl[z+1] = src1[length]
    $plidx[z+1] = barindex[length]
    z=z+1
    
    endif
    //Pivots high
    src2 = high
    if src2 < src2[length] and highest[length](src2)<src2[length] and src2[length]>highest[length](src2)[length+1] then
    ph=src2[length]
    $ph[t+1]=src2[length]
    $phidx[t+1]=barindex[length]
    t=t+1
    
    endif
    
    bars=500
    height=bars/ratio
    Xaxis=min(max(1,n),bars)
    Yaxis=highest[Xaxis](high)-lowest[Xaxis](low)
    
    //----------------------------------------------//
    // Execution
    //----------------------------------------------//
    
    if t>0 and islastbarupdate then
    for i=t downto 3 do
    if $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/diffYh
    normalisedSlopeh=(height/diffYtoYaxish)/diffXh
    slopeh=diffYh/diffXh
    angleh=round((atan(normalisedSlopeh)),2)
    //(x-x1)/(x2-x1) = (y-y1)/(y2-y1)
    upperx1=$phidx[i-1]+length
    upper1=$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]+length
    upper2=$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 then
    drawtext("#angleh#",$phidx[i-2],$ph[i-2])coloured("red")
    endif
    endif
    drawpoint($phidx[i],$ph[i],2)coloured("red",100*showpivot)
    next
    endif
    
    if z>0 and islastbarupdate then
    for i=z downto 3 do
    if $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/diffYl
    normalisedSlopel=(height/diffYtoYaxisl)/diffXl
    slopel=diffYl/diffXl
    anglel=round((atan(normalisedSlopel)),2)
    //(x-x1)/(x2-x1) = (y-y1)/(y2-y1)
    //y = y1+(x-x1)*(y2-y1)/(x2-x1)
    lowerx=$plidx[i]+length
    lower=$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 then
    drawtext("#anglel#",$plidx[i-1],$pl[i-1])coloured("blue")
    endif
    endif
    drawpoint($plidx[i],$pl[i],2)coloured("blue",100*showpivot)
    next
    endif
    //----------------------------------------------//
    return
    Fr7 thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

CONVERSION INDICADOR TRADINGVIEW:”Trend Lines “


ProBuilder: Indicadores y Herramientas

New Reply
Author
author-avatar
Fr7 @fr7 Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Iván González
1 year, 3 months ago.

Topic Details
Forum: ProBuilder: Indicadores y Herramientas
Language: Spanish
Started: 11/08/2024
Status: Active
Attachments: No files
Logo Logo
Loading...