Conversion of DFTX Zones – fibo algo .. TIA

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #264993 quote
    ZiggyZiggy
    Participant
    Average

    code follows – source LuzAlgo


    // 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=6

    indicator(“DTFX Algo Zones”, shorttitle = “DTFX Algo Zones”, overlay = true, max_boxes_count = 500, max_lines_count = 500)


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

    //Inputs

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


    structureTog = input.bool(true, title = “Show Swing Points”, group = “Structure”)

    structureLen = input.int(10, title = “Structure Length”, group = “Structure”)


    zoneDispNum = input.int(1, title = “Show Last”, group = “Zones”, minval = 0)

    dispAll = input.bool(true, title = “Display All Zones”, tooltip = “Ignores Zone Display # and Displays all Possible Zones.”, group = “Zones”)

    zoneFilter = input.string(“Both”, title = “Zone Display”, options = [“Bullish Only”, “Bearish Only”, “Both”], group = “Zones”)

    noOverlap = input.bool(true, title = “Clean-Up Level Overlap”, group = “Zones”)


    fib_group = ”       Fib Levels          Line Style         Bull | Bear”


    f1Tog = input.bool(false, title = “”, group = fib_group, inline = “1”)

    f2Tog = input.bool(true, title = “”, group = fib_group, inline = “2”)

    f3Tog = input.bool(true, title = “”, group = fib_group, inline = “3”)

    f4Tog = input.bool(true, title = “”, group = fib_group, inline = “4”)

    f5Tog = input.bool(false, title = “”, group = fib_group, inline = “5”)


    f1Lvl = f1Tog?input.float(0, title = “”, group = fib_group, inline = “1”):na

    f2Lvl = f2Tog?input.float(0.3, title = “”, group = fib_group, inline = “2”):na

    f3Lvl = f3Tog?input.float(0.5, title = “”, group = fib_group, inline = “3”):na

    f4Lvl = f4Tog?input.float(0.7, title = “”, group = fib_group, inline = “4”):na

    f5Lvl = f5Tog?input.float(1, title = “”, group = fib_group, inline = “5”):na


    f1Style = input.string(“. . .”, title = “”, options = [“___”,”- – -“,”. . .”], group = fib_group, inline = “1”)

    f2Style = input.string(“- – -“, title = “”, options = [“___”,”- – -“,”. . .”], group = fib_group, inline = “2”)

    f3Style = input.string(“___”, title = “”, options = [“___”,”- – -“,”. . .”], group = fib_group, inline = “3”)

    f4Style = input.string(“- – -“, title = “”, options = [“___”,”- – -“,”. . .”], group = fib_group, inline = “4”)

    f5Style = input.string(“. . .”, title = “”, options = [“___”,”- – -“,”. . .”], group = fib_group, inline = “5”)


    f1BullColor = input.color(#089981, title = “”, group = fib_group, inline = “1”)

    f2BullColor = input.color(#089981, title = “”, group = fib_group, inline = “2”)

    f3BullColor = input.color(#089981, title = “”, group = fib_group, inline = “3”)

    f4BullColor = input.color(#089981, title = “”, group = fib_group, inline = “4”)

    f5BullColor = input.color(#089981, title = “”, group = fib_group, inline = “5”)


    f1BearColor = input.color(#f23645, title = “”, group = fib_group, inline = “1”)

    f2BearColor = input.color(#f23645, title = “”, group = fib_group, inline = “2”)

    f3BearColor = input.color(#f23645, title = “”, group = fib_group, inline = “3”)

    f4BearColor = input.color(#f23645, title = “”, group = fib_group, inline = “4”)

    f5BearColor = input.color(#f23645, title = “”, group = fib_group, inline = “5”)


    structureColor = input.color(color.gray, title = “Structure Color”, group = “Style”)

    bullZoneColor = input.color(color.new(#089981,80), title = “Bullish Zone Color”, group = “Style”)

    bearZoneColor = input.color(color.new(#f23645,80), title = “Bearish Zone Color”, group = “Style”)



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

    //UDTs

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


    type pb 

      float price

      int bar


    type fs

      line f1

      line f2

      line f3

      line f4

      line f5


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

    //Functions

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


    linestyle(_input) =>

      _input == “___”?line.style_solid:

       _input == “- – -“?line.style_dashed:

       _input == “. . .”?line.style_dotted:

       na


    get_fibs(_top,_bot,_dir,_fl1,_fl2,_fl3,_fl4,_fl5) =>

      rng = _dir == 1 ? _top – _bot : _bot – _top

      anchor = _dir == 1 ? _bot : _top

      fib1 = anchor + (rng*_fl1)

      fib2 = anchor + (rng*_fl2)

      fib3 = anchor + (rng*_fl3)

      fib4 = anchor + (rng*_fl4)

      fib5 = anchor + (rng*_fl5)

      [fib1,fib2,fib3,fib4,fib5]


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

    //Calcs

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


    var int dir = 0


    float top = na

    float btm = na


    var pb t = pb.new(na,na)

    var pb b = pb.new(na,na)


    var bool bos_up_check = false

    var bool bos_down_check = false

       

    var string last_bot = “NA”

    var string last_top = “NA”


    var zones = array.new_box()

    var lvls = array.new<fs>()


    var box live_zone = na

    var fs live_lvls = fs.new(na,na,na,na,na)


    upper = ta.highest(structureLen)

    lower = ta.lowest(structureLen)


    if dir >= 0 and high[structureLen] > upper

      dir := -1 

      top := high[structureLen]


    if dir <= 0 and low[structureLen] < lower

      dir := 1

      btm := low[structureLen]


    top_conf = not na(top)

    bot_conf = not na(btm)


    int structure_confirmed = 0


    if top_conf

      t := pb.new(top,bar_index-structureLen)

      bos_up_check := true

      if structureTog

        structure_confirmed := 1

    if bot_conf

      b := pb.new(btm,bar_index-structureLen)

      bos_down_check := true

      if structureTog

        structure_confirmed := -1

       

    plotshape(structure_confirmed>0?true:false, style = shape.circle, title = “Swing High”, location = location.abovebar, offset = -structureLen, color = structureColor)

    plotshape(structure_confirmed<0?true:false, style = shape.circle, title = “Swing Low”, location = location.belowbar, offset = -structureLen, color = structureColor)



    HH = top_conf and t.price > t.price[1]

    HL = bot_conf and b.price > b.price[1]

    LH = top_conf and t.price < t.price[1]

    LL = bot_conf and b.price < b.price[1]


    last_top := HH?”HH”:LH?”LH”:last_top

    last_bot := LL?”LL”:HL?”HL”:last_bot


    var int t_dir = 0


    choch_up = ta.crossover(close,t.price) and (high == upper) and t_dir <= 0 

    choch_down = ta.crossunder(close,b.price) and (low == lower) and t_dir >= 0

       

    if choch_up

      t_dir := 1

    if choch_down

      t_dir := -1

       

    bos_up = ta.crossover(close,t.price) and bos_up_check and t_dir >= 0

    bos_down = ta.crossunder(close,b.price) and bos_down_check and t_dir <= 0


    mss_up = bos_up or choch_up

    mss_down = bos_down or choch_down


    if mss_up

      bos_up_check := false

      if zoneFilter != “Bearish Only”

        _top = t.price

        _bot = dir == -1 ? lower : dir == 1 ? b.price : 0

        [fib1,fib2,fib3,fib4,fib5] = get_fibs(_top,_bot,1,f1Lvl,f2Lvl,f3Lvl,f4Lvl,f5Lvl)

        live_zone := box.new(t.bar,_top,bar_index,_bot,bgcolor = bullZoneColor,border_color = na)

        live_lvls := fs.new(

         line.new(t.bar,(f1Tog?fib1:na),bar_index,fib1, color = f1BullColor, style = linestyle(f1Style)),

         line.new(t.bar,(f2Tog?fib2:na),bar_index,fib2, color = f2BullColor, style = linestyle(f2Style)),

         line.new(t.bar,(f3Tog?fib3:na),bar_index,fib3, color = f3BullColor, style = linestyle(f3Style)),

         line.new(t.bar,(f4Tog?fib4:na),bar_index,fib4, color = f4BullColor, style = linestyle(f4Style)),

         line.new(t.bar,(f5Tog?fib5:na),bar_index,fib5, color = f5BullColor, style = linestyle(f5Style))

         )

        zones.push(live_zone)

        lvls.push(live_lvls)  


    if mss_down

      bos_down_check := false

      if zoneFilter != “Bullish Only”

        _top = dir == 1 ? upper : dir == -1 ? t.price : 0

        _bot = b.price

        [fib1,fib2,fib3,fib4,fib5] = get_fibs(_top,_bot,-1,f1Lvl,f2Lvl,f3Lvl,f4Lvl,f5Lvl)

        live_zone := box.new(b.bar,_top,bar_index,_bot,bgcolor = bearZoneColor,border_color = na)

        live_lvls := fs.new(

         line.new(b.bar,(f1Tog?fib1:na),bar_index,fib1, color = f1BearColor, style = linestyle(f1Style)),

         line.new(b.bar,(f2Tog?fib2:na),bar_index,fib2, color = f2BearColor, style = linestyle(f2Style)),

         line.new(b.bar,(f3Tog?fib3:na),bar_index,fib3, color = f3BearColor, style = linestyle(f3Style)),

         line.new(b.bar,(f4Tog?fib4:na),bar_index,fib4, color = f4BearColor, style = linestyle(f4Style)),

         line.new(b.bar,(f5Tog?fib5:na),bar_index,fib5, color = f5BearColor, style = linestyle(f5Style))

         )

        zones.push(live_zone)

        lvls.push(live_lvls)  


    if zones.size() > zoneDispNum and not dispAll

      zones.shift().delete()

      ln = lvls.shift()

      ln.f1.delete()

      ln.f2.delete()

      ln.f3.delete()

      ln.f4.delete()

      ln.f5.delete()


    if lvls.size() > 1 and noOverlap

      last_zone = zones.get(zones.size()-2)

      last_lvl = lvls.get(lvls.size()-2)

      if last_lvl.f1.get_x2() > live_lvls.f1.get_x1()

        last_lvl.f1.set_x2(math.max(live_zone.get_left(),last_zone.get_right()))

        last_lvl.f2.set_x2(math.max(live_zone.get_left(),last_zone.get_right()))

        last_lvl.f3.set_x2(math.max(live_zone.get_left(),last_zone.get_right()))

        last_lvl.f4.set_x2(math.max(live_zone.get_left(),last_zone.get_right()))

        last_lvl.f5.set_x2(math.max(live_zone.get_left(),last_zone.get_right()))


        live_lvls.f1.set_x1(math.max(live_zone.get_left(),last_zone.get_right()))

        live_lvls.f2.set_x1(math.max(live_zone.get_left(),last_zone.get_right()))

        live_lvls.f3.set_x1(math.max(live_zone.get_left(),last_zone.get_right()))

        live_lvls.f4.set_x1(math.max(live_zone.get_left(),last_zone.get_right()))

        live_lvls.f5.set_x1(math.max(live_zone.get_left(),last_zone.get_right()))


    live_lvls.f1.set_x2(bar_index)

    live_lvls.f2.set_x2(bar_index)

    live_lvls.f3.set_x2(bar_index)

    live_lvls.f4.set_x2(bar_index)

    live_lvls.f5.set_x2(bar_index)

       

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

    #265005 quote
    ZiggyZiggy
    Participant
    Average

    try this!

    // DTFX Algo Zones – ProRealTime conversion

    // Original: LuxAlgo (CC BY-NC-SA 4.0)

    // Converted to ProBuilder by ProRealAI


    defparam drawonlastbaronly = true


    // —- Inputs —-

    structureLen = 10

    showSwing  = 1


    // Fib level toggles

    f2Tog = 1

    f3Tog = 1

    f4Tog = 1


    // Fib ratios

    f2Lvl = 0.3

    f3Lvl = 0.5

    f4Lvl = 0.7


    // Zone filter: 0=Both, 1=Bullish Only, -1=Bearish Only

    zoneFilter = 0


    // Bull zone color (green #089981)

    bullR = 8

    bullG = 153

    bullB = 129

    bullA = 50


    // Bear zone color (red #f23645)

    bearR = 242

    bearG = 54

    bearB = 69

    bearA = 50


    // Fib line colors

    fibBullR = 8

    fibBullG = 153

    fibBullB = 129

    fibBearR = 242

    fibBearG = 54

    fibBearB = 69


    // Structure dot color (gray)

    strR = 128

    strG = 128

    strB = 128


    // —- Pivot detection —-

    // A pivot high occurs when high[structureLen] is the highest in window of 2*structureLen+1 bars

    upper = highest[structureLen*2+1](high)

    lower = lowest[structureLen*2+1](low)


    pivotHigh = (high[structureLen] = upper)

    pivotLow = (low[structureLen] = lower)


    // —- Track last confirmed pivot prices and bar indices —-

    if pivotHigh then

      dir    = -1

      topPrice = high[structureLen]

      topBarIdx = barindex[structureLen]

    endif


    if pivotLow then

      dir    = 1

      botPrice = low[structureLen]

      botBarIdx = barindex[structureLen]

    endif


    if topPrice > 0 then

      lastTopPrice = topPrice

      lastTopBar  = topBarIdx

    endif


    if botPrice > 0 then

      lastBotPrice = botPrice

      lastBotBar  = botBarIdx

    endif


    // —- Swing dot markers —-

    if showSwing = 1 then

      if pivotHigh then

        drawpoint(barindex[structureLen], high[structureLen], 3) coloured(strR, strG, strB)

      endif

      if pivotLow then

        drawpoint(barindex[structureLen], low[structureLen], 3) coloured(strR, strG, strB)

      endif

    endif


    // —- Market structure trend direction (tdir) —-

    chochUp  = (close > lastTopPrice) and (close[1] <= lastTopPrice) and (tdir <= 0)

    chochDown = (close < lastBotPrice) and (close[1] >= lastBotPrice) and (tdir >= 0)


    bosUp  = (close > lastTopPrice) and (close[1] <= lastTopPrice) and (bosUpCheck = 1) and (tdir >= 0)

    bosDown = (close < lastBotPrice) and (close[1] >= lastBotPrice) and (bosDnCheck = 1) and (tdir <= 0)


    mssUp  = bosUp  or chochUp

    mssDown = bosDown or chochDown


    if chochUp then

      tdir = 1

    endif

    if chochDown then

      tdir = -1

    endif


    // BOS check flags reset after zone is triggered

    if pivotHigh then

      bosUpCheck = 1

    endif

    if pivotLow then

      bosDnCheck = 1

    endif

    if mssUp then

      bosUpCheck = 0

    endif

    if mssDown then

      bosDnCheck = 0

    endif


    // —- Bullish zone drawing —-

    if mssUp and (zoneFilter = 0 or zoneFilter = 1) then

      zTop = lastTopPrice

      if dir = -1 then

        zBot = lowest[structureLen](low)

      else

        zBot = lastBotPrice

      endif

      rng = zTop – zBot


      if f2Tog = 1 then

        fb2bull = zBot + rng * f2Lvl

      endif

      if f3Tog = 1 then

        fb3bull = zBot + rng * f3Lvl

      endif

      if f4Tog = 1 then

        fb4bull = zBot + rng * f4Lvl

      endif


      drawrectangle(lastTopBar, zTop, barindex, zBot) coloured(bullR, bullG, bullB, bullA) bordercolor(bullR, bullG, bullB, 0)


      if f2Tog = 1 then

        drawsegment(lastTopBar, fb2bull, barindex, fb2bull) coloured(fibBullR, fibBullG, fibBullB) style(dottedline)

      endif

      if f3Tog = 1 then

        drawsegment(lastTopBar, fb3bull, barindex, fb3bull) coloured(fibBullR, fibBullG, fibBullB) style(line)

      endif

      if f4Tog = 1 then

        drawsegment(lastTopBar, fb4bull, barindex, fb4bull) coloured(fibBullR, fibBullG, fibBullB) style(dottedline)

      endif


      liveZoneTop = zTop

      liveZoneBot = zBot

      liveZoneBar = lastTopBar

      liveFb2   = fb2bull

      liveFb3   = fb3bull

      liveFb4   = fb4bull

      liveIsBull = 1

    endif


    // —- Bearish zone drawing —-

    if mssDown and (zoneFilter = 0 or zoneFilter = -1) then

      zBot = lastBotPrice

      if dir = 1 then

        zTop = highest[structureLen](high)

      else

        zTop = lastTopPrice

      endif

      rng = zBot – zTop


      if f2Tog = 1 then

        fb2bear = zTop + rng * f2Lvl

      endif

      if f3Tog = 1 then

        fb3bear = zTop + rng * f3Lvl

      endif

      if f4Tog = 1 then

        fb4bear = zTop + rng * f4Lvl

      endif


      drawrectangle(lastBotBar, zTop, barindex, zBot) coloured(bearR, bearG, bearB, bearA) bordercolor(bearR, bearG, bearB, 0)


      if f2Tog = 1 then

        drawsegment(lastBotBar, fb2bear, barindex, fb2bear) coloured(fibBearR, fibBearG, fibBearB) style(dottedline)

      endif

      if f3Tog = 1 then

        drawsegment(lastBotBar, fb3bear, barindex, fb3bear) coloured(fibBearR, fibBearG, fibBearB) style(line)

      endif

      if f4Tog = 1 then

        drawsegment(lastBotBar, fb4bear, barindex, fb4bear) coloured(fibBearR, fibBearG, fibBearB) style(dottedline)

      endif


      liveZoneTop = zTop

      liveZoneBot = zBot

      liveZoneBar = lastBotBar

      liveFb2   = fb2bear

      liveFb3   = fb3bear

      liveFb4   = fb4bear

      liveIsBull = 0

    endif


    // —- Extend the live zone to current bar on every bar —-

    if liveZoneTop > 0 then

      if liveIsBull = 1 then

        drawrectangle(liveZoneBar, liveZoneTop, barindex, liveZoneBot) coloured(bullR, bullG, bullB, bullA) bordercolor(bullR, bullG, bullB, 0)

        if f2Tog = 1 then

          drawsegment(liveZoneBar, liveFb2, barindex, liveFb2) coloured(fibBullR, fibBullG, fibBullB) style(dottedline)

        endif

        if f3Tog = 1 then

          drawsegment(liveZoneBar, liveFb3, barindex, liveFb3) coloured(fibBullR, fibBullG, fibBullB) style(line)

        endif

        if f4Tog = 1 then

          drawsegment(liveZoneBar, liveFb4, barindex, liveFb4) coloured(fibBullR, fibBullG, fibBullB) style(dottedline)

        endif

      else

        drawrectangle(liveZoneBar, liveZoneTop, barindex, liveZoneBot) coloured(bearR, bearG, bearB, bearA) bordercolor(bearR, bearG, bearB, 0)

        if f2Tog = 1 then

          drawsegment(liveZoneBar, liveFb2, barindex, liveFb2) coloured(fibBearR, fibBearG, fibBearB) style(dottedline)

        endif

        if f3Tog = 1 then

          drawsegment(liveZoneBar, liveFb3, barindex, liveFb3) coloured(fibBearR, fibBearG, fibBearB) style(line)

        endif

        if f4Tog = 1 then

          drawsegment(liveZoneBar, liveFb4, barindex, liveFb4) coloured(fibBearR, fibBearG, fibBearB) style(dottedline)

        endif

      endif

    endif


    RETURN


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

Conversion of DFTX Zones – fibo algo .. TIA


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
Ziggy @ziggy Participant
Summary

This topic contains 1 reply,
has 1 voice, and was last updated by ZiggyZiggy
1 month ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 09/08/2026
Status: Active
Attachments: No files
ProRealCode ProRealCode
Loading...