FVG With Supertrend
FVG With Supertrend
tf = input.timeframe('', "Timeframe")
//Style
extend = input.int(20, 'Extend', minval = 0, inline = 'extend', group = 'Style')
dynamic = input(false, 'Dynamic', inline = 'extend', 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
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)
//-----------------------------------------------------------------------------}
//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
//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
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
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
//-----------------------------------------------------------------------------{
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)
//-----------------------------------------------------------------------------}
//EMAs
//-----------------------------------------------------------------------------{
ema1Length = input.int(9, "EMA 1 Length")
ema2Length = input.int(21, "EMA 2 Length")
ema3Length = input.int(50, "EMA 3 Length")
//-----------------------------------------------------------------------------}
//Bollinger Bands
//-----------------------------------------------------------------------------{
bbLength = input.int(20, "BB Length")
bbStdDev = input.float(2.0, "BB StdDev")
//-----------------------------------------------------------------------------}
//No Gap Candles
//-----------------------------------------------------------------------------{
applyToDayOpenOnly = input(false, title="Apply to day open only")
dayChangeHourThreshold = input(6, title="Hour threshold to detect the day open")
showPriceLine = input(true, title="Show price line")
myOpen = open
myClose = close
myHigh = high
myLow = low
if barstate.islast
if showPriceLine
line.new(bar_index - 4999, close, bar_index + 500, close,
color=candleColor, style=line.style_dotted, width=1)
//-----------------------------------------------------------------------------}
// USER INPUT (SUPERTREND)
// TRADING INDICATORS