0% found this document useful (0 votes)
132 views7 pages

Umesh

Uploaded by

aaryinfo
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)
132 views7 pages

Umesh

Uploaded by

aaryinfo
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/ 7

//@version=5

//indicator(title="Volume Weighted Average Price", shorttitle="VWAP", overlay=true,


timeframe="", timeframe_gaps=true,overlay = true, max_lines_count = 500,
max_boxes_count = 500)
indicator("Fair Value Gap [LuxAlgo]", "Gap", overlay = true, max_lines_count = 500,
max_boxes_count = 500)
hideonDWM = input(false, title="Hide VWAP on 1D or Above", group="VWAP Settings",
display = display.data_window)
var anchor = input.string(defval = "Session", title="Anchor Period",
options=["Session", "Week", "Month", "Quarter", "Year", "Decade", "Century",
"Earnings", "Dividends", "Splits"], group="VWAP Settings")
src = input(title = "Source", defval = hlc3, group="VWAP Settings", display =
display.data_window)
offset = input.int(0, title="Offset", group="VWAP Settings", minval=0, display =
display.data_window)

BANDS_GROUP = "Bands Settings"


CALC_MODE_TOOLTIP = "Determines the units used to calculate the distance of the
bands. When 'Percentage' is selected, a multiplier of 1 means 1%."
calcModeInput = input.string("Standard Deviation", "Bands Calculation Mode",
options = ["Standard Deviation", "Percentage"], group = BANDS_GROUP, tooltip =
CALC_MODE_TOOLTIP, display = display.data_window)
showBand_1 = input(true, title = "", group = BANDS_GROUP, inline = "band_1",
display = display.data_window)
bandMult_1 = input.float(1.0, title = "Bands Multiplier #1", group = BANDS_GROUP,
inline = "band_1", step = 0.5, minval=0, display = display.data_window)
showBand_2 = input(false, title = "", group = BANDS_GROUP, inline = "band_2",
display = display.data_window)
bandMult_2 = input.float(2.0, title = "Bands Multiplier #2", group = BANDS_GROUP,
inline = "band_2", step = 0.5, minval=0, display = display.data_window)
showBand_3 = input(false, title = "", group = BANDS_GROUP, inline = "band_3",
display = display.data_window)
bandMult_3 = input.float(3.0, title = "Bands Multiplier #3", group = BANDS_GROUP,
inline = "band_3", step = 0.5, minval=0, display = display.data_window)

if barstate.islast and ta.cum(volume) == 0


runtime.error("No volume is provided by the data vendor.")

new_earnings = request.earnings(syminfo.tickerid, earnings.actual,


barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true)
new_dividends = request.dividends(syminfo.tickerid, dividends.gross,
barmerge.gaps_on, barmerge.lookahead_on, ignore_invalid_symbol=true)
new_split = request.splits(syminfo.tickerid, splits.denominator, barmerge.gaps_on,
barmerge.lookahead_on, ignore_invalid_symbol=true)

isNewPeriod = switch anchor


"Earnings" => not na(new_earnings)
"Dividends" => not na(new_dividends)
"Splits" => not na(new_split)
"Session" => timeframe.change("D")
"Week" => timeframe.change("W")
"Month" => timeframe.change("M")
"Quarter" => timeframe.change("3M")
"Year" => timeframe.change("12M")
"Decade" => timeframe.change("12M") and year % 10 == 0
"Century" => timeframe.change("12M") and year % 100 == 0
=> false

isEsdAnchor = anchor == "Earnings" or anchor == "Dividends" or anchor == "Splits"


if na(src[1]) and not isEsdAnchor
isNewPeriod := true

float vwapValue = na
float upperBandValue1 = na
float lowerBandValue1 = na
float upperBandValue2 = na
float lowerBandValue2 = na
float upperBandValue3 = na
float lowerBandValue3 = na

if not (hideonDWM and timeframe.isdwm)


[_vwap, _stdevUpper, _] = ta.vwap(src, isNewPeriod, 1)
vwapValue := _vwap
stdevAbs = _stdevUpper - _vwap
bandBasis = calcModeInput == "Standard Deviation" ? stdevAbs : _vwap * 0.01
upperBandValue1 := _vwap + bandBasis * bandMult_1
lowerBandValue1 := _vwap - bandBasis * bandMult_1
upperBandValue2 := _vwap + bandBasis * bandMult_2
lowerBandValue2 := _vwap - bandBasis * bandMult_2
upperBandValue3 := _vwap + bandBasis * bandMult_3
lowerBandValue3 := _vwap - bandBasis * bandMult_3

plot(vwapValue, title="VWAP", color=color.green, offset=offset)

//upperBand_1 = plot(upperBandValue1, title="Upper Band #1", color=color.green,


offset=offset, display = showBand_1 ? display.all : display.none)
//lowerBand_1 = plot(lowerBandValue1, title="Lower Band #1", color=color.green,
offset=offset, display = showBand_1 ? display.all : display.none)
//fill(upperBand_1, lowerBand_1, title="Bands Fill #1", color=
color.new(color.green, 95) , display = showBand_1 ? display.all : display.none)

//upperBand_2 = plot(upperBandValue2, title="Upper Band #2", color=color.olive,


offset=offset, display = showBand_2 ? display.all : display.none)
//lowerBand_2 = plot(lowerBandValue2, title="Lower Band #2", color=color.olive,
offset=offset, display = showBand_2 ? display.all : display.none)
//fill(upperBand_2, lowerBand_2, title="Bands Fill #2", color=
color.new(color.olive, 95) , display = showBand_2 ? display.all : display.none)

//upperBand_3 = plot(upperBandValue3, title="Upper Band #3", color=color.teal,


offset=offset, display = showBand_3 ? display.all : display.none)
//lowerBand_3 = plot(lowerBandValue3, title="Lower Band #3", color=color.teal,
offset=offset, display = showBand_3 ? display.all : display.none)
//fill(upperBand_3, lowerBand_3, title="Bands Fill #3", color=
color.new(color.teal, 95) , display = showBand_3 ? display.all : display.none)
len = input.int(9, minval=1, title="Length")
src1 = input(close, title="Source")
offset1 = input.int(title="Offset", defval=0, minval=-500, maxval=500, display =
display.data_window)
out = ta.ema(src1, len)
plot(out, title="EMA", color=color.yellow, offset=offset)

ma(source, length, type) =>


switch type
"SMA" => ta.sma(source, length)
"EMA" => ta.ema(source, length)
"SMMA (RMA)" => ta.rma(source, length)
"WMA" => ta.wma(source, length)
"VWMA" => ta.vwma(source, length)
typeMA = input.string(title = "Method", defval = "SMA", options=["SMA", "EMA",
"SMMA (RMA)", "WMA", "VWMA"], group="Smoothing", display = display.data_window)
smoothingLength = input.int(title = "Length", defval = 5, minval = 1, maxval = 100,
group="Smoothing", display = display.data_window)

smoothingLine = ma(out, smoothingLength, typeMA)


plot(smoothingLine, title="Smoothing Line", color=#f37f20, offset=offset1,
display=display.none)

length = input.int(20, minval=1)


maType = input.string("SMA", "Basis MA Type", options = ["SMA", "EMA", "SMMA
(RMA)", "WMA", "VWMA"])
src2 = input(close, title="Source")
mult = input.float(2.0, minval=0.001, maxval=50, title="StdDev")

basis = ma(src2, length, maType)


dev = mult * ta.stdev(src2, length)
upper = basis + dev
lower = basis - dev
offset2 = input.int(0, "Offset", minval = -500, maxval = 500, display =
display.data_window)
plot(basis, "Basis", color=#2962FF, offset = offset2)
p1 = plot(upper, "Upper", color=#F23645, offset = offset2)
p2 = plot(lower, "Lower", color=#089981, offset = offset2)
//fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 95))

//-------------------------------------------------------------------------------
New Indicator
//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_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
//-----------------------------------------------------------------------------{
//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_right

var table_size = textSize == 'Tiny' ? size.tiny


: textSize == 'Small' ? size.small
: size.normal

var 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')

//-----------------------------------------------------------------------------}

You might also like