LNEAS DE TENDENCIA CON BREAKOUTS EN RSI

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #227597 quote
    deletedaccount22102025deletedaccount22102025
    Participant
    New

    Hola a todos,

    he estado buscando un indicador que dibuje las lineas de tendencia y marque los breakouts en un RSI, pero no he encontrado nada en el foro. Conocéis alguno o similar a éste de Tradingview. Podéis transcribirlo a ProRealcode?, porque con mis conocimientos no he podido transcribirlo.

    Gracias

    ————————————————————————–

    // © HoanGhetti
    //@version=5
    indicator(“RSI Trendlines with Breakouts [HG]”, precision = 2, max_labels_count = 500, max_lines_count = 500)
    import HoanGhetti/SimpleTrendlines/3 as tl
    g_trendlines    = ‘Trendline Settings’, g_conditions = ‘Conditions’,  g_styling = ‘Styling’, g_timeframe = ‘Timeframe’
    input_timeframe = input.timeframe(defval = ”, title = ‘Timeframe’, group = g_timeframe)
    input_pLen      = input.int(defval = 4, title = ‘Lookback Range’, minval = 1, group = g_trendlines, tooltip = ‘How many bars to determine when a swing high/low is detected.’)
    input_rLen      = input.int(defval = 14, title = ‘RSI Length’ , minval = 1, group = g_trendlines)
    input_rSrc      = input.source(defval = close, title = ‘RSI Source’, group = g_trendlines)
    input_repaint   = input.string(defval = ‘On’, title = ‘Repainting’, group = g_conditions, options = [‘On’, ‘Off: Bar Confirmation’], tooltip = ‘Bar Confirmation: Generates alerts when candle closes. (1 Candle Later)’)
    input_rsiDiff   = input.int(defval = 3, title = ‘RSI Difference’, group = g_conditions, tooltip = ‘The difference between the current RSI value and the breakout value.\n\nHow much higher in value should the current RSI be compared to the breakout value in order to detect a breakout?’)
    input_rsiCol    = input.color(defval = color.blue, title = ‘RSI Color’, group = g_styling)
    input_width     = input.int(defval = 2, title = ‘Line Width’, minval = 1, group = g_styling)
    input_lblType   = input.string(defval = ‘Simple’, title = ‘Label Type’, group = g_styling, options = [‘Full’, ‘Simple’])
    input_lblSize   = input.string(defval = size.small, title = ‘Label Size’, group = g_styling, options = [size.huge, size.large, size.normal, size.small, size.tiny])
    input_pLowCol   = input.color(defval = color.red, title = ‘Pivot Low’, inline = ‘col’, group = g_styling)
    input_pHighCol  = input.color(defval = #089981, title = ‘Pivot High’, inline = ‘col’, group = g_styling)
    input_override  = input.bool(defval = false, title = ‘Override Text Color’, group = g_styling, inline = ‘override’)
    input_overCol   = input.color(defval = color.white, title = ‘ ‘, group = g_styling, inline = ‘override’)
    lblText = switch input_lblType
        ‘Simple’ => ‘Br’
        ‘Full’   => ‘Break’
    repaint = switch input_repaint
        ‘On’ => true
        ‘Off: Bar Confirmation’ => false
    rsi_v = ta.rsi(input_rSrc, input_rLen)
    rsi = input_timeframe == ” ? rsi_v : request.security(syminfo.tickerid, input_timeframe, rsi_v, lookahead = barmerge.lookahead_on)
    pl = fixnan(ta.pivotlow(rsi, 1, input_pLen))
    ph = fixnan(ta.pivothigh(rsi, 1, input_pLen))
    pivot(float pType) =>
        pivot = pType == pl ? pl : ph
        xAxis = ta.valuewhen(ta.change(pivot), bar_index, 0) – ta.valuewhen(ta.change(pivot), bar_index, 1)
        prevPivot = ta.valuewhen(ta.change(pivot), pivot, 1)
        pivotCond = ta.change(pivot) and (pType == pl ? pivot > prevPivot : pivot < prevPivot)
        pData = tl.new(x_axis = xAxis, offset = input_pLen, strictMode = true, strictType = pType == pl ? 0 : 1)
        pData.drawLine(pivotCond, prevPivot, pivot, rsi)
        pData
    breakout(tl.Trendline this, float pType) =>
        var bool hasCrossed = false
        if ta.change(this.lines.startline.get_y1())
            hasCrossed := false
        this.drawTrendline(not hasCrossed)
        condType = (pType == pl ? rsi < this.lines.trendline.get_y2() – input_rsiDiff : rsi > this.lines.trendline.get_y2() + input_rsiDiff) and not hasCrossed
        condition = repaint ? condType : condType and barstate.isconfirmed
        if condition
            hasCrossed := true
            this.lines.startline.set_xy2(this.lines.trendline.get_x2(), this.lines.trendline.get_y2())
            this.lines.trendline.set_xy2(na, na)
            this.lines.startline.copy()
            label.new(
                 bar_index,
                 this.lines.startline.get_y2(),
                 text=lblText,color=pType==pl?color.new(input_pLowCol,50) :color.new(input_pHighCol,50),
                 size=input_lblSize,style=pType==pl?label.style_label_lower_left:label.style_label_upper_left,
                 textcolor = pType == pl ? (input_override ? input_overCol : input_pLowCol) : input_override ? input_overCol : input_pHighCol)
        hasCrossed
    method style(tl.Trendline this, color col) =>
        this.lines.startline.set_color(col)
        this.lines.startline.set_width(input_width)
        this.lines.trendline.set_color(col)
        this.lines.trendline.set_width(input_width)
        this.lines.trendline.set_style(line.style_dashed)
    plData = pivot(pl)
    phData = pivot(ph)
    plData.style(input_pLowCol)
    phData.style(input_pHighCol)
    cu = breakout(plData, pl)
    co = breakout(phData, ph)
    hline(70, title = ‘Overbought’, color = input_pHighCol, linestyle = hline.style_dotted)
    hline(30, title = ‘Oversold’, color = input_pLowCol, linestyle = hline.style_dotted)
    plot(rsi, title = ‘Relative Strength Index’, linewidth = 2, color = input_rsiCol)
    alertcondition(ta.change(plData.lines.startline.get_y1()), ‘New Pivot Low Trendline’)
    alertcondition(ta.change(cu) and cu, ‘Pivot Low Breakout’)
    alertcondition(ta.change(phData.lines.startline.get_y1()), ‘New Pivot High Trendline’)
    alertcondition(ta.change(co) and co, ‘Pivot High Breakout’)
    US100_2024-02-07_17-33-39.png US100_2024-02-07_17-33-39.png
    #227686 quote
    larouedegannlarouedegann
    Participant
    Master

    holà
    aqui esta el codigo utilizado para cualquier discrepancia en obv rsi macd

    
    //    by Jose Callao
    //    twitter @jose7674
    //
    //N      = 40                      //N is the number of bars to look back for a divergence.
    //                                   Normal values are 20-40. Must be the same in both indicators
    //
    MiRSI  = RSI[14](close)
    Offset = MiRSI * 0.1
    IF (BarIndex > 10+1+N) THEN
    ///divergencia bajista
    IF (miRSI[1]>miRSI AND miRSI[1]>miRSI[2]) THEN
    extremum2=miRSI[1]
    extremum1=highest[N](miRSI)
    preciomax2=close[1]
    preciomax=Highest[N](close)
    IF(extremum2<extremum1 AND preciomax2>preciomax[1]) THEN
    for i=1 to N
    if miRSI[i]=extremum1 then
    zz=i
    drawsegment (barindex[1], miRSI[1]+Offset, barindex[zz], miRSI[zz]+Offset) coloured("RED")STYLE(line,4)
    endif
    next
    endif
    endif
    ///divergencia alcista
    IF (miRSI[1]<miRSI AND miRSI[1]<miRSI[2]) THEN
    extremum22=miRSI[1]
    extremum11=lowest[N](miRSI)
    preciomin2=close[1]
    preciomin=lowest[N](close)
    IF(extremum22>extremum11 AND preciomin2<preciomin[1]) THEN
    for i2=1 to N
    if miRSI[i2]=extremum11[1] then
    zz2=i2
    drawsegment(barindex[1], miRSI[1]-Offset, barindex[zz2], miRSI[zz2]-Offset) coloured("DARKGREEN")STYLE(line,4)
    endif
    next
    ENDIF
    ENDIF
    endif
    return miRSI as "RSI", 50 as "50"
    thanked this post
    #227910 quote
    deletedaccount22102025deletedaccount22102025
    Participant
    New

    Hola larouedegann, muchísimas gracias por responder, pero tu indicador muestra las divergencias no los breakouts tal y cómo muestra la imagen que adjunté.

    Muchas gracias de todos modos

    #228409 quote
    Iván GonzálezIván González
    Moderator
    Legend

    Buenas tardes
    Aquí tienes el indicador mostrando los breakouts del RSI.

    defparam DRAWONLASTBARONLY=false
    ////inputs/////////////////
    BarsAfter = 8
    BarsBefore = 8
    BarLookBack  = BarsAfter + 1
    ////RSI
    myrsi = rsi[14](close)
    /////pivots low
    IF myrsi[BarsAfter] < lowest[BarsBefore](myrsi)[BarLookBack] THEN
    IF myrsi[BarsAfter] = lowest[BarLookBack](myrsi) THEN
    $ply[z]  = myrsi[BarsAfter]
    $plx[z] = barindex-BarsAfter
    z=z+1
    ENDIF
    ENDIF
    /////pivots low line
    //(x-x1)/(x2-x1) = (y-y1)/(y2-y1)
    y2 = $ply[max(z-1,1)]
    x2 = $plx[max(z-1,1)]
    y1 = $ply[max(z-2,1)]
    x1 = $plx[max(z-2,1)]
    xl = barindex
    yl = y1+(xl-x1)*(y2-y1)/(x2-x1)
    //draw line only when rsi is over the line
    if y2 > y1 then
    drawsegment(x1,y1,x2,y2)coloured("red")
    //look for the cross under
    if myrsi crosses under yl then
    drawarrowdown(xl,yl+5)coloured("red")
    drawsegment(x2,y2,xl,yl)style(dottedline,2)coloured("red")
    endif
    endif
    /////pivots high
    if myrsi[Barsafter] > highest[BarsBefore](myrsi)[BarLookBack] THEN
    IF myrsi[BarsAfter] = highest[BarLookBack](myrsi) THEN
    $phy[n]  = myrsi[BarsAfter]
    $phx[n] = barindex-BarsAfter
    n=n+1
    ENDIF
    ENDIF
    /////pivots high line
    ////(x-x1)/(x2-x1) = (y-y1)/(y2-y1)
    y22 = $phy[max(n-1,1)]
    x22 = $phx[max(n-1,1)]
    y11 = $phy[max(n-2,1)]
    x11 = $phx[max(n-2,1)]
    xh = barindex
    yh = y11+(xh-x11)*(y22-y11)/(x22-x11)
    //draw line only when rsi is under the line
    if y22 < y11 then
    drawsegment(x11,y11,x22,y22)coloured("green")
    //look for the cross over
    if myrsi crosses over yh then
    drawarrowup(xh,yh-5)coloured("green")
    drawsegment(x22,y22,xh,yh)style(dottedline,2)coloured("green")
    endif
    endif
    /////////////////////////////
    
    return myrsi as "RSI" coloured(250,250,250)style(line,2)
    
    thanked this post
    #228410 quote
    deletedaccount22102025deletedaccount22102025
    Participant
    New

    Muchas gracias Iván, tremendo trabajo. Magnífico. Esto es lo que buscaba. Mil gracias.

    #228701 quote
    LucasBestLucasBest
    Participant
    Senior

    Agregué dos opciones del código original (repintar y rsiDiff) y simplifiqué el anidamiento de condiciones.

    defparam DRAWONLASTBARONLY=false
    ////inputs/////////////////
    BarLookBack = 8
    repaint = 0
    RSIdiff = 2
    ////RSI
    myrsi = rsi[14](close)
    /////pivots low
    IF myrsi[repaint*BarLookBack+1] = lowest[repaint*BarLookBack+BarLookBack+1](myrsi) THEN
    $ply[z] = myrsi[repaint*BarLookBack+1]
    $plx[z] = barindex-(repaint*BarLookBack+1)
    z=z+1
    ENDIF
    
    /////pivots low line
    //(x-x1)/(x2-x1) = (y-y1)/(y2-y1)
    y2 = $ply[max(z-1,1)]
    x2 = $plx[max(z-1,1)]
    y1 = $ply[max(z-2,1)]
    x1 = $plx[max(z-2,1)]
    xl = barindex
    yl = y1+(xl-x1)*(y2-y1)/(x2-x1)
    //draw line only when rsi is over the line
    if y2 > y1 then
    drawsegment(x1,y1,x2,y2)coloured("red")
    //look for the cross under
    if myrsi crosses under yl-RSIdiff then
    drawarrowdown(xl,yl+5)coloured("red")
    drawsegment(x2,y2,xl,yl)style(dottedline,2)coloured("red")
    endif
    endif
    /////pivots high
    IF myrsi[repaint*BarLookBack+1] = highest[repaint*BarLookBack+BarLookBack+1](myrsi) THEN
    $phy[n] = myrsi[repaint*BarLookBack+1]
    $phx[n] = barindex-(repaint*BarLookBack+1)
    n=n+1
    ENDIF
    
    /////pivots high line
    ////(x-x1)/(x2-x1) = (y-y1)/(y2-y1)
    y22 = $phy[max(n-1,1)]
    x22 = $phx[max(n-1,1)]
    y11 = $phy[max(n-2,1)]
    x11 = $phx[max(n-2,1)]
    xh = barindex
    yh = y11+(xh-x11)*(y22-y11)/(x22-x11)
    //draw line only when rsi is under the line
    if y22 < y11 then
    drawsegment(x11,y11,x22,y22)coloured("green")
    //look for the cross over
    if myrsi crosses over yh+RSIdiff then
    drawarrowup(xh,yh-5)coloured("green")
    drawsegment(x22,y22,xh,yh)style(dottedline,2)coloured("green")
    endif
    endif
    /////////////////////////////
    
    return myrsi as "RSI" coloured("black",255 )style(line,2)
    thanked this post
    #228708 quote
    deletedaccount22102025deletedaccount22102025
    Participant
    New

    Muchas gracias Lucas. Muy buena y práctica la mejora. Saludos.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

LNEAS DE TENDENCIA CON BREAKOUTS EN RSI


ProBuilder: Indicadores y Herramientas

New Reply
Summary

This topic contains 6 replies,
has 4 voices, and was last updated by deletedaccount22102025deletedaccount22102025
2 years, 8 months ago.

Topic Details
Forum: ProBuilder: Indicadores y Herramientas
Language: Spanish
Started: 02/07/2024
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...