Confluencia de Fibonacci

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #256963 quote
    Maricarmen
    Participant
    Junior

    Se podría hacer un Screener para este indicador de LuxAlgo..

    https://www.tradingview.com/script/c8yi95fx-Fibonacci-Confluence-Toolkit-LuxAlgo/

    Gracias,

    #256965 quote
    Nicolas
    Keymaster
    Master

    ¿Podrías publicar el código del indicador para que podamos analizar su conversión y luego el código de su filtro derivado? Gracias por la ayuda.

    #256989 quote
    Maricarmen
    Participant
    Junior

    Este es el Código.

    // 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(“Fibonacci Confluence Toolkit [LuxAlgo]”, ‘LuxAlgo – Fibonacci Confluence Toolkit’, true, max_labels_count = 500, max_boxes_count = 500, max_lines_count = 500)

    //———————————————————————————————————————

    // Settings 

    //———————————————————————————————————————{


    display = display.all – display.status_line


    ltGroup = ‘Market Patterns’

    bullCHoCHs = input(true, ‘Bullish Structures’, inline = ‘MS’, group = ltGroup)

    ltBullMSColor = input.color(#089981, ”, group = ltGroup, inline = ‘MS’), ltBullMSColor := bullCHoCHs ? ltBullMSColor : chart.bg_color

    bearCHoCHs = input(true, ‘Bearish Structures’, inline = ‘MS1’, group = ltGroup)

    ltBearMSColor = input.color(#f23645, ”, group = ltGroup, inline = ‘MS1’), ltBearMSColor := bearCHoCHs ? ltBearMSColor : chart.bg_color


    areaOfInt = input.string(‘Enabled’, ‘Highlight Area of Interest’, options = [‘Enabled’, ‘Disabled’], group = ltGroup, display = display)

    ltMSLineStyle = input.string(‘Solid’, ‘CHoCH Line’, options = [‘Solid’, ‘Dashed’, ‘Dotted’], group = ltGroup, inline = ‘LN’, display = display)

    ltMSLineWidth = input.int(2, ‘Width’, minval = 1, group = ltGroup, inline = ‘LN’, display = display)


    group_fib = ‘Retracement Levels’


    show_0 = input.bool(true, ”, inline=’Level0′, group = group_fib)

    value_0 = input.float(0, ”, inline=’Level0′, group = group_fib, display = display)


    show_0_236 = input.bool(false, ”, inline=’Level0′, group = group_fib)

    value_0_236 = input.float(0.236, ”, inline=’Level0′, group = group_fib, display = display)


    show_0_382 = input.bool(true, ”, inline=’Level1′, group = group_fib)

    value_0_382 = input.float(0.382, ”, inline=’Level1′, group = group_fib, display = display)


    show_0_5 = input.bool(true, ”, inline=’Level1′, group = group_fib)

    value_0_5 = input.float(0.5, ”, inline=’Level1′, group = group_fib, display = display)


    show_0_618 = input.bool(true, ”, inline=’Level2′, group = group_fib)

    value_0_618 = input.float(0.618, ”, inline=’Level2′, group = group_fib, display = display)


    show_0_65 = input.bool(false, ”, inline=’Level2′, group = group_fib)

    value_0_65 = input.float(0.65, ”, inline=’Level2′, group = group_fib, display = display)


    show_0_786 = input.bool(true, ”, inline=’Level3′, group = group_fib)

    value_0_786 = input.float(0.786, ”, inline=’Level3′, group = group_fib, display = display)


    show_1 = input.bool(true, ”, inline=’Level3′, group = group_fib)

    value_1 = input.float(1, ”, inline=’Level3′, group = group_fib, display = display)


    sweGroup = ‘Swing Levels & Engulfing Patterns’

    ltSwings = input.string(‘Disabled’, ‘Swing Levels’, options = [‘◉’, ‘△▽’, ‘H/L’, ‘Disabled’], inline = ‘NA’, group = sweGroup, display = display)

    ltSwingsSZ = input.string(‘Tiny’, ‘Size’, options = [‘Tiny’, ‘Small’, ‘Normal’, ‘Large’], inline = ‘NA’, group = sweGroup, display = display)

    engulf = input.string(‘Structure Based’, ‘Engulfing Candle Patterns’, options = [‘All’, ‘Structure Based’, ‘Disabled’], inline = ‘NA1’, group = sweGroup, display = display)

    engulfSZ = input.string(‘Tiny’, ”, options = [‘Tiny’, ‘Small’, ‘Normal’, ‘Large’], inline = ‘NA1’, group = sweGroup, display = display)


    //———————————————————————————————————————}

    // User Defined Types

    //———————————————————————————————————————{


    type BAR

      float  open = open

      float  high = high

      float  low  = low

      float  close = close

      int   index = bar_index


    type ICTMS

      float  lastPrice

      float  midPrice

      float  prevPrice


      int   lastIndex

      int   midIndex

      int   prevIndex


      label  lastLabel

      label  midLabel

      label  prevLabel


      bool  isCrossed

      bool  isCHoCH

      bool  measure


      int   marketStructure


      float  lwest 

      float  hghst

      line  msLine

      box   msLabel

      box   zone


    type MS

      int lastType = 0

      int prevType = 0


    type FIB

      line lnRef

      line ln0

      line ln0_236

      line ln0_382

      line ln0_5

      line ln0_618

      line ln0_65

      line ln0_786

      line ln1


      label lb0

      label lb0_236

      label lb0_382

      label lb0_5

      label lb0_618

      label lb0_65

      label lb0_786

      label lb1

    //———————————————————————————————————————}

    // Generic Variables

    //———————————————————————————————————————{


    BAR bar = BAR.new()


    var ICTMS stLow = ICTMS.new()

    var ICTMS stHigh = ICTMS.new()


    var ICTMS itLow = ICTMS.new()

    var ICTMS itHigh = ICTMS.new()


    var ICTMS ltLow = ICTMS.new()

    var ICTMS ltHigh = ICTMS.new()

    var MS ltMS = MS.new()


    var FIB bullFibs = FIB.new()

    var FIB bearFibs = FIB.new()


    //———————————————————————————————————————}

    // Functions / Methods

    //———————————————————————————————————————{


    textSize(sizeInText) =>

      switch sizeInText

        ‘Tiny’  => size.tiny

        ‘Small’ => size.small

        ‘Normal’ => size.normal

        => size.large


    lineStyle(styleInText) =>

      switch styleInText

        ‘Solid’   => line.style_solid

        ‘Dotted’  => line.style_dotted

        ‘Dashed’  => line.style_dashed


    queryPatterns(lastPrice, midPrice, prevPrice, isSwingHigh) =>

      if isSwingHigh

        prevPrice < midPrice and midPrice >= lastPrice

      else

        prevPrice > midPrice and midPrice <= lastPrice


    method queryPatterns(ICTMS this, isSwingHigh) =>

      if isSwingHigh

        this.prevPrice < this.midPrice and this.midPrice >= this.lastPrice

      else

        this.prevPrice > this.midPrice and this.midPrice <= this.lastPrice


    method updatePattern(ICTMS this, price, index) =>

      this.isCrossed := false

      this.prevPrice := this.midPrice, this.midPrice := this.lastPrice, this.lastPrice := price

      this.prevIndex := this.midIndex, this.midIndex := this.lastIndex, this.lastIndex := index

      this.prevLabel := this.midLabel, this.midLabel := this.lastLabel


    method setType(MS this, value) =>

      this.prevType := this.lastType

      this.lastType := value


    method renderStructures(ICTMS this, isBullish, marketStructure, color, style, width) =>


      condition = isBullish ? bar.close > this.lastPrice : bar.close < this.lastPrice


      if condition and not this.isCrossed

        this.isCrossed := true


        if marketStructure.lastType == (isBullish ? -1 : 1)

          this.isCHoCH := true

          this.measure := false


          this.msLine := line.new(this.lastIndex, this.lastPrice, bar.index, this.lastPrice, color = color, style = lineStyle(style), width = width)


          float refValue = isBullish ? bar.low : bar.high

          int  refIndex = bar.index


          [value, index] = if isBullish

            for i = 1 to (bar.index – this.lastIndex)

              if low[i] < refValue

                refValue := low[i]

                refIndex := bar_index[i]

            [refValue, refIndex]

          else

            for i = 1 to (bar.index – this.lastIndex)

              if high[i] > refValue

                refValue := high[i]

                refIndex := bar_index[i]

            [refValue, refIndex]


          if isBullish

            bullFibs.ln1 := line.new(index, value, bar.index, value, color = color(na))

            bullFibs.lb1 := label.new(bar.index, value, ‘1 · ‘ + str.tostring(value, format.mintick), color = color(na), style = label.style_label_left, textcolor = color(na), size = size.small, tooltip = ‘1 · ‘ + str.tostring(value, format.mintick))

          else

            bearFibs.ln1 := line.new(index, value, bar.index, value, color = color(na))

            bearFibs.lb1 := label.new(bar.index, value, ‘1 · ‘ + str.tostring(value, format.mintick), color = color(na), style = label.style_label_left, textcolor = color(na), size = size.small, tooltip = ‘1 · ‘ + str.tostring(value, format.mintick))


          this.lwest := isBullish ? value : bar.low

          this.hghst := isBullish ? bar.high : value

          this.zone := box.new(bar.index, isBullish ? this.lastPrice : value, bar.index + 1, isBullish ? value : this.lastPrice, color(na), bgcolor = areaOfInt == ‘Enabled’ ? color.new(color, 89) : color(na))


          this.msLabel := box.new(this.lastIndex, this.lastPrice, bar.index, this.lastPrice, color(na), bgcolor = color(na), 

           text = ‘CHoCH’, text_size = size.tiny, text_halign = text.align_left, text_valign = isBullish ? text.align_bottom : text.align_top, text_color = color.new(color, 17))

        else

          this.isCHoCH := false


        marketStructure.setType(isBullish ? 1 : -1)

        true

      else

        if this.isCHoCH

          if (isBullish ? bar.low > this.lwest : bar.high < this.hghst)

            this.zone.set_right(bar_index + 1)

          else

            this.isCHoCH := false

        true


    method manageFibs(FIB this, render, isBullish, rHighI, rHighV, rLowI, rLowV, color) =>


      if render

        rnage = math.abs(rHighV – rLowV)

        m = (rHighV – rLowV) / (rHighI – rLowI)

        b = rLowV – m * rLowI


        if show_1 or show_0_786 or show_0_65 or show_0_618 or show_0_5 or show_0_382 or show_0_236 or show_0

          this.lnRef := line.new(rLowI, rLowV, rHighI, rHighV, color = color, style = lineStyle(‘Dashed’))

        if show_1

          this.ln1.set_color(color), this.ln1.set_x2(bar.index + 1), this.lb1.set_x(bar.index + 1)//, this.lb1.set_textcolor(color)

        if show_0_786

          value = isBullish ? rHighV – rnage * value_0_786 : rLowV + rnage * value_0_786

          this.ln0_786 := line.new(math.ceil((value – b)/ m), value, bar.index + 1, value, color = color, style = lineStyle(‘Dotted’))

          this.lb0_786 := label.new(bar.index + 1, value, str.tostring(value_0_786) + ‘ · ‘ + str.tostring(value, format.mintick), color = color(na), style = label.style_label_left, textcolor = color(na), size = size.small, tooltip = str.tostring(value_0_786) + ‘ · ‘ + str.tostring(value, format.mintick))

        if show_0_65

          value = isBullish ? rHighV – rnage * value_0_65 : rLowV + rnage * value_0_65

          this.ln0_65 := line.new(math.ceil((value – b)/ m), value, bar.index + 1, value, color = color, style = lineStyle(‘Dotted’))

          this.lb0_65 := label.new(bar.index + 1, value, str.tostring(value_0_65) + ‘ · ‘ + str.tostring(value, format.mintick), color = color(na), style = label.style_label_left, textcolor = color(na), size = size.small, tooltip = str.tostring(value_0_65) + ‘ · ‘ + str.tostring(value, format.mintick))

        if show_0_618

          value = isBullish ? rHighV – rnage * value_0_618 : rLowV + rnage * value_0_618

          this.ln0_618 := line.new(math.ceil((value – b)/ m), value, bar.index + 1, value, color = color, style = lineStyle(‘Dotted’))

          this.lb0_618 := label.new(bar.index + 1, value, str.tostring(value_0_618) + ‘ · ‘ + str.tostring(value, format.mintick), color = color(na), style = label.style_label_left, textcolor = color(na), size = size.small, tooltip = str.tostring(value_0_618) + ‘ · ‘ + str.tostring(value, format.mintick))

        if show_0_5

          value = isBullish ? rHighV – rnage * value_0_5 : rLowV + rnage * value_0_5

          this.ln0_5 := line.new(math.ceil((value – b)/ m), value, bar.index + 1, value, color = color, style = lineStyle(‘Dotted’))

          this.lb0_5 := label.new(bar.index + 1, value, str.tostring(value_0_5) + ‘ · ‘ + str.tostring(value, format.mintick), color = color(na), style = label.style_label_left, textcolor = color(na), size = size.small, tooltip = str.tostring(value_0_5) + ‘ · ‘ + str.tostring(value, format.mintick))

        if show_0_382

          value = isBullish ? rHighV – rnage * value_0_382 : rLowV + rnage * value_0_382

          this.ln0_382 := line.new(math.ceil((value – b)/ m), value, bar.index + 1, value, color = color, style = lineStyle(‘Dotted’))

          this.lb0_382 := label.new(bar.index + 1, value, str.tostring(value_0_382) + ‘ · ‘ + str.tostring(value, format.mintick), color = color(na), style = label.style_label_left, textcolor = color(na), size = size.small, tooltip = str.tostring(value_0_382) + ‘ · ‘ + str.tostring(value, format.mintick))

        if show_0_236

          value = isBullish ? rHighV – rnage * value_0_236 : rLowV + rnage * value_0_236

          this.ln0_236 := line.new(math.ceil((value – b)/ m), value, bar.index + 1, value, color = color, style = lineStyle(‘Dotted’))

          this.lb0_236 := label.new(bar.index + 1, value, str.tostring(value_0_236) + ‘ · ‘ + str.tostring(value, format.mintick), color = color(na), style = label.style_label_left, textcolor = color(na), size = size.small, tooltip = str.tostring(value_0_236) + ‘ · ‘ + str.tostring(value, format.mintick))

        if show_0

          value = isBullish ? rHighV : rLowV

          this.ln0 := line.new(isBullish ? rHighI : rLowI, value, bar.index + 1, value, color = color, style = lineStyle(‘Solid’))

          this.lb0 := label.new(bar.index + 1, value, str.tostring(value_0) + ‘ · ‘ + str.tostring(value, format.mintick), color = color(na), style = label.style_label_left, textcolor = color(na), size = size.small, tooltip = str.tostring(value_0) + ‘ · ‘ + str.tostring(value, format.mintick))

        true

      else

        if show_1

          this.ln1.set_x2(bar.index + 1), this.lb1.set_x(bar.index + 1)

        if show_0_786

          this.ln0_786.set_x2(bar.index + 1), this.lb0_786.set_x(bar.index + 1)

        if show_0_65

          this.ln0_65.set_x2(bar.index + 1), this.lb0_65.set_x(bar.index + 1)

        if show_0_618

          this.ln0_618.set_x2(bar.index + 1), this.lb0_618.set_x(bar.index + 1)

        if show_0_5

          this.ln0_5.set_x2(bar.index + 1), this.lb0_5.set_x(bar.index + 1)

        if show_0_382

          this.ln0_382.set_x2(bar.index + 1), this.lb0_382.set_x(bar.index + 1)

        if show_0_236

          this.ln0_236.set_x2(bar.index + 1), this.lb0_236.set_x(bar.index + 1)

        if show_0

          this.ln0.set_x2(bar.index + 1), this.lb0.set_x(bar.index + 1)

        true

    //———————————————————————————————————————}

    // Calculations – ICT Short Term Market Structures 

    //———————————————————————————————————————{


    if queryPatterns(bar.low, bar.low[1], bar.low[2], false)

      stLow.updatePattern(bar.low[1], bar.index[1])

      stLow.lastLabel := label.new(stLow.lastIndex, stLow.lastPrice, ‘⦁’, color = color(na), textcolor = color(na), style = label.style_label_up)


    if queryPatterns(bar.high, bar.high[1], bar.high[2], true)

      stHigh.updatePattern(bar.high[1], bar.index[1])

      stHigh.lastLabel := label.new(bar.index[1], bar.high[1], ‘⦁’, color = color(na), textcolor = color(na), style = label.style_label_down)


    //———————————————————————————————————————}

    // Calculations – ICT Intermediate Term Market Structures 

    //———————————————————————————————————————{


    cITL = stLow.queryPatterns(false) 


    if cITL and cITL != cITL[1]

      itLow.updatePattern(stLow.midPrice, stLow.midIndex)

      itLow.lastLabel := stLow.midLabel


    cITH = stHigh.queryPatterns(true) 


    if cITH and cITH != cITH[1]

      itHigh.updatePattern(stHigh.midPrice, stHigh.midIndex)

      itHigh.lastLabel := stHigh.midLabel


    //———————————————————————————————————————}

    // Calculations – ICT Long Term Market Structures 

    //———————————————————————————————————————{


    cLTL = itLow.queryPatterns(false)


    if cLTL and cLTL != cLTL[1]

      ltLow.isCrossed := false


      if ltMS.lastType == -1 and ltMS.prevType != ltMS.lastType and not ltLow.measure// 

        ltLow.measure := true

        bearFibs.manageFibs(true, false, bearFibs.ln1.get_x1(), ltLow.zone.get_top(), itLow.midIndex, itLow.midPrice , ltBearMSColor)


      TX = ltSwings == ‘△▽’ ? ‘△’ : ltSwings == ‘◉’ ? ‘◉’ : ltLow.lastPrice > itLow.midPrice ? ‘LL’ : ‘LH’


      ltLow.lastPrice := itLow.midPrice

      ltLow.lastIndex := itLow.midIndex


      if ltSwings != ‘Disabled’

        itLow.midLabel.set_text(TX)

        itLow.midLabel.set_size(textSize(ltSwingsSZ))

        itLow.midLabel.set_textcolor(ltBearMSColor)


    if ltLow.isCHoCH and ltLow.measure

      if bar.high < ltLow.hghst

        bearFibs.manageFibs(false, false, 0, 0., 0, 0., color(na))


    cLTH = itHigh.queryPatterns(true)


    if cLTH and cLTH != cLTH[1]

      ltHigh.isCrossed := false


      if ltMS.lastType == 1 and ltMS.prevType != ltMS.lastType and not ltHigh.measure// 

        ltHigh.measure := true

        bullFibs.manageFibs(true, true, itHigh.midIndex, itHigh.midPrice, bullFibs.ln1.get_x1(), ltHigh.zone.get_bottom(), ltBullMSColor)


      TX = ltSwings == ‘△▽’ ? ‘▽’ : ltSwings == ‘◉’ ? ‘◉’ : ltHigh.lastPrice > itHigh.midPrice ? ‘HL’ : ‘HH’


      ltHigh.lastPrice := itHigh.midPrice

      ltHigh.lastIndex := itHigh.midIndex


      if ltSwings != ‘Disabled’

        itHigh.midLabel.set_text(TX)

        itHigh.midLabel.set_size(textSize(ltSwingsSZ))

        itHigh.midLabel.set_textcolor(ltBullMSColor)


    if ltHigh.isCHoCH and ltHigh.measure

      if bar.low > ltHigh.lwest

        bullFibs.manageFibs(false, true, 0, 0., 0, 0., color(na))


    ltLow.renderStructures(false, ltMS, ltBearMSColor, ltMSLineStyle, ltMSLineWidth)

    ltHigh.renderStructures(true, ltMS, ltBullMSColor, ltMSLineStyle, ltMSLineWidth)


    C_DownTrend = engulf == ‘Disabled’ ? false : true

    C_UpTrend = engulf == ‘Disabled’ ? false : true

    C_Len = 14

    C_BodyHi = math.max(close, open)

    C_BodyLo = math.min(close, open)

    C_Body = C_BodyHi – C_BodyLo

    C_BodyAvg = ta.ema(C_Body, C_Len)

    C_SmallBody = C_Body < C_BodyAvg

    C_LongBody = C_Body > C_BodyAvg

    C_WhiteBody = open < close

    C_BlackBody = open > close


    C_EngulfingBearish = C_UpTrend and C_BlackBody and C_LongBody and C_WhiteBody[1] and C_SmallBody[1] and close <= open[1] and open >= close[1] and ( close < open[1] or open > close[1] )


    if C_EngulfingBearish and (engulf == ‘All’ ? true : ltLow.isCHoCH and ltLow.measure and bar.close > ltLow.zone.get_bottom())

      var ttBearishEngulfing = “A bearish engulfing pattern is a two-candle reversal pattern that often signals a potential shift from an uptrend to a downtrend.”

      label.new(bar.index, bar.high, ‘▼’, color = color(na), textcolor = ltBearMSColor, style = label.style_label_down, tooltip = ttBearishEngulfing, size = textSize(engulfSZ))


    C_EngulfingBullish = C_DownTrend and C_WhiteBody and C_LongBody and C_BlackBody[1] and C_SmallBody[1] and close >= open[1] and open <= close[1] and ( close > open[1] or open < close[1] )


    if C_EngulfingBullish and (engulf == ‘All’ ? true : ltHigh.isCHoCH and ltHigh.measure and bar.close < ltHigh.zone.get_top())

      var ttBullishEngulfing = “A bullish engulfing pattern is a two-candle reversal pattern that typically signals a potential shift from a downtrend to an uptrend in price.”

      label.new(bar.index, bar.low, ‘▲’, color = color(na), textcolor = ltBullMSColor, style=label.style_label_up, tooltip = ttBullishEngulfing, size = textSize(engulfSZ))


    //———————————————————————————————————————}

    #256990 quote
    Iván González
    Moderator
    Master

    ok, miraré primero si se puede convertir a prorealtime y luego vemos lo del screener

    Maricarmen thanked this post
    #257011 quote
    Maricarmen
    Participant
    Junior

    Gracias, espero los puedas realizar

    #257078 quote
    Iván González
    Moderator
    Master

    Buenas. Te puedo pasar el código del indicador.

    //------------------------------------------------
    // PRC_Fibonacci Confluence Toolkit (by LuxAlgo)
    // version = 1
    // 29.01.2026
    // Iván González @ www.prorealcode.com
    //------------------------------------------------
    defparam drawonlastbaronly=true
    //------------------------------------------------
    //----- Inputs -----
    //------------------------------------------------
    // Market Patterns
    bullCHoCHs = 1          // 1=mostrar, 0=ocultar
    bearCHoCHs = 1          // 1=mostrar, 0=ocultar
    // Retracement Levels (1=show, 0=hide)
    show0 = 1
    value0 = 0
    show0236 = 1
    value0236 = 0.236
    show0382 = 1
    value0382 = 0.382
    show05 = 1
    value05 = 0.5
    show0618 = 1
    value0618 = 0.618
    show0786 = 1
    value0786 = 0.786
    show1 = 1
    value1 = 1
    // Swing Levels & Engulfing
    showSwings = 1          // 1=HH/HL/LH/LL, 0=disabled
    showHLSwings = 1        // Strong/Weak High/Low
    engulfMode = 2          // 0=disabled, 1=all, 2=structure based
    //------------------------------------------------
    // Generic Variables
    //------------------------------------------------
    n = barindex
    atr = averagetruerange[14](close)
    // Market Structure state
    once ltMS = 0
    once ltMSPrev = 0
    //------------------------------------------------
    // Short Term Swings Detection (1 bar lookback)
    //------------------------------------------------
    // ST High: high[1] es mayor que sus vecinos
    stHighDetected = high[1] > high and high[1] > high[2]
    // ST Low: low[1] es menor que sus vecinos
    stLowDetected = low[1] < low and low[1] < low[2]
    // Actualizar estado ST High
    if stHighDetected then
       stHPrevPrice = stHMidPrice
       stHMidPrice = stHLastPrice
       stHLastPrice = high[1]
       stHPrevIndex = stHMidIndex
       stHMidIndex = stHLastIndex
       stHLastIndex = n - 1
    endif
    // Actualizar estado ST Low
    if stLowDetected then
       stLPrevPrice = stLMidPrice
       stLMidPrice = stLLastPrice
       stLLastPrice = low[1]
       stLPrevIndex = stLMidIndex
       stLMidIndex = stLLastIndex
       stLLastIndex = n - 1
    endif
    //------------------------------------------------
    // Intermediate Term Swings (based on ST patterns)
    //------------------------------------------------
    // IT Low: patrón swing low en ST (prev > mid <= last)
    itLowPattern = stLPrevPrice > stLMidPrice and stLMidPrice <= stLLastPrice and stLMidPrice > 0
    // Detectar nuevo IT Low
    if itLowPattern and itLowPattern <> itLowPattern[1] then
       itLPrevPrice = itLMidPrice
       itLMidPrice = itLLastPrice
       itLLastPrice = stLMidPrice
       itLPrevIndex = itLMidIndex
       itLMidIndex = itLLastIndex
       itLLastIndex = stLMidIndex
    endif
    // IT High: patrón swing high en ST (prev < mid >= last)
    itHighPattern = stHPrevPrice < stHMidPrice and stHMidPrice >= stHLastPrice and stHMidPrice > 0
    // Detectar nuevo IT High
    if itHighPattern and itHighPattern <> itHighPattern[1] then
       itHPrevPrice = itHMidPrice
       itHMidPrice = itHLastPrice
       itHLastPrice = stHMidPrice
       itHPrevIndex = itHMidIndex
       itHMidIndex = itHLastIndex
       itHLastIndex = stHMidIndex
    endif
    //------------------------------------------------
    // Long Term Swings (based on IT patterns) + CHoCH Detection
    //------------------------------------------------
    // LT Low: patrón swing low en IT
    ltLowPattern = itLPrevPrice > itLMidPrice and itLMidPrice <= itLLastPrice and itLMidPrice > 0
    // Detectar nuevo LT Low
    if ltLowPattern and ltLowPattern <> ltLowPattern[1] then
       ltLLastPrice = itLMidPrice
       ltLLastIndex = itLMidIndex
       ltLCross = 0
       // Si estructura bajista activa y midiendo, activar Fibs
       if ltMS = -1 and ltMSPrev <> ltMS and ltLMeasure = 0 then
          ltLMeasure = 1
          bearFibActive = 1
          bearFibHighIndex = bearFibLn1X
          bearFibHighPrice = ltLZoneTop
          bearFibLowIndex = itLMidIndex
          bearFibLowPrice = itLMidPrice
       endif
    endif
    // LT High: patron swing high en IT
    ltHighPattern = itHPrevPrice < itHMidPrice and itHMidPrice >= itHLastPrice and itHMidPrice > 0
    // Detectar nuevo LT High
    if ltHighPattern and ltHighPattern <> ltHighPattern[1] then
       ltHLastPrice = itHMidPrice
       ltHLastIndex = itHMidIndex
       ltHCross = 0
       // Si estructura alcista activa y midiendo, activar Fibs
       if ltMS = 1 and ltMSPrev <> ltMS and ltHMeasure = 0 then
          ltHMeasure = 1
          bullFibActive = 1
          bullFibHighIndex = itHMidIndex
          bullFibHighPrice = itHMidPrice
          bullFibLowIndex = bullFibLn1X
          bullFibLowPrice = ltHZoneBot
       endif
    endif
    //------------------------------------------------
    // Bearish CHoCH Detection (close crosses under ltLLastPrice)
    //------------------------------------------------
    if close crosses under ltLLastPrice and ltLCross = 0 and ltLLastPrice > 0 then
       ltLCross = 1
       if ltMS = 1 then
          // CHoCH bajista detectado (cambio de alcista a bajista)
          ltLisCHoCH = 1
          ltLMeasure = 0
          // Guardar datos del CHoCH
          bearChochX = ltLLastIndex
          bearChochY = ltLLastPrice
          bearChochRight = n
          bearChochActive = 1
          // Buscar el máximo entre el swing y la ruptura para Area of Interest
          refValue = high
          refIndex = n
          for i = 1 to (n - ltLLastIndex) do
             if high[i] > refValue then
                refValue = high[i]
                refIndex = n - i
             endif
          next
          // Guardar para Fib nivel 1
          bearFibLn1X = refIndex
          bearFibLn1Y = refValue
          // Zone coordinates
          ltLZoneTop = refValue
          ltLZoneBot = ltLLastPrice
          ltLZoneLeft = n
          ltLZoneRight = n + 1
          ltLwest = low
          ltLhghst = refValue
       else
          ltLisCHoCH = 0
       endif
       ltMSPrev = ltMS
       ltMS = -1
    endif
    // Extender zona si sigue activa
    if ltLisCHoCH = 1 and ltLMeasure = 0 then
       if high < ltLhghst then
          ltLZoneRight = n + 1
       else
          ltLisCHoCH = 0
       endif
    endif
    //--------------------------------------------------------------------------------//
    // Bullish CHoCH Detection (close crosses over ltHLastPrice)
    //--------------------------------------------------------------------------------//
    if close crosses over ltHLastPrice and ltHCross = 0 and ltHLastPrice > 0 then
       ltHCross = 1
       if ltMS = -1 then
          // CHoCH alcista detectado (cambio de bajista a alcista)
          ltHisCHoCH = 1
          ltHMeasure = 0
          // Guardar datos del CHoCH
          bullChochX = ltHLastIndex
          bullChochY = ltHLastPrice
          bullChochRight = n
          bullChochActive = 1
          // Buscar el mínimo entre el swing y la ruptura para Area of Interest
          refValue = low
          refIndex = n
          for i = 1 to (n - ltHLastIndex) do
             if low[i] < refValue then
                refValue = low[i]
                refIndex = n - i
             endif
          next
          // Guardar para Fib nivel 1
          bullFibLn1X = refIndex
          bullFibLn1Y = refValue
          // Zone coordinates
          ltHZoneTop = ltHLastPrice
          ltHZoneBot = refValue
          ltHZoneLeft = n
          ltHZoneRight = n + 1
          ltHlwest = refValue
          ltHhghst = high
       else
          ltHisCHoCH = 0
       endif
       
       ltMSPrev = ltMS
       ltMS = 1
    endif
    
    // Extender zona si sigue activa
    if ltHisCHoCH = 1 and ltHMeasure = 0 then
       if low > ltHlwest then
          ltHZoneRight = n + 1
       else
          ltHisCHoCH = 0
       endif
    endif
    //------------------------------------------------
    // Engulfing Patterns
    //------------------------------------------------
    bodyHi = max(close, open)
    bodyLo = min(close, open)
    body = bodyHi - bodyLo
    bodyAvg = average[14](body)
    smallBody = body < bodyAvg
    longBody = body > bodyAvg
    whiteBody = open < close
    blackBody = open > close
    // Bearish Engulfing
    bearishEngulfing = blackBody and longBody and whiteBody[1] and smallBody[1] and close <= open[1] and open >= close[1] and (close < open[1] or open > close[1])
    // Bullish Engulfing
    bullishEngulfing = whiteBody and longBody and blackBody[1] and smallBody[1] and close >= open[1] and open <= close[1] and (close > open[1] or open < close[1])
    // Filtrar por estructura si engulfMode = 2
    if engulfMode = 2 then
       if bearishEngulfing and ltLisCHoCH = 1 and ltLMeasure = 0 and close > ltLZoneBot then
          bearEngulfShow = 1
       else
          bearEngulfShow = 0
       endif
       if bullishEngulfing and ltHisCHoCH = 1 and ltHMeasure = 0 and close < ltHZoneTop then
          bullEngulfShow = 1
       else
          bullEngulfShow = 0
       endif
    elsif engulfMode = 1 then
       if bearishEngulfing then
          bearEngulfShow = 1
       else
          bearEngulfShow = 0
       endif
       if bullishEngulfing then
          bullEngulfShow = 1
       else
          bullEngulfShow = 0
       endif
    else
       bearEngulfShow = 0
       bullEngulfShow = 0
    endif
    //------------------------------------------------
    // Fibonacci Management - Bullish
    //------------------------------------------------
    if ltHisCHoCH = 1 and ltHMeasure = 1 then
       if low > ltHlwest then
          bullFibActive = 1
       else
          bullFibActive = 0
       endif
    endif
    //------------------------------------------------
    // Fibonacci Management - Bearish
    //------------------------------------------------
    if ltLisCHoCH = 1 and ltLMeasure = 1 then
       if high < ltLhghst then
          bearFibActive = 1
       else
          bearFibActive = 0
       endif
    endif
    //------------------------------------------------
    // Drawing Section - Only on last bar update
    //------------------------------------------------
    if islastbarupdate then
       //--- Bullish CHoCH Line and Label ---
       if bullChochActive and bullCHoCHs then
          drawsegment(bullChochX, bullChochY, bullChochRight, bullChochY) coloured("green") style(line)
          drawtext("CHoCH", (bullChochX + bullChochRight) / 2, bullChochY - atr * 0.3) coloured("green")
       endif
       //--- Bearish CHoCH Line and Label ---
       if bearChochActive and bearCHoCHs then
          drawsegment(bearChochX, bearChochY, bearChochRight, bearChochY) coloured("red") style(line)
          drawtext("CHoCH", (bearChochX + bearChochRight) / 2, bearChochY + atr * 0.3) coloured("red")
       endif
       
       //--- Bullish Fibonacci Levels ---
       if bullFibActive and bullFibHighPrice > 0 and bullFibLowPrice > 0 then
          fibRange = abs(bullFibHighPrice - bullFibLowPrice)
          
          // Reference line (dashed)
          drawsegment(bullFibLowIndex, bullFibLowPrice, bullFibHighIndex, bullFibHighPrice) coloured("green") style(dottedline)
          
          // Level 1 (bottom of move)
          if show1 then
             fib1Price = bullFibLowPrice
             drawsegment(bullFibLowIndex, fib1Price, n + 5, fib1Price) coloured("green") style(line)
             drawtext("100%", n + 8, fib1Price) coloured("green")
          endif
          
          // Level 0.786
          if show0786 then
             fib0786Price = bullFibHighPrice - fibRange * value0786
             drawsegment(bullFibHighIndex, fib0786Price, n + 5, fib0786Price) coloured("green") style(dottedline)
             drawtext("78.6%", n + 8, fib0786Price) coloured("green")
          endif
          
          // Level 0.618
          if show0618 then
             fib0618Price = bullFibHighPrice - fibRange * value0618
             drawsegment(bullFibHighIndex, fib0618Price, n + 5, fib0618Price) coloured("green") style(dottedline)
             drawtext("61.8%", n + 8, fib0618Price) coloured("green")
          endif
          
          // Level 0.5
          if show05 then
             fib05Price = bullFibHighPrice - fibRange * value05
             drawsegment(bullFibHighIndex, fib05Price, n + 5, fib05Price) coloured("green") style(dottedline)
             drawtext("50%", n + 8, fib05Price) coloured("green")
          endif
          
          // Level 0.382
          if show0382 then
             fib0382Price = bullFibHighPrice - fibRange * value0382
             drawsegment(bullFibHighIndex, fib0382Price, n + 5, fib0382Price) coloured("green") style(dottedline)
             drawtext("38.2%", n + 8, fib0382Price) coloured("green")
          endif
          
          // Level 0.236
          if show0236 then
             fib0236Price = bullFibHighPrice - fibRange * value0236
             drawsegment(bullFibHighIndex, fib0236Price, n + 5, fib0236Price) coloured("green") style(dottedline)
             drawtext("23.6%", n + 8, fib0236Price) coloured("green")
          endif
          
          // Level 0 (top of move)
          if show0 then
             fib0Price = bullFibHighPrice
             drawsegment(bullFibHighIndex, fib0Price, n + 5, fib0Price) coloured("green") style(line)
             drawtext("0%", n + 8, fib0Price) coloured("green")
          endif
       endif
       
       //--- Bearish Fibonacci Levels ---
       if bearFibActive and bearFibHighPrice > 0 and bearFibLowPrice > 0 then
          fibRange = abs(bearFibHighPrice - bearFibLowPrice)
          
          // Reference line (dashed)
          drawsegment(bearFibHighIndex, bearFibHighPrice, bearFibLowIndex, bearFibLowPrice) coloured("red") style(dottedline)
          
          // Level 1 (top of move)
          if show1 then
             fib1Price = bearFibHighPrice
             drawsegment(bearFibHighIndex, fib1Price, n + 5, fib1Price) coloured("red") style(line)
             drawtext("100%", n + 8, fib1Price) coloured("red")
          endif
          
          // Level 0.786
          if show0786 then
             fib0786Price = bearFibLowPrice + fibRange * value0786
             drawsegment(bearFibLowIndex, fib0786Price, n + 5, fib0786Price) coloured("red") style(dottedline)
             drawtext("78.6%", n + 8, fib0786Price) coloured("red")
          endif
          
          // Level 0.618
          if show0618 then
             fib0618Price = bearFibLowPrice + fibRange * value0618
             drawsegment(bearFibLowIndex, fib0618Price, n + 5, fib0618Price) coloured("red") style(dottedline)
             drawtext("61.8%", n + 8, fib0618Price) coloured("red")
          endif
          
          // Level 0.5
          if show05 then
             fib05Price = bearFibLowPrice + fibRange * value05
             drawsegment(bearFibLowIndex, fib05Price, n + 5, fib05Price) coloured("red") style(dottedline)
             drawtext("50%", n + 8, fib05Price) coloured("red")
          endif
          
          // Level 0.382
          if show0382 then
             fib0382Price = bearFibLowPrice + fibRange * value0382
             drawsegment(bearFibLowIndex, fib0382Price, n + 5, fib0382Price) coloured("red") style(dottedline)
             drawtext("38.2%", n + 8, fib0382Price) coloured("red")
          endif
          
          // Level 0.236
          if show0236 then
             fib0236Price = bearFibLowPrice + fibRange * value0236
             drawsegment(bearFibLowIndex, fib0236Price, n + 5, fib0236Price) coloured("red") style(dottedline)
             drawtext("23.6%", n + 8, fib0236Price) coloured("red")
          endif
          
          // Level 0 (bottom of move)
          if show0 then
             fib0Price = bearFibLowPrice
             drawsegment(bearFibLowIndex, fib0Price, n + 5, fib0Price) coloured("red") style(line)
             drawtext("0%", n + 8, fib0Price) coloured("red")
          endif
       endif
       
       //--- Engulfing Patterns ---
       if bearEngulfShow then
          drawtext("▼", n, high + atr * 0.3) coloured("red")
       endif
       
       if bullEngulfShow then
          drawtext("▲", n, low - atr * 0.3) coloured("green")
       endif
       
       //--- Strong/Weak High/Low Labels ---
       if showHLSwings then
          if ltMS > 0 then
             drawtext("Weak High", ltHLastIndex, ltHLastPrice + atr * 0.5) coloured("red")
             drawtext("Strong Low", ltLLastIndex, ltLLastPrice - atr * 0.5) coloured("green")
          else
             drawtext("Strong High", ltHLastIndex, ltHLastPrice + atr * 0.5) coloured("red")
             drawtext("Weak Low", ltLLastIndex, ltLLastPrice - atr * 0.5) coloured("green")
          endif
       endif
    endif
    //--------------------------------------------------------------------------------//
    return
    


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

TradingView to ProRealTime Translation Center

New Reply
Author
author-avatar
Maricarmen @maricarmen Participant
Summary

This topic contains 5 replies,
has 3 voices, and was last updated by Iván González
1 week, 3 days ago.

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