0% found this document useful (0 votes)
63 views5 pages

FVG With Supertrend

FVG WITh ST

Uploaded by

joydiprudra19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views5 pages

FVG With Supertrend

FVG WITh ST

Uploaded by

joydiprudra19
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

//@version=5

indicator("Fair Value Gap by Happy Trading", overlay = true, max_lines_count = 500,


max_boxes_count = 500)

// Fair Value Gap Base Code


//------------------------------------------------------------------------------
//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
//-----------------------------------------------------------------------------{
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))

//-----------------------------------------------------------------------------}
//EMAs
//-----------------------------------------------------------------------------{
ema1Length = input.int(9, "EMA 1 Length")
ema2Length = input.int(21, "EMA 2 Length")
ema3Length = input.int(50, "EMA 3 Length")

ema1 = ta.ema(close, ema1Length)


ema2 = ta.ema(close, ema2Length)
ema3 = ta.ema(close, ema3Length)
plot(ema1, color=color.blue, title="EMA 1")
plot(ema2, color=color.red, title="EMA 2")
plot(ema3, color=color.green, title="EMA 3")

//-----------------------------------------------------------------------------}
//Bollinger Bands
//-----------------------------------------------------------------------------{
bbLength = input.int(20, "BB Length")
bbStdDev = input.float(2.0, "BB StdDev")

[bbBasis, bbUpper, bbLower] = ta.bb(close, bbLength, bbStdDev)

plot(bbBasis, color=color.orange, title="BB Basis")


plot(bbUpper, color=color.red, title="BB Upper")
plot(bbLower, color=color.green, title="BB Lower")

fill(plot(bbUpper, color=color.red), plot(bbLower, color=color.green),


color=color.new(color.blue, 90))

//-----------------------------------------------------------------------------}
//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")

hoursSinceLastCandle = (time[0] - time[1]) / 1000 / 60 / 60

myOpen = open
myClose = close
myHigh = high
myLow = low

if not applyToDayOpenOnly or hoursSinceLastCandle > dayChangeHourThreshold


myOpen := close[1]
myClose := close
myHigh := high
myLow := low

candleColor = myOpen <= myClose ? color.teal : color.red

plotcandle(myOpen, myHigh, myLow, myClose, color=candleColor,


bordercolor=candleColor, wickcolor=candleColor)

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)

length1 = input.int(title = "ATR_P1", defval = 10, minval = 1, maxval = 10, step =


1)
length2 = input.int(title = "ATR_P2", defval = 10, minval = 1, maxval = 10, step =
1)
length3 = input.int(title = "ATR_P3", defval = 10, minval = 1, maxval = 10, step =
1)
FACTOR1 = input.int(title = "FACTOR1", defval = 3, minval = 1, maxval = 3, step =
1)
FACTOR2 = input.int(title = "FACTOR2", defval = 3, minval = 1, maxval = 3, step =
1)
FACTOR3 = input.int(title = "FACTOR3", defval = 3, minval = 1, maxval = 3, step =
1)

S_D = input.timeframe(title = "S_D", defval = "D")


S_W = input.timeframe(title = "S_W", defval = "W")
S_M = input.timeframe(title = "S_M", defval = "M")

// TRADING INDICATORS

[Supertrend1, direction1] = ta.supertrend(FACTOR1,length1)


[Supertrend2, direction2] = ta.supertrend(FACTOR2,length2)
[Supertrend3, direction3] = ta.supertrend(FACTOR3,length3)

Supertrend_d = request.security(syminfo.tickerid, S_D,


Supertrend1[barstate.isrealtime ? 1 : 0])
Supertrend_w = request.security(syminfo.tickerid, S_W,
Supertrend2[barstate.isrealtime ? 1 : 0])
Supertrend_m = request.security(syminfo.tickerid, S_M,
Supertrend3[barstate.isrealtime ? 1 : 0])

plot(Supertrend_d, color = direction1 == -1 ? color.new(color.green,0) :


color.new(color.red,0))
plot(Supertrend_w, color = direction2 == -1 ? color.new(color.green,0) :
color.new(color.red,0))
plot(Supertrend_m, color = direction3 == -1 ? color.new(color.green,0) :
color.new(color.red,0))

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy