OPEN-SOURCE SCRIPT
EMA Bollinger Bands with FVG Boxes Outside

//version=6
indicator("EMA Bollinger Bands with FVG Boxes Outside", overlay=true)
// Input parameters
length = input.int(50, "EMA Length")
mult = input.float(2.0, "Bollinger Band Multiplier", step=0.1)
fvg_color_up = input.color(color.new(color.green, 80), "FVG Up Box Color")
fvg_color_down = input.color(color.new(color.red, 80), "FVG Down Box Color")
extension_length = input.int(3, "Box Extension Bars to Right", minval=0, maxval=50)
// Calculate EMA and EMA-based Bollinger Bands
ema_val = ta.ema(close, length)
dev = mult * ta.stdev(close, length)
upper_band = ema_val + dev
lower_band = ema_val - dev
// Plot EMA Bollinger Bands
plot(upper_band, "Upper Band", color=color.blue)
plot(ema_val, "EMA", color=color.orange)
plot(lower_band, "Lower Band", color=color.blue)
// Function to detect Fair Value Gaps (FVG)
// Bullish FVG when low of current bar > high of bar 2 bars ago
fvg_up = low > high[2]
// Bearish FVG when high of current bar < low of bar 2 bars ago
fvg_down = high < low[2]
// Check if FVG is outside Bollinger Bands
fvg_up_outside = fvg_up and low > upper_band
fvg_down_outside = fvg_down and high < lower_band
// Draw bullish FVG box, extended to the right by extension_length bars
if (fvg_up_outside)
box.new(left=bar_index[2], top=high[2], right=bar_index + extension_length, bottom=low, bgcolor=fvg_color_up, border_color=fvg_color_up)
// Draw bearish FVG box, extended to the right by extension_length bars
if (fvg_down_outside)
box.new(left=bar_index[2], top=low[2], right=bar_index + extension_length, bottom=high, bgcolor=fvg_color_down, border_color=fvg_color_down)
indicator("EMA Bollinger Bands with FVG Boxes Outside", overlay=true)
// Input parameters
length = input.int(50, "EMA Length")
mult = input.float(2.0, "Bollinger Band Multiplier", step=0.1)
fvg_color_up = input.color(color.new(color.green, 80), "FVG Up Box Color")
fvg_color_down = input.color(color.new(color.red, 80), "FVG Down Box Color")
extension_length = input.int(3, "Box Extension Bars to Right", minval=0, maxval=50)
// Calculate EMA and EMA-based Bollinger Bands
ema_val = ta.ema(close, length)
dev = mult * ta.stdev(close, length)
upper_band = ema_val + dev
lower_band = ema_val - dev
// Plot EMA Bollinger Bands
plot(upper_band, "Upper Band", color=color.blue)
plot(ema_val, "EMA", color=color.orange)
plot(lower_band, "Lower Band", color=color.blue)
// Function to detect Fair Value Gaps (FVG)
// Bullish FVG when low of current bar > high of bar 2 bars ago
fvg_up = low > high[2]
// Bearish FVG when high of current bar < low of bar 2 bars ago
fvg_down = high < low[2]
// Check if FVG is outside Bollinger Bands
fvg_up_outside = fvg_up and low > upper_band
fvg_down_outside = fvg_down and high < lower_band
// Draw bullish FVG box, extended to the right by extension_length bars
if (fvg_up_outside)
box.new(left=bar_index[2], top=high[2], right=bar_index + extension_length, bottom=low, bgcolor=fvg_color_up, border_color=fvg_color_up)
// Draw bearish FVG box, extended to the right by extension_length bars
if (fvg_down_outside)
box.new(left=bar_index[2], top=low[2], right=bar_index + extension_length, bottom=high, bgcolor=fvg_color_down, border_color=fvg_color_down)
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.