PHANTOMFLOW TREND DETECTOR

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #260910 quote
    brian gilbert
    Participant
    Average
    Hello everyone, I'm writing about a new TW indicator that seems interesting to me, and I'd like to know if I can get the corresponding Prorealcode indicator. Here's the link:
    

    https://www.tradingview.com/script/AuFIke86-PhantomFlow-TrendDetector/


    And here's the Pine-script code
    

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

    // © PhantomFlow_s666ex_


    //@version=5

    indicator(“PhantomFlow Trend Detector”, “PhantomFlow TrendDetector”, true, max_lines_count = 500)


    type fractal

      int fractal_bar

      box bx


    type wave

      bool isActive

      bool isSearchCountertrendFormation

      bool isSearchTrendFormation

      int bar_start

      int bar_end

      float high_price

      float low_price

      array<line> lines


    var array<wave> waves_down = array.new<wave>()

    var array<wave> waves_up = array.new<wave>()

    var array<int> fractals_down_zigzag = array.new<int>()

    var array<int> fractals_up_zigzag = array.new<int>()


    var array<bool> listFractals = array.new<bool>()


    var array<fractal> LevelsShort = array.new<fractal>()

    var array<fractal> LevelsLong = array.new<fractal>()


    var array<fractal> LevelsShortHTF = array.new<fractal>()

    var array<fractal> LevelsLongHTF = array.new<fractal>()


    var array<int> levelsToCoef = array.new<int>()

    htf_alerts_enable = input.bool(title=’Enable Alerts’, defval = false)


    ltf = timeframe.period

    up_trend_start = input.color(title=’Low’, defval = color.rgb(255, 253, 106), group=”Up Trend Power”, inline = “up_trend”)

    up_trend_end = input.color(title=’High’, defval = color.rgb(0, 255, 0), group=”Up Trend Power”, inline = “up_trend”)

    down_trend_start = input.color(title=’Low’, defval = color.rgb(255, 89, 255), group=”Down Trend Power”, inline = “down_trend”)

    down_trend_end = input.color(title=’High’, defval = color.rgb(255, 0, 0), group=”Down Trend Power”, inline = “down_trend”)


    n_zigzag = 2


    is_down_fractal_zigzag() =>

      bool isConfirmFractal = false


      for i = 0 to n_zigzag + n_zigzag

        if low[n_zigzag] > low[i]

          break


        if (i == n_zigzag + n_zigzag)

    isConfirmFractal := true


      isConfirmFractal


    is_up_fractal_zigzag() =>

      bool isConfirmFractal = false

       

      for i = 0 to n_zigzag + n_zigzag

        if high[n_zigzag] < high[i]

          break


        if (i == n_zigzag + n_zigzag)

    isConfirmFractal := true

         

      isConfirmFractal


    check_is_add_up_liquidity() =>

      if array.size(fractals_up_zigzag) > 2

        item1 = array.last(fractals_up_zigzag)

        item2 = array.get(fractals_up_zigzag, array.size(fractals_up_zigzag) – 2)

        item3 = array.get(fractals_up_zigzag, array.size(fractals_up_zigzag) – 3)

        if (high[bar_index – item1] < high[bar_index – item2] and high[bar_index – item2] < high[bar_index – item3])

          if array.size(waves_up) == 0

            array.push(waves_up, wave.new(true, true, true, item3, item1, high[bar_index – item3], high[bar_index – item1], array.new<line>()))

            true

          else

            wave last_wave = array.last(waves_up)

            if (item3 >= last_wave.bar_start and item3 < last_wave.bar_end)

              last_wave.bar_end := item1

              last_wave.low_price := high[bar_index – item1]

              last_wave.isActive := false

              true

            else

              array.push(waves_up, wave.new(true, true, true, item3, item1, high[bar_index – item3], high[bar_index – item1], array.new<line>()))

              true


    check_is_add_down_liquidity() =>

      if array.size(fractals_down_zigzag) > 2

        item1 = array.last(fractals_down_zigzag)

        item2 = array.get(fractals_down_zigzag, array.size(fractals_down_zigzag) – 2)

        item3 = array.get(fractals_down_zigzag, array.size(fractals_down_zigzag) – 3)

        if (low[bar_index – item1] > low[bar_index – item2] and low[bar_index – item2] > low[bar_index – item3])

          if array.size(waves_down) == 0

            array.push(waves_down, wave.new(true, true, true, item3, item1, low[bar_index – item1], low[bar_index – item3], array.new<line>()))

            true

          else

            wave last_wave = array.last(waves_down)

            if (item3 >= last_wave.bar_start and item3 < last_wave.bar_end)

              last_wave.bar_end := item1

              last_wave.high_price := low[bar_index – item1]

              last_wave.isActive := false

              true

            else

              array.push(waves_down, wave.new(true, true, true, item3, item1, low[bar_index – item1], low[bar_index – item3], array.new<line>()))

              true


    bool is_search_fractal_zigzag = bar_index – n_zigzag * 2 >= 0 


    if is_search_fractal_zigzag and true

      if is_up_fractal_zigzag()

        if array.size(fractals_up_zigzag) == 0

          array.push(fractals_up_zigzag, bar_index – (n_zigzag))

          array.push(listFractals, true)

        else 

          isUpLastFractal = array.last(listFractals)

          lastFractal = array.last(fractals_up_zigzag)


          if isUpLastFractal and high[bar_index – lastFractal] < high[n_zigzag]

            array.pop(fractals_up_zigzag)

            array.push(fractals_up_zigzag, bar_index – (n_zigzag))

            check_is_add_up_liquidity()


          if not isUpLastFractal

            lastFractalDown = array.last(fractals_down_zigzag)

            if (low[bar_index – lastFractalDown] < high[n_zigzag])

              array.push(fractals_up_zigzag, bar_index – (n_zigzag))

              array.push(listFractals, true)

              check_is_add_up_liquidity()

      if is_down_fractal_zigzag()

        if array.size(fractals_down_zigzag) == 0

          array.push(fractals_down_zigzag, bar_index – (n_zigzag))

          array.push(listFractals, false)

        else

          isUpLastFractal = array.last(listFractals)

          lastFractal = array.last(fractals_down_zigzag)


          if not isUpLastFractal and low[bar_index – lastFractal] > low[n_zigzag]

            array.pop(fractals_down_zigzag)

            array.push(fractals_down_zigzag, bar_index – (n_zigzag))

            check_is_add_down_liquidity()


          if isUpLastFractal

            lastFractalUp = array.last(fractals_up_zigzag)

            if (high[bar_index – lastFractalUp] > low[n_zigzag])

              array.push(fractals_down_zigzag, bar_index – (n_zigzag))

              array.push(listFractals, false)

              check_is_add_down_liquidity()


    bool isDownTrend = false

    bool isUpTrend = false


    var float last_low = na

    var float last_high = na


    if (array.size(waves_up) != 0 and array.size(waves_down) != 0)

      wave lastWaveUp = array.last(waves_up)

      wave lastWaveDown = array.last(waves_down)


      if (close < lastWaveDown.high_price and close > lastWaveUp.low_price)

        if (lastWaveDown.bar_end < lastWaveUp.bar_end)

          isUpTrend := true

          last_low := lastWaveUp.low_price

          last_high := lastWaveUp.high_price

        else

          isDownTrend := true

          last_low := lastWaveDown.low_price

          last_high := lastWaveDown.high_price

         

      if (close >= lastWaveDown.high_price and close > lastWaveUp.low_price)

        isUpTrend := true

        last_low := lastWaveUp.low_price

        last_high := lastWaveUp.high_price


      if (close < lastWaveDown.high_price and close <= lastWaveUp.low_price)

        isDownTrend := true

        last_low := lastWaveDown.low_price

        last_high := lastWaveDown.high_price



    if (array.size(waves_up) != 0 and array.size(waves_down) == 0)

      wave lastWave = array.last(waves_up)

      if (close > lastWave.low_price)

        isUpTrend := true

        last_low := lastWave.low_price

        last_high := lastWave.high_price


    if (array.size(waves_down) != 0 and array.size(waves_up) == 0)

      wave lastWave = array.last(waves_down)

      if (close < lastWave.high_price)

        isDownTrend := true

        last_low := lastWave.low_price

        last_high := lastWave.high_price


    var color trend_css = na

    float signal = ta.ema(close, 1)


    color signalColorDown = color.from_gradient(signal, last_low, last_high, up_trend_start, up_trend_end)

    color signalColorUp = color.from_gradient(signal, last_low, last_high, down_trend_end, down_trend_start)


    if isDownTrend

      trend_css := signalColorUp

    if isUpTrend

      trend_css := signalColorDown


    isUpTrendAlert = trend_css == signalColorDown

    isDownTrendAlert = trend_css == signalColorUp


    if (isDownTrendAlert and not isDownTrendAlert[1] and htf_alerts_enable and not isUpTrendAlert and barstate.isconfirmed)

      alert(“🔴A new Down Trend has been detected!🔴”)

    if (isUpTrendAlert and not isUpTrendAlert[1] and htf_alerts_enable and barstate.isconfirmed)

      alert(“🟢A new Up Trend has been detected!🟢”)


    plotcandle(open, high, low, close

     , color = trend_css

     , wickcolor = trend_css

     , bordercolor = trend_css

     , editable = false

     , display = display.pane)

    ————————————————————————————————————————————————————————————

    Thank you very much!

    Paolo Bonsanti


    #260955 quote
    Iván González
    Moderator
    Master

    hi, here you have

    //----------------------------------------------------------------------------------------
    //PRC_PhantomFlow TrendDetector
    //version = 0
    //11.05.2026
    //Ivan Gonzalez @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    // Original: PhantomFlow_s666ex_ (TradingView, MPL 2.0)
    //----------------------------------------------------------------------------------------
    // === Inputs ===
    //----------------------------------------------------------------------------------------
    //nZigzag = 2
    
    // Up Trend gradient (low -> high)
    upStartR = 255
    upStartG = 253
    upStartB = 106
    upEndR = 0
    upEndG = 255
    upEndB = 0
    
    // Down Trend gradient (low -> high)
    downStartR = 255
    downStartG = 89
    downStartB = 255
    downEndR = 255
    downEndG = 0
    downEndB = 0
    //----------------------------------------------------------------------------------------
    // === Inicializacion (primera barra) ===
    //----------------------------------------------------------------------------------------
    IF barindex = 0 THEN
       fracUp1 = 0
       fracUp2 = 0
       fracUp3 = 0
       fracDown1 = 0
       fracDown2 = 0
       fracDown3 = 0
       numUp = 0
       numDown = 0
       isLastUp = -1
       waveUpStart = 0
       waveUpEnd = 0
       waveUpHigh = 0
       waveUpLow = 0
       hasWaveUp = 0
       waveDownStart = 0
       waveDownEnd = 0
       waveDownHigh = 0
       waveDownLow = 0
       hasWaveDown = 0
       lastLow = 0
       lastHigh = 0
    ENDIF
    
    addUpWave = 0
    addDownWave = 0
    //----------------------------------------------------------------------------------------
    // === Deteccion de fractales (simetricos n=2, ventana = 5 barras) ===
    //----------------------------------------------------------------------------------------
    canSearchFractal = barindex >= 2 * nZigzag
    
    IF canSearchFractal THEN
       // Fractal up: high[2] es maximo de high[0..4]
       IF high[nZigzag] = highest[2 * nZigzag + 1](high) THEN
          isUpFractal = 1
       ELSE
          isUpFractal = 0
       ENDIF
       // Fractal down: low[2] es minimo de low[0..4]
       IF low[nZigzag] = lowest[2 * nZigzag + 1](low) THEN
          isDownFractal = 1
       ELSE
          isDownFractal = 0
       ENDIF
       
       barFrac = barindex - nZigzag
       priceUpFrac = high[nZigzag]
       priceDownFrac = low[nZigzag]
       
       // --- Procesar fractal up ---
       IF isUpFractal = 1 THEN
          IF numUp = 0 AND numDown = 0 THEN
             fracUp1 = barFrac
             numUp = 1
             isLastUp = 1
          ELSE
             IF isLastUp = 1 THEN
                // Ultimo era up: si el nuevo es mas alto, reemplazar (pop + push)
                IF high[barindex - fracUp1] < priceUpFrac THEN
                   fracUp1 = barFrac
                   addUpWave = 1
                ENDIF
             ELSE
                // Ultimo era down: confirmar zigzag si new high > last down low
                IF low[barindex - fracDown1] < priceUpFrac THEN
                   fracUp3 = fracUp2
                   fracUp2 = fracUp1
                   fracUp1 = barFrac
                   numUp = numUp + 1
                   isLastUp = 1
                   addUpWave = 1
                ENDIF
             ENDIF
          ENDIF
       ENDIF
       
       // Check is_add_up_liquidity: 3 ups consecutivos con highs decrecientes
       IF addUpWave = 1 AND numUp >= 3 THEN
          h1 = high[barindex - fracUp1]
          h2 = high[barindex - fracUp2]
          h3 = high[barindex - fracUp3]
          IF h1 < h2 AND h2 < h3 THEN
             IF hasWaveUp = 1 AND fracUp3 >= waveUpStart AND fracUp3 < waveUpEnd THEN
                // Extender wave
                waveUpEnd = fracUp1
                waveUpLow = h1
             ELSE
                // Nueva wave
                waveUpStart = fracUp3
                waveUpEnd = fracUp1
                waveUpHigh = h3
                waveUpLow = h1
             ENDIF
             hasWaveUp = 1
          ENDIF
       ENDIF
       
       // --- Procesar fractal down ---
       IF isDownFractal = 1 THEN
          IF numDown = 0 AND numUp = 0 THEN
             fracDown1 = barFrac
             numDown = 1
             isLastUp = 0
          ELSE
             IF isLastUp = 0 THEN
                // Ultimo era down: si el nuevo es mas bajo, reemplazar
                IF low[barindex - fracDown1] > priceDownFrac THEN
                   fracDown1 = barFrac
                   addDownWave = 1
                ENDIF
             ELSE
                // Ultimo era up: confirmar zigzag si last up high > new down low
                IF high[barindex - fracUp1] > priceDownFrac THEN
                   fracDown3 = fracDown2
                   fracDown2 = fracDown1
                   fracDown1 = barFrac
                   numDown = numDown + 1
                   isLastUp = 0
                   addDownWave = 1
                ENDIF
             ENDIF
          ENDIF
       ENDIF
       
       // Check is_add_down_liquidity: 3 downs consecutivos con lows crecientes
       IF addDownWave = 1 AND numDown >= 3 THEN
          l1 = low[barindex - fracDown1]
          l2 = low[barindex - fracDown2]
          l3 = low[barindex - fracDown3]
          IF l1 > l2 AND l2 > l3 THEN
             IF hasWaveDown = 1 AND fracDown3 >= waveDownStart AND fracDown3 < waveDownEnd THEN
                // Extender wave
                waveDownEnd = fracDown1
                waveDownHigh = l1
             ELSE
                // Nueva wave
                waveDownStart = fracDown3
                waveDownEnd = fracDown1
                waveDownLow = l3
                waveDownHigh = l1
             ENDIF
             hasWaveDown = 1
          ENDIF
       ENDIF
    ENDIF
    //----------------------------------------------------------------------------------------
    // === Determinar tendencia ===
    //----------------------------------------------------------------------------------------
    isUpTrend = 0
    isDownTrend = 0
    
    IF hasWaveUp = 1 AND hasWaveDown = 1 THEN
       IF close < waveDownHigh AND close > waveUpLow THEN
          IF waveDownEnd < waveUpEnd THEN
             isUpTrend = 1
             lastLow = waveUpLow
             lastHigh = waveUpHigh
          ELSE
             isDownTrend = 1
             lastLow = waveDownLow
             lastHigh = waveDownHigh
          ENDIF
       ENDIF
       IF close >= waveDownHigh AND close > waveUpLow THEN
          isUpTrend = 1
          lastLow = waveUpLow
          lastHigh = waveUpHigh
       ENDIF
       IF close < waveDownHigh AND close <= waveUpLow THEN
          isDownTrend = 1
          lastLow = waveDownLow
          lastHigh = waveDownHigh
       ENDIF
    ENDIF
    
    IF hasWaveUp = 1 AND hasWaveDown = 0 THEN
       IF close > waveUpLow THEN
          isUpTrend = 1
          lastLow = waveUpLow
          lastHigh = waveUpHigh
       ENDIF
    ENDIF
    
    IF hasWaveDown = 1 AND hasWaveUp = 0 THEN
       IF close < waveDownHigh THEN
          isDownTrend = 1
          lastLow = waveDownLow
          lastHigh = waveDownHigh
       ENDIF
    ENDIF
    //----------------------------------------------------------------------------------------
    // === Color gradient interpolado (signal = close, ema(1) = close) ===
    //----------------------------------------------------------------------------------------
    signal = close
    
    IF lastHigh - lastLow <= 0 THEN
       norm = 0.5
    ELSE
       norm = (signal - lastLow) / (lastHigh - lastLow)
       IF norm < 0 THEN
          norm = 0
       ENDIF
       IF norm > 1 THEN
          norm = 1
       ENDIF
    ENDIF
    
    paintR = 128
    paintG = 128
    paintB = 128
    
    IF isUpTrend = 1 THEN
       // Up: upStart (low) -> upEnd (high)
       paintR = ROUND(upStartR + (upEndR - upStartR) * norm)
       paintG = ROUND(upStartG + (upEndG - upStartG) * norm)
       paintB = ROUND(upStartB + (upEndB - upStartB) * norm)
    ENDIF
    
    IF isDownTrend = 1 THEN
       // Down: downEnd (low) -> downStart (high)
       paintR = ROUND(downEndR + (downStartR - downEndR) * norm)
       paintG = ROUND(downEndG + (downStartG - downEndG) * norm)
       paintB = ROUND(downEndB + (downStartB - downEndB) * norm)
    ENDIF
    
    DRAWCANDLE(open, high, low, close) COLOURED(paintR, paintG, paintB)
    //----------------------------------------------------------------------------------------
    RETURN
    
    TSLA-Diario.png TSLA-Diario.png
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

TradingView to ProRealTime Translation Center

New Reply
Author
Summary

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

Topic Details
Forum: TradingView to ProRealTime Translation Center Forum
Started: 05/07/2026
Status: Active
Attachments: 1 files
Logo Logo
Loading...