Convert FVG TO Pro Real Time Please
Forums › ProRealTime English forum › ProBuilder support › Convert FVG TO Pro Real Time Please
- This topic has 4 replies, 2 voices, and was last updated 6 days ago by yas.
-
-
10/18/2024 at 10:42 AM #239182
// 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_indexmethod 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 / 100bull_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 > thresholdif 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 = 0var 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_rightvar table_size = textSize == ‘Tiny’ ? size.tiny
: textSize == ‘Small’ ? size.small
: size.normalvar 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’)//—————————————————————————–}
10/23/2024 at 8:30 PM #23938510/24/2024 at 10:58 AM #239400I 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 = barindexIF bull_fvg THEN
DRAWRECTANGLE(n-2, high[2], n+extend, low, bullCss, 70) // Draw bullish box
ENDIFIF 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 close10/24/2024 at 4:52 PM #239422Hi. 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:
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162//---------------------------------------------////PRC_Fair Value Gap//version = 0//24.10.2024//Iván González @ www.prorealcode.com//Sharing ProRealTime knowledge//---------------------------------------------////--------------Inputs-------------------------////---------------------------------------------//thresholdPer=0 //% thresholdauto=0 //Boolean.dynamic=0 //Boolean.extend=20mitigationsLevels=1 //Boolean.//---------------------------------------------////--------------Threshold Level----------------////---------------------------------------------//if barindex>0 and auto thenthreshold=summation[barindex]((high-low)/low)/barindexelsethreshold=thresholdPer/100endif//---------------------------------------------////--------------FVG Detection------------------////---------------------------------------------//bullFvg=low > high[2] and close[1] > high[2] and (low - high[2]) / high[2] > thresholdbearFvg=high < low[2] and close[1] < low[2] and (low[2] - high) / high > thresholdif bullFvg thennewFvgmax=lownewFvgmin=high[2]newFvgisbull=1newFvgx=barindexr=8g=153b=129a=0elsif bearFvg thennewFvgmax=low[2]newFvgmin=highnewFvgisbull=0newFvgx=barindexr=244g=54b=69a=0elsea=100endif//---------------------------------------------////---------------Bull FVG's--------------------////---------------------------------------------//if bullFvg and newFvgx<>t thenif dynamic thenmaxbullFvg=newFvgmaxminbullFvg=newFvgminendifif dynamic=0 then$boxleft[z+1]=barindex[2]$boxrigth[z+1]=barindex+extend$boxbot[z+1]=newFvgmin$boxTop[z+1]=newFvgmaxendif$newFvgmax[z+1]=newFvgmax$newFvgmin[z+1]=newFvgmin$newFvgisbull[z+1]=newFvgisbull$newFvgx[z+1]=newFvgxz=z+1bullcount=bullcount+1t=newFvgxelsif dynamic thenmaxBullFvg=max(min(close,maxBullFvg),minBullFvg)endif//---------------------------------------------////---------------Bear FVG's--------------------////---------------------------------------------//if bearFvg and newFvgx<>t thenif dynamic thenmaxbearFvg=newFvgmaxminbearFvg=newFvgminendifif dynamic=0 then$boxleft[z+1]=barindex[2]$boxrigth[z+1]=barindex+extend$boxbot[z+1]=newFvgmin$boxTop[z+1]=newFvgmaxendif$newFvgmax[z+1]=newFvgmax$newFvgmin[z+1]=newFvgmin$newFvgisbull[z+1]=newFvgisbull$newFvgx[z+1]=newFvgxz=z+1bearcount=bearcount+1t=newFvgxelsif dynamic thenminBearFvg=min(max(close,minBearFvg),maxBearFvg)endif//---------------------------------------------////--------------Mitigated lines----------------////---------------------------------------------//if z>0 then//Test for mitigationfor i=z-1 downto 0 doif $newFvgisbull[i]=1 and close < $newFvgmin[i] thenif mitigationsLevels thendrawsegment($newFvgx[i],$newFvgmin[i],barindex,$newFvgmin[i])coloured(8,153,129)style(dottedline)endifif dynamic=0 then$boxleft[i]=undefined$boxrigth[i]=undefined$boxbot[i]=undefined$boxTop[i]=undefinedendif$newFvgmax[i]=undefined$newFvgmin[i]=undefined$newFvgisbull[i]=undefined$newFvgx[i]=undefinedbullMitigated=bullMitigated+1elsif $newFvgisbull[i]=0 and close > $newFvgmax[i] thenif mitigationsLevels thendrawsegment($newFvgx[i],$newFvgmin[i],barindex,$newFvgmin[i])coloured(242,54,69)style(dottedline)endifif dynamic=0 then$boxleft[i]=undefined$boxrigth[i]=undefined$boxbot[i]=undefined$boxTop[i]=undefinedendif$newFvgmax[i]=undefined$newFvgmin[i]=undefined$newFvgisbull[i]=undefined$newFvgx[i]=undefinedbearMitigated=bearMitigated+1endifnextendif//---------------------------------------------////-------------Unmitigated lines---------------////---------------------------------------------//if islastbarupdate and z>0 and dynamic=0 thenfor i=z downto 0 dodrawrectangle($boxleft[i],$boxbot[i],$boxrigth[i],$boxTop[i])fillcolor("orange",25)coloured("orange",0)nextendif//---------------------------------------------////----------Plot Dynamic Bull FVG--------------////---------------------------------------------//if dynamic thenif newFvgisbull thencolorbetween($newFvgmax[z],$newFvgmin[z],r,g,b,a)elsecolorbetween($newFvgmax[z],$newFvgmin[z],r,g,b,a)endifendif//---------------------------------------------//return10/25/2024 at 6:45 AM #239443 -
AuthorPosts
Find exclusive trading pro-tools on