Volume Weighted Average Price (VWAP) with Extras [starlord_xrp]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © starlord_xrp

//@version=5
indicator("Volume Weighted Average Price with Extras", "VWAP+", overlay = true)

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//% Price Change by [OrganicPunch]
//
// To visually evaluate the % change in price between two candles

pc_ema_lenght = input.int(7, title="Price Change EMA", minval=1)
pc_display_toggle = input.bool(false, "Two-side display")
pc_price_increase = (close - close[1]) / close[1] * 100
pc_price_decrease = (close[1] - close) / close * 100
pc_price_up = close > close[1] 
pc_price_change = pc_price_up ? pc_price_increase : pc_price_decrease
pc_price_change2 = pc_price_up ? pc_price_increase : -pc_price_decrease
pc_price_toggle = pc_display_toggle ? pc_price_change2 : pc_price_change
pc_color = pc_price_up ? color(color.green) : color(color.red)
pc_ema = ta.ema(pc_price_toggle, pc_ema_lenght)

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Volume Weighted Average Price
hideonDWM = input(false, title="Hide VWAP on 1D or Above", group="VWAP Settings")
var anchor = input.string(defval = "Percent Change", title="Anchor Period", options=["Percent Change", "Extreme", "Low", "High", "Session", "Week", "Month", "Quarter", "Year", "Decade", "Century", "Earnings", "Dividends", "Splits"], group="VWAP Settings")
src = input(title = "Source", defval = hlc3, group="VWAP Settings")
offset = input(0, title="Offset", group="VWAP Settings")

lookback = input(100, "Lookback length for High and Low", group = "Extra Settings")
check_percent = input(1.00, "Threshhold for price Percent Change", group = "Extra Settings")

showBand_1 = input(true, title="", group="Standard Deviation Bands Settings", inline="band_1")
stdevMult_1 = input(1.0, title="Bands Multiplier #1", group="Standard Deviation Bands Settings", inline="band_1")
showBand_2 = input(false, title="", group="Standard Deviation Bands Settings", inline="band_2")
stdevMult_2 = input(2.0, title="Bands Multiplier #2", group="Standard Deviation Bands Settings", inline="band_2")
showBand_3 = input(false, title="", group="Standard Deviation Bands Settings", inline="band_3")
stdevMult_3 = input(3.0, title="Bands Multiplier #3", group="Standard Deviation Bands Settings", inline="band_3")

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)

var float lowest_number = high
var float highest_number = low

if ta.change(dayofmonth) and dayofweek == dayofweek.saturday
    lowest_number := high
    highest_number:= low

high_check = ta.highest(high, lookback)
low_check = ta.lowest(low, lookback)
if low_check < lowest_number
    lowest_number := low_check

if high_check > highest_number
    highest_number := high_check

bool new_low = na
bool new_high = na
bool new_extreme = na
bool new_percent = na

if (ta.change(lowest_number))
    new_low := true

if (ta.change(highest_number))
    new_high := true

if (new_high or new_low)
    new_extreme := true

if (pc_price_toggle > 1.00)
    new_percent := true

isNewPeriod = switch anchor
    "Percent Change"   => not na(new_percent)
    "Extreme"   => not na(new_extreme)
    "Low"       => not na(new_low)
    "High"      => not na(new_high) 
	"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
	upperBandValue1 := _vwap + stdevAbs * stdevMult_1
	lowerBandValue1 := _vwap - stdevAbs * stdevMult_1
	upperBandValue2 := _vwap + stdevAbs * stdevMult_2
	lowerBandValue2 := _vwap - stdevAbs * stdevMult_2
	upperBandValue3 := _vwap + stdevAbs * stdevMult_3
	lowerBandValue3 := _vwap - stdevAbs * stdevMult_3

plot(vwapValue, title="VWAP", color=#2962FF, 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)