//@version=5
indicator(‘Moj FVG i Fractals’, overlay = true)
// === FVG Inputs ===
fvg_border_color = input.color(color.yellow, “FVG Border Color”)
fvg_bg_color = input.color(color.new(color.yellow, 90), “FVG Bg Color”)
fvg_bar_color = input.color(color.yellow, “FVG Bar Color”)
// === FVG Logic ===
fvg_up_gap = close[1] > open[1] ? low – high[2] : na
fvg_down_gap = close[1] < open[1] ? low[2] – high : na
fvg_up_box = fvg_up_gap > 0 ? box.new(left = bar_index[2], top = high[2], right = bar_index, bottom = low, border_color = fvg_border_color, bgcolor = fvg_bg_color) : na
fvg_down_box = fvg_down_gap > 0 ? box.new(left = bar_index[2], top = low[2], right = bar_index, bottom = high, border_color = fvg_border_color, bgcolor = fvg_bg_color) : na
// === Bar Colors for FVG ===
barcolor(fvg_up_gap > 0 ? fvg_bar_color : na, offset = -1)
barcolor(fvg_down_gap > 0 ? fvg_bar_color : na, offset = -1)
// === Fractal Inputs ===
showPatterns = input(true, “Show Fractal Patterns”)
filterBW = input(false, title=”Bill Williams Fractals Filter”)
// === Fractal Recognition Functions ===
isRegularFractal(mode) =>
mode == 1 ? high[4] < high[3] and high[3] < high[2] and high[2] > high[1] and high[1] > high[0] :mode == -1 ? low[4] > low[3] and low[3] > low[2] and low[2] < low[1] and low[1] < low[0] : false
isBWFractal(mode) =>
mode == 1 ? high[4] < high[2] and high[3] <= high[2] and high[2] >= high[1] and high[2] > high[0] :mode == -1 ? low[4] > low[2] and low[3] >= low[2] and low[2] <= low[1] and low[2] < low[0] : false
filteredtopf = filterBW ? isRegularFractal(1) : isBWFractal(1)
filteredbotf = filterBW ? isRegularFractal(-1) : isBWFractal(-1)
// === Plot Fractals ===
plotshape(filteredtopf, title=’Filtered Top Fractals’, style=shape.triangledown, location=location.abovebar, color=color.red, offset=-2)
plotshape(filteredbotf, title=’Filtered Bottom Fractals’, style=shape.triangleup, location=location.belowbar, color=color.green, offset=-2)