Conversion Lineas de Tendencia y Rupturas de Pivote HG

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #255260 quote
    MaricarmenMaricarmen
    Participant
    Veteran

    Buenas Tardes:

    Se podría hacer la conversión de este indicador.

    Muchas gracias.

    // This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/

    // © HoanGhetti

    //@version=5

    indicator(“Pivot Trendlines with Breaks [HG]”, overlay = true, max_lines_count = 500)

    import HoanGhetti/SimpleTrendlines/4 as tl

    input_len       = input.int(defval = 20, title = ‘Pivot Length’, minval = 1)

    input_pivotType = input.string(defval = ‘Normal’, title = ‘Pivot Type’, options = [‘Normal’, ‘Fast’], tooltip = ‘Normal: Uses Pine\’s built-in pivot system.\n\nFast: Uses a custom pivot system that tracks every reversal.’)

    input_repaint   = input.bool(defval = true, title = ‘Repainting’, tooltip = ‘If disabled, it will wait for bar confirmation to avoid printing false alerts.’)

    input_targets   = input.bool(defval = false, title = ‘Target Levels’)

    input_bearC     = input.color(defval = color.red, title = ‘Bear Breakout’, group = ‘Styling’)

    input_bullC     = input.color(defval = color.green, title = ‘Bull Breakout’, group = ‘Styling’)

    input_extend    = input.string(defval = extend.none, title = ‘Extend’, options = [extend.none, extend.right, extend.left, extend.both], group = ‘Styling’)

    input_style     = input.string(defval = line.style_dotted, title = ‘Trendline Style’, options = [line.style_dotted, line.style_dashed, line.style_solid], group = ‘Styling’)

    input_tstyle    = input.string(defval = line.style_dashed, title = ‘Target Style’, options = [line.style_dotted, line.style_dashed, line.style_solid], group = ‘Styling’)

    input_override  = input.bool(defval = false, title = ‘Override Source’, group = ‘Override’, tooltip = ‘Overriding the source will allow the script to create trendlines on any specified source.’)

    input_useSrc    = input.bool(defval = true, title = ‘Use Source for Cross Detection’, group = ‘Override’, tooltip = ‘Instead of checking if the close value crossed trendline, check for the specified source.’)

    input_source    = input.source(defval = low, title = ‘Source’, group = ‘Override’)

    pl = fixnan(ta.pivotlow(input_override ? input_source : low, input_pivotType == ‘Normal’ ? input_len : 1, input_len))

    ph = fixnan(ta.pivothigh(input_override ? input_source : high, input_pivotType == ‘Normal’ ? input_len : 1, input_len))

    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_len, strictMode = true, strictType = pType == pl ? 0 : 1)

        pData.drawLine(pivotCond, prevPivot, pivot, input_override ? input_source : na)

        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)

        confirmation = not hasCrossed and (input_repaint ? not hasCrossed : barstate.isconfirmed)

        if (pType == pl ? (input_override and input_useSrc ? input_source : close) < this.lines.trendline.get_y2() : (input_override and input_useSrc ? input_source : close) > this.lines.trendline.get_y2()) and confirmation

            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()

        hasCrossed

    plData = pivot(pl)

    phData = pivot(ph)

    style(tl.Trendline this, color col) =>

        this.lines.startline.set_color(col), this.lines.trendline.set_color(col)

        this.lines.startline.set_width(2), this.lines.trendline.set_width(2)

        this.lines.trendline.set_style(input_style), this.lines.trendline.set_extend(input_extend)

    style(plData, input_bearC), style(phData, input_bullC)

    cu = breakout(plData, pl)

    co = breakout(phData, ph)

    plotshape(ta.change(cu) and cu ? plData.lines.startline.get_y2() : na, title = ‘Bearish Breakout’, style = shape.labeldown, color = input_bearC, textcolor = color.white, location = location.absolute, text = ‘Br’)

    plotshape(ta.change(co) and co ? phData.lines.startline.get_y2() : na, title = ‘Bullish Breakout’, style = shape.labelup, color = input_bullC, textcolor = color.white, location = location.absolute, text = ‘Br’)

    alertcondition(ta.change(cu) and cu, ‘Bearish Breakout’)

    alertcondition(ta.change(co) and co, ‘Bullish Breakout’)

    // Target Levels [v4 Update]

    phData_target = tl.new(phData.values.changeInX)

    plData_target = tl.new(plData.values.changeInX)

    phData_target.drawLine(ta.change(phData.values.y1) and input_targets, phData.values.y2, phData.values.y2)

    plData_target.drawLine(ta.change(plData.values.y1) and input_targets, plData.values.y2, plData.values.y2)

    target_style(tl.Trendline this, color col) =>

        this.lines.startline.set_style(input_tstyle)

        this.lines.trendline.set_style(input_tstyle)

        this.lines.startline.set_color(col)

        this.lines.trendline.set_color(col)

    target_style(plData_target, input_bearC)

    target_style(phData_target, input_bullC)

    breakout(phData_target, ph)

    breakout(plData_target, pl)

    #255265 quote
    Iván GonzálezIván González
    Moderator
    Legend
    Buenas. Aquí tienes el indicador:
    //--------------------------------------------------//
    //PRC_Pivot Trendlines with Breaks [HG]
    //version = 0
    //14.01.2026
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //--------------------------------------------------//
    // --- Inputs ---
    //--------------------------------------------------//
    pivotLen = 20
    pivotType = 1 //(1 for Wicks, 0 for Body)
    maxLines = 20 //(Limits how many historical lines are drawn to keep chart clean)
    showOldBrokenLines = 1 //(Boolean: 1 to see history, 0 for clean chart)
    //--------------------------------------------------//
    // --- Initialization ---
    //--------------------------------------------------//
    leftBars = pivotLen
    rightBars = MAX(1, ROUND(pivotLen / 2))
    
    IF pivotType = 1 THEN
       srcLo = low
       srcHi = high
    ELSE
       srcLo = MIN(open, close)
       srcHi = MAX(open, close)
    ENDIF
    //--------------------------------------------------//
    // --- Pivot Detection and Array Storage ---
    //--------------------------------------------------//
    IF srcLo > srcLo[rightBars] AND LOWEST[rightBars](srcLo) > srcLo[rightBars] AND srcLo[rightBars] < LOWEST[leftBars](srcLo)[rightBars + 1] THEN
       $PLy[z] = srcLo[rightBars]
       $PLx[z] = barindex[rightBars]
       IF z > 0 THEN
          IF $PLy[z] > $PLy[z-1] THEN
             $slopeL[z] = ($PLy[z] - $PLy[z-1]) / ($PLx[z] - $PLx[z-1])
          ELSE
             $slopeL[z] = 0
          ENDIF
       ENDIF
       z = z + 1
    ENDIF
    
    IF srcHi < srcHi[rightBars] AND HIGHEST[rightBars](srcHi) < srcHi[rightBars] AND srcHi[rightBars] > HIGHEST[leftBars](srcHi)[rightBars + 1] THEN
       $PHy[t] = srcHi[rightBars]
       $PHx[t] = barindex[rightBars]
       IF t > 0 THEN
          IF $PHy[t] < $PHy[t-1] THEN
             $slopeH[t] = ($PHy[t] - $PHy[t-1]) / ($PHx[t] - $PHx[t-1])
          ELSE
             $slopeH[t] = 0
          ENDIF
       ENDIF
       t = t + 1
    ENDIF
    //--------------------------------------------------//
    // --- Drawing Logic on Last Bar ---
    //--------------------------------------------------//
    IF ISLASTBARUPDATE THEN
       
       // Limit the loop to the last N lines to match TradingView's cleanliness
       startLoopH = MAX(1, t - maxLines)
       startLoopL = MAX(1, z - maxLines)
       
       // Resistance Lines (Bearish)
       IF t > 2 THEN
          FOR i = t - 1 DOWNTO startLoopH DO
             IF $slopeH[i] <> 0 THEN
                x1 = $PHx[i-1]
                y1 = $PHy[i-1]
                m = $slopeH[i]
                
                breakX = 0
                breakY = 0
                
                FOR j = $PHx[i] + 1 TO barindex DO
                   valLine = y1 + (j - x1) * m
                   IF close[barindex - j] > valLine THEN
                      breakX = j
                      breakY = valLine
                      BREAK
                   ENDIF
                NEXT
                
                IF breakX = 0 THEN
                   // Active line
                   yEnd = y1 + (barindex - x1) * m
                   DRAWSEGMENT(x1, y1, barindex, yEnd) STYLE(dottedline, 2) COLOURED(255, 0, 0)
                ELSE
                   // Broken line: only draw if the user wants to see history
                   IF showOldBrokenLines THEN
                      DRAWSEGMENT(x1, y1, breakX, breakY) COLOURED(150, 0, 0, 150) // More transparent
                      DRAWTEXT("Br", breakX, breakY + range, Dialog, Bold, 10) COLOURED(255, 0, 0)
                   ENDIF
                ENDIF
             ENDIF
          NEXT
       ENDIF
       
       // Support Lines (Bullish)
       IF z > 2 THEN
          FOR i = z - 1 DOWNTO startLoopL DO
             IF $slopeL[i] <> 0 THEN
                x1 = $PLx[i-1]
                y1 = $PLy[i-1]
                m = $slopeL[i]
                
                breakX = 0
                breakY = 0
                
                FOR j = $PLx[i] + 1 TO barindex DO
                   valLine = y1 + (j - x1) * m
                   IF close[barindex - j] < valLine THEN
                      breakX = j
                      breakY = valLine
                      BREAK
                   ENDIF
                NEXT
                
                IF breakX = 0 THEN
                   // Active line
                   yEnd = y1 + (barindex - x1) * m
                   DRAWSEGMENT(x1, y1, barindex, yEnd) STYLE(dottedline, 2) COLOURED(0, 255, 0)
                ELSE
                   // Broken line
                   IF showOldBrokenLines THEN
                      DRAWSEGMENT(x1, y1, breakX, breakY) COLOURED(0, 150, 0, 150)
                      DRAWTEXT("Br", breakX, breakY - range, Dialog, Bold, 10) COLOURED(0, 200, 0)
                   ENDIF
                ENDIF
             ENDIF
          NEXT
       ENDIF
       
    ENDIF
    
    RETURN
    
    Maricarmen thanked this post
Viewing 2 posts - 1 through 2 (of 2 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

TradingView to ProRealTime Translation Center

New Reply
Author
author-avatar
Maricarmen @maricarmen Participant
Summary

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

Topic Details
Forum: TradingView to ProRealTime Translation Center Forum
Started: 01/13/2026
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...