Convert FVG TO Pro Real Time Please

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #239182 quote
    yas
    Participant
    Junior

    // 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(“Fair Value Gap [LuxAlgo]”, “LuxAlgo – Fair Value Gap”, overlay = true, max_lines_count = 500, max_boxes_count = 500)
    //——————————————————————————
    //Settings
    //—————————————————————————–{
    thresholdPer = input.float(0, “Threshold %”, minval = 0, maxval = 100, step = .1, inline = ‘threshold’)
    auto = input(false, “Auto”, inline = ‘threshold’)

    showLast = input.int(0, ‘Unmitigated Levels’, minval = 0)
    mitigationLevels = input.bool(false, ‘Mitigation Levels’)

    tf = input.timeframe(”, “Timeframe”)

    //Style
    extend = input.int(20, ‘Extend’, minval = 0, inline = ‘extend’, group = ‘Style’)
    dynamic = input(false, ‘Dynamic’, inline = ‘extend’, group = ‘Style’)

    bullCss = input.color(color.new(#089981, 70), “Bullish FVG”, group = ‘Style’)
    bearCss = input.color(color.new(#f23645, 70), “Bearish FVG”, group = ‘Style’)

    //Dashboard
    showDash = input(false, ‘Show Dashboard’, group = ‘Dashboard’)
    dashLoc = input.string(‘Top Right’, ‘Location’, options = [‘Top Right’, ‘Bottom Right’, ‘Bottom Left’], group = ‘Dashboard’)
    textSize = input.string(‘Small’, ‘Size’ , options = [‘Tiny’, ‘Small’, ‘Normal’] , group = ‘Dashboard’)

    //—————————————————————————–}
    //UDT’s
    //—————————————————————————–{
    type fvg
    float max
    float min
    bool isbull
    int t = time

    //—————————————————————————–}
    //Methods/Functions
    //—————————————————————————–{
    n = bar_index

    method tosolid(color id)=> color.rgb(color.r(id),color.g(id),color.b(id))

    detect()=>
    var new_fvg = fvg.new(na, na, na, na)
    threshold = auto ? ta.cum((high – low) / low) / bar_index : thresholdPer / 100

    bull_fvg = low > high[2] and close[1] > high[2] and (low – high[2]) / high[2] > threshold
    bear_fvg = high < low[2] and close[1] < low[2] and (low[2] – high) / high > threshold

    if bull_fvg
    new_fvg := fvg.new(low, high[2], true)
    else if bear_fvg
    new_fvg := fvg.new(low[2], high, false)

    [bull_fvg, bear_fvg, new_fvg]

    //—————————————————————————–}
    //FVG’s detection/display
    //—————————————————————————–{
    var float max_bull_fvg = na, var float min_bull_fvg = na, var bull_count = 0, var bull_mitigated = 0
    var float max_bear_fvg = na, var float min_bear_fvg = na, var bear_count = 0, var bear_mitigated = 0
    var t = 0

    var fvg_records = array.new<fvg>(0)
    var fvg_areas = array.new<box>(0)

    [bull_fvg, bear_fvg, new_fvg] = request.security(syminfo.tickerid, tf, detect())

    //Bull FVG’s
    if bull_fvg and new_fvg.t != t
    if dynamic
    max_bull_fvg := new_fvg.max
    min_bull_fvg := new_fvg.min

    //Populate FVG array
    if not dynamic
    fvg_areas.unshift(box.new(n-2, new_fvg.max, n+extend, new_fvg.min, na, bgcolor = bullCss))
    fvg_records.unshift(new_fvg)

    bull_count += 1
    t := new_fvg.t
    else if dynamic
    max_bull_fvg := math.max(math.min(close, max_bull_fvg), min_bull_fvg)

    //Bear FVG’s
    if bear_fvg and new_fvg.t != t
    if dynamic
    max_bear_fvg := new_fvg.max
    min_bear_fvg := new_fvg.min

    //Populate FVG array
    if not dynamic
    fvg_areas.unshift(box.new(n-2, new_fvg.max, n+extend, new_fvg.min, na, bgcolor = bearCss))
    fvg_records.unshift(new_fvg)

    bear_count += 1
    t := new_fvg.t
    else if dynamic
    min_bear_fvg := math.min(math.max(close, min_bear_fvg), max_bear_fvg)

    //—————————————————————————–}
    //Unmitigated/Mitigated lines
    //—————————————————————————–{
    //Test for mitigation
    if fvg_records.size() > 0
    for i = fvg_records.size()-1 to 0
    get = fvg_records.get(i)

    if get.isbull
    if close < get.min
    //Display line if mitigated
    if mitigationLevels
    line.new(get.t
    , get.min
    , time
    , get.min
    , xloc.bar_time
    , color = bullCss
    , style = line.style_dashed)

    //Delete box
    if not dynamic
    area = fvg_areas.remove(i)
    area.delete()

    fvg_records.remove(i)
    bull_mitigated += 1
    else if close > get.max
    //Display line if mitigated
    if mitigationLevels
    line.new(get.t
    , get.max
    , time
    , get.max
    , xloc.bar_time
    , color = bearCss
    , style = line.style_dashed)

    //Delete box
    if not dynamic
    area = fvg_areas.remove(i)
    area.delete()

    fvg_records.remove(i)
    bear_mitigated += 1

    //Unmitigated lines
    var unmitigated = array.new<line>(0)

    //Remove umitigated lines
    if barstate.islast and showLast > 0 and fvg_records.size() > 0
    if unmitigated.size() > 0
    for element in unmitigated
    element.delete()
    unmitigated.clear()

    for i = 0 to math.min(showLast-1, fvg_records.size()-1)
    get = fvg_records.get(i)

    unmitigated.push(line.new(get.t
    , get.isbull ? get.min : get.max
    , time
    , get.isbull ? get.min : get.max
    , xloc.bar_time
    , color = get.isbull ? bullCss : bearCss))

    //—————————————————————————–}
    //Dashboard
    //—————————————————————————–{
    var table_position = dashLoc == ‘Bottom Left’ ? position.bottom_left
    : dashLoc == ‘Top Right’ ? position.top_right
    : position.bottom_right

    var table_size = textSize == ‘Tiny’ ? size.tiny
    : textSize == ‘Small’ ? size.small
    : size.normal

    var tb = table.new(table_position, 3, 3
    , bgcolor = #1e222d
    , border_color = #373a46
    , border_width = 1
    , frame_color = #373a46
    , frame_width = 1)

    if showDash
    if barstate.isfirst
    tb.cell(1, 0, ‘Bullish’, text_color = bullCss.tosolid(), text_size = table_size)
    tb.cell(2, 0, ‘Bearish’, text_color = bearCss.tosolid(), text_size = table_size)

    tb.cell(0, 1, ‘Count’, text_size = table_size, text_color = color.white)
    tb.cell(0, 2, ‘Mitigated’, text_size = table_size, text_color = color.white)

    if barstate.islast
    tb.cell(1, 1, str.tostring(bull_count), text_color = bullCss.tosolid(), text_size = table_size)
    tb.cell(2, 1, str.tostring(bear_count), text_color = bearCss.tosolid(), text_size = table_size)

    tb.cell(1, 2, str.tostring(bull_mitigated / bull_count * 100, format.percent), text_color = bullCss.tosolid(), text_size = table_size)
    tb.cell(2, 2, str.tostring(bear_mitigated / bear_count * 100, format.percent), text_color = bearCss.tosolid(), text_size = table_size)

    //—————————————————————————–}
    //Plots
    //—————————————————————————–{
    //Dynamic Bull FVG
    max_bull_plot = plot(max_bull_fvg, color = na)
    min_bull_plot = plot(min_bull_fvg, color = na)
    fill(max_bull_plot, min_bull_plot, color = bullCss)

    //Dynamic Bear FVG
    max_bear_plot = plot(max_bear_fvg, color = na)
    min_bear_plot = plot(min_bear_fvg, color = na)
    fill(max_bear_plot, min_bear_plot, color = bearCss)

    //—————————————————————————–}
    //Alerts
    //—————————————————————————–{
    alertcondition(bull_count > bull_count[1], ‘Bullish FVG’, ‘Bullish FVG detected’)
    alertcondition(bear_count > bear_count[1], ‘Bearish FVG’, ‘Bearish FVG detected’)

    alertcondition(bull_mitigated > bull_mitigated[1], ‘Bullish FVG Mitigation’, ‘Bullish FVG mitigated’)
    alertcondition(bear_mitigated > bear_mitigated[1], ‘Bearish FVG Mitigation’, ‘Bearish FVG mitigated’)

    //—————————————————————————–}

    #239385 quote
    yas
    Participant
    Junior

    hi

    can anyone be able to convert the above code into pro real time please if possibe

    many thanks

    #239400 quote
    yas
    Participant
    Junior

    I have converted the above code in chatGPT PRO REAL TIME but it has some errors if you guys can help me diagnose this

    // Fair Value Gap (FVG) Detection

    // Inputs
    thresholdPer = 0.01 // Threshold percentage (as 1%)
    extend = 20 // Number of bars to extend the FVG boxes
    showLast = 5 // Unmitigated levels to show
    mitigationLevels = 1 // Show mitigation levels (1 or 0)

    // Colors for FVGs
    bullCss = RGB(8, 153, 129) // Bullish color
    bearCss = RGB(242, 54, 69) // Bearish color

    // Detect bullish and bearish FVGs
    bull_fvg = (low > high[2] AND close[1] > high[2] AND (low – high[2]) / high[2] > thresholdPer)
    bear_fvg = (high < low[2] AND close[1] < low[2] AND (low[2] – high) / high > thresholdPer)

    // Drawing FVG boxes
    n = barindex

    IF bull_fvg THEN
    DRAWRECTANGLE(n-2, high[2], n+extend, low, bullCss, 70) // Draw bullish box
    ENDIF

    IF bear_fvg THEN
    DRAWRECTANGLE(n-2, high, n+extend, low[2], bearCss, 70) // Draw bearish box
    ENDIF

    // Mitigation logic: check if price crosses the FVG level, then draw mitigation lines
    FOR i = 0 TO showLast-1 DO
    IF close < low AND bull_fvg THEN
    DRAWHLINE(low, bullCss) // Draw mitigated line for bullish FVG
    ELSIF close > high AND bear_fvg THEN
    DRAWHLINE(high, bearCss) // Draw mitigated line for bearish FVG
    ENDIF
    NEXT

    // Return the close price to maintain functionality
    RETURN close

    #239422 quote
    Iván González
    Moderator
    Master

    Hi. Translations take time… be patient please 🙂

    ChatGPT doesn’t make good translations from TV to probuilder when code is complicated …

    Here you have and aprox. not optimized:

    //---------------------------------------------//
    //PRC_Fair Value Gap
    //version = 0
    //24.10.2024
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    //---------------------------------------------//
    //--------------Inputs-------------------------//
    //---------------------------------------------//
    thresholdPer=0 //% threshold
    auto=0 //Boolean.
    dynamic=0 //Boolean.
    extend=20
    mitigationsLevels=1 //Boolean.
    //---------------------------------------------//
    //--------------Threshold Level----------------//
    //---------------------------------------------//
    if barindex>0 and auto then
    threshold=summation[barindex]((high-low)/low)/barindex
    else
    threshold=thresholdPer/100
    endif
    //---------------------------------------------//
    //--------------FVG Detection------------------//
    //---------------------------------------------//
    bullFvg=low > high[2] and close[1] > high[2] and (low - high[2]) / high[2] > threshold
    bearFvg=high < low[2] and close[1] < low[2] and (low[2] - high) / high > threshold
    
    if bullFvg then
    newFvgmax=low
    newFvgmin=high[2]
    newFvgisbull=1
    newFvgx=barindex
    r=8
    g=153
    b=129
    a=0
    elsif bearFvg then
    newFvgmax=low[2]
    newFvgmin=high
    newFvgisbull=0
    newFvgx=barindex
    r=244
    g=54
    b=69
    a=0
    else
    a=100
    endif
    //---------------------------------------------//
    //---------------Bull FVG's--------------------//
    //---------------------------------------------//
    if bullFvg and newFvgx<>t then
    
    if dynamic then
    maxbullFvg=newFvgmax
    minbullFvg=newFvgmin
    endif
    if dynamic=0 then
    $boxleft[z+1]=barindex[2]
    $boxrigth[z+1]=barindex+extend
    $boxbot[z+1]=newFvgmin
    $boxTop[z+1]=newFvgmax
    endif
    $newFvgmax[z+1]=newFvgmax
    $newFvgmin[z+1]=newFvgmin
    $newFvgisbull[z+1]=newFvgisbull
    $newFvgx[z+1]=newFvgx
    
    z=z+1
    bullcount=bullcount+1
    t=newFvgx
    elsif dynamic then
    maxBullFvg=max(min(close,maxBullFvg),minBullFvg)
    endif
    //---------------------------------------------//
    //---------------Bear FVG's--------------------//
    //---------------------------------------------//
    if bearFvg and newFvgx<>t then
    if dynamic then
    maxbearFvg=newFvgmax
    minbearFvg=newFvgmin
    endif
    if dynamic=0 then
    $boxleft[z+1]=barindex[2]
    $boxrigth[z+1]=barindex+extend
    $boxbot[z+1]=newFvgmin
    $boxTop[z+1]=newFvgmax
    endif
    $newFvgmax[z+1]=newFvgmax
    $newFvgmin[z+1]=newFvgmin
    $newFvgisbull[z+1]=newFvgisbull
    $newFvgx[z+1]=newFvgx
    
    z=z+1
    bearcount=bearcount+1
    t=newFvgx
    elsif dynamic then
    minBearFvg=min(max(close,minBearFvg),maxBearFvg)
    endif
    //---------------------------------------------//
    //--------------Mitigated lines----------------//
    //---------------------------------------------//
    if z>0 then
    //Test for mitigation
    for i=z-1 downto 0 do
    
    if $newFvgisbull[i]=1 and close < $newFvgmin[i] then
    if mitigationsLevels then
    drawsegment($newFvgx[i],$newFvgmin[i],barindex,$newFvgmin[i])coloured(8,153,129)style(dottedline)
    endif
    if dynamic=0 then
    $boxleft[i]=undefined
    $boxrigth[i]=undefined
    $boxbot[i]=undefined
    $boxTop[i]=undefined
    endif
    $newFvgmax[i]=undefined
    $newFvgmin[i]=undefined
    $newFvgisbull[i]=undefined
    $newFvgx[i]=undefined
    bullMitigated=bullMitigated+1
    
    elsif $newFvgisbull[i]=0 and close > $newFvgmax[i] then
    if mitigationsLevels then
    drawsegment($newFvgx[i],$newFvgmin[i],barindex,$newFvgmin[i])coloured(242,54,69)style(dottedline)
    endif
    if dynamic=0 then
    $boxleft[i]=undefined
    $boxrigth[i]=undefined
    $boxbot[i]=undefined
    $boxTop[i]=undefined
    endif
    $newFvgmax[i]=undefined
    $newFvgmin[i]=undefined
    $newFvgisbull[i]=undefined
    $newFvgx[i]=undefined
    bearMitigated=bearMitigated+1
    
    endif
    next
    endif
    //---------------------------------------------//
    //-------------Unmitigated lines---------------//
    //---------------------------------------------//
    if islastbarupdate and z>0 and dynamic=0 then
    for i=z downto 0 do
    drawrectangle($boxleft[i],$boxbot[i],$boxrigth[i],$boxTop[i])fillcolor("orange",25)coloured("orange",0)
    next
    endif
    //---------------------------------------------//
    //----------Plot Dynamic Bull FVG--------------//
    //---------------------------------------------//
    if dynamic then
    if newFvgisbull then
    colorbetween($newFvgmax[z],$newFvgmin[z],r,g,b,a)
    else
    colorbetween($newFvgmax[z],$newFvgmin[z],r,g,b,a)
    endif
    endif
    //---------------------------------------------//
    return
    
    #239443 quote
    yas
    Participant
    Junior

    Thank you ivan much appreciated

    #240089 quote
    Maricarmen
    Participant
    Junior

    How to modify the indicator so that it shows one color when going down and a different color when going up.

    #252175 quote
    bertrandpinoy
    Participant
    Veteran

    Hello,

    is it an FVG that can be translated by you? If you have enough time of course. Thanks

    https://in.tradingview.com/script/p86jWs6i-Multi-TF-FVG-Kerze-Break-Alert

     

    ///@version=6
    indicator(“Multi-TF FVG Kerze Break Alert”, overlay=true)

    // === Inputs ===
    tfList = input.string(“2,5,15”, “Timeframes (Comma separated)”)
    alertOnce = input.bool(true, “Alarm nur einmal pro Pattern”)

    // Funktion: FVG + Kerze, die hineinragt + späterer Bruch
    fvgSignal(_high, _low, _close) =>
    fvgBull = _low[1] > _high[2]
    candleInFVG = fvgBull and _low < _low[1] and _high > _low[1]
    var float candleLevel = na
    var bool monitor = false

    if candleInFVG
    candleLevel := _low
    monitor := true

    fvgBroken = monitor and _close < candleLevel
    [candleLevel, monitor, fvgBroken]

    // To address a compiler warning about function calls in a local scope,
    // we call the function once in the global scope. This ensures consistent
    // behavior between the main chart series and the ‘request.security’ contexts.
    // The result of this global call is not used for plotting or alerts.
    fvgSignal(high, low, close)

    // === Multi-Timeframe Processing ===
    tfArray = str.split(tfList, “,”)
    var float[] plotLevels = array.new_float()

    for tf in tfArray
    tf = str.trim(tf)
    [clvl, mon, broken] = request.security(syminfo.tickerid, tf, fvgSignal(high, low, close))

    // Nur Plot speichern, wenn Level existiert
    if not na(clvl)
    array.push(plotLevels, clvl)

    // Alarm
    if broken
    alert(“FVG Kerze im ” + tf + ” Timeframe gebrochen!”, alert.freq_once_per_bar_close)

    // === Plot Level für Übersicht (festes title, max 3 Timeframes) ===
    level1 = array.size(plotLevels) > 0 ? array.get(plotLevels, 0) : na
    level2 = array.size(plotLevels) > 1 ? array.get(plotLevels, 1) : na
    level3 = array.size(plotLevels) > 2 ? array.get(plotLevels, 2) : na

    plot(level1, title=”Candle Level 1″, color=color.new(color.green,0))
    plot(level2, title=”Candle Level 2″, color=color.new(color.blue,0))
    plot(level3, title=”Candle Level 3″, color=color.new(color.orange,0))

    #252453 quote
    Iván González
    Moderator
    Master
    // ============================================================
    // PRC - Multi-TF FVG Candle Break Alert
    // version = 1
    // 10.10.2025
    // Iván González @ www.prorealcode.com
    // Sharing ProRealTime knowledge
    // ============================================================
    // === Procesamiento Multi-Timeframe ===
    // ============================================================
    // --- Bloque para Timeframe 1 ---
    TIMEFRAME(15mn, updateonclose)
    ONCE monitor1 = 0
    ONCE candleLevel1 = 0
    ONCE plotLevel1 = 0
    ONCE broken1 = 0
    
    htf1 = high
    ltf1 = low
    ctf1 = close
    
    fvgBull1 = ltf1[1] > htf1[2]
    
    candleInFVG1 = fvgBull1 AND ltf1 < ltf1[1] AND htf1 > ltf1[1]
    
    IF candleInFVG1 AND monitor1 = 0 THEN
       candleLevel1 = ltf1
       monitor1 = 1
    ENDIF
    
    fvgBroken1 = monitor1 AND ctf1 < candleLevel1
    
    IF fvgBroken1 THEN
       plotLevel1 = candleLevel1
       broken1 = 1
       monitor1 = 0
       candleLevel1 = 0
    ELSE
       broken1 = 0
    ENDIF
    // ============================================================
    // --- Bloque para Timeframe 2 ---
    TIMEFRAME(1h, updateonclose)
    ONCE monitor2 = 0
    ONCE candleLevel2 = 0
    ONCE plotLevel2 = 0
    ONCE broken2 = 0
    htf2 = high
    ltf2 = low
    ctf2 = close
    
    fvgBull2 = ltf2[1] > htf2[2]
    candleInFVG2 = fvgBull2 AND ltf2 < ltf2[1] AND htf2 > ltf2[1]
    
    IF candleInFVG2 AND monitor2 = 0 THEN
       candleLevel2 = ltf2
       monitor2 = 1
    ENDIF
    
    fvgBroken2 = monitor2 AND ctf2 < candleLevel2
    
    IF fvgBroken2 THEN
       plotLevel2 = candleLevel2
       broken2 = 1
       monitor2 = 0
       candleLevel2 = 0
    ELSE
       broken2 = 0
    ENDIF
    // ============================================================
    // --- Bloque para Timeframe 3 ---
    TIMEFRAME(4h, updateonclose)
    ONCE monitor3 = 0
    ONCE candleLevel3 = 0
    ONCE plotLevel3 = 0
    ONCE broken3 = 0
    
    htf3 = high
    ltf3 = low
    ctf3 = close
    
    fvgBull3 = ltf3[1] > htf3[2]
    candleInFVG3 = fvgBull3 AND ltf3 < ltf3[1] AND htf3 > ltf3[1]
    
    IF candleInFVG3 AND monitor3 = 0 THEN
       candleLevel3 = ltf3
       monitor3 = 1
    ENDIF
    
    fvgBroken3 = monitor3 AND ctf3 < candleLevel3
    
    IF fvgBroken3 THEN
       plotLevel3 = candleLevel3
       broken3 = 1
       monitor3 = 0
       candleLevel3 = 0
    ELSE
       broken3 = 0
    ENDIF
    timeframe(default)
    // ============================================================
    // === Dibujo de Niveles y Alertas Visuales ===
    // ============================================================
    IF plotLevel1 > 0 THEN
       DRAWHLINE(plotLevel1) COLOURED(0,255,0)
    ENDIF
    
    IF plotLevel2 > 0 THEN
       DRAWHLINE(plotLevel2) COLOURED(0,0,255)
    ENDIF
    
    IF plotLevel3 > 0 THEN
       DRAWHLINE(plotLevel3) COLOURED(255,165,0)
    ENDIF
    
    IF (broken1 AND NOT broken1[1]) OR (broken2 AND NOT broken2[1]) OR (broken3 AND NOT broken3[1]) THEN
       DRAWARROWDOWN(barindex, high+2*pipsize) COLOURED(255,0,0)
    ENDIF
    // ============================================================
    RETURN
    
    bertrandpinoy thanked this post
Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.

Convert FVG TO Pro Real Time Please


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
yas @yas Participant
Summary

This topic contains 7 replies,
has 4 voices, and was last updated by Iván González
3 months, 3 weeks ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 10/18/2024
Status: Active
Attachments: No files
Logo Logo
Loading...