I have a script based on VWAP. Now VWAP starts at session beginning and is unreliable for first 2 15-minute candles. Since the script is based on VWAP, I need the script to record values only after say 9:45 AM i.e. disregard the first 2 15-minutes candles (Since market opening is at 9:15 in India. Also find my code below. Please suggest ways to get the desired results.
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © tradesher
//@version=5
indicator(title="Strategy arun", shorttitle="COMBOA", overlay=true)
length = input.int(title="Length", defval=14, minval=1, maxval=2000)
source = input(title="Source", defval=hlc3)
len= input.int(title="EMA Length", defval=21, minval=1, maxval=2000)
smoothingLength = input.int(title = "Length", defval = 9, minval = 1, maxval = 100, group="Smoothing")
hideonDWM = input(false, title="Hide VWAP on 1D or Above", group="VWAP Settings")
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")
offset = input(0, title="Offset", group="VWAP 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)
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
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)
//Store values of cross of price above or below SD
sd1ubreach=ta.valuewhen(ta.crossover(close,upperBandValue1),high,0)
sd1lbreach=ta.valuewhen(ta.crossunder(close,lowerBandValue1),low,0)
sd2ubreach=ta.valuewhen(ta.crossover(close,upperBandValue2),high,0)
sd2lbreach=ta.valuewhen(ta.crossunder(close,lowerBandValue2),low,0)
sd3ubreach=ta.valuewhen(ta.crossover(close,upperBandValue3),high,0)
sd3lbreach=ta.valuewhen(ta.crossunder(close,lowerBandValue3),low,0)
//plot(sd1lbreach, color=color.red,style=plot.style_line)
//mfi check
mf=ta.mfi(src,length)
//plot(mf, "MF", color=#7E57C2)
//overbought=hline(80, title="Overbought", color=#787B86)
//hline(50, "Middle Band", color=color.new(#787B86, 50))
//oversold=hline(20, title="Oversold", color=#787B86)
//fill(overbought, oversold, color=color.rgb(126, 87, 194, 90), title="Background")
averageline = ta.ema(mf,len)
//plot(averageline, "EMA", color=#1558bd, linewidth=2)
smoothing= ta.sma(averageline, smoothingLength)
//cci check
length_CCI= input.int(20, minval=1)
ma = ta.sma(src, length)
cci = (src - ma) / (0.015 * ta.dev(src, length))
//plot(cci, "CCI", color=#2962FF)
//band1 = hline(100, "Upper Band", color=#787B86, linestyle=hline.style_dashed)
//hline(0, "Middle Band", color=color.new(#787B86, 50))
//band0 = hline(-100, "Lower Band", color=#787B86, linestyle=hline.style_dashed)
//fill(band1, band0, color=color.rgb(33, 150, 243, 90), title="Background")
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")
smoothingLengthcci = input.int(title = "Length", defval = 5, minval = 1, maxval = 100, group="Smoothing")
smoothingLine = ma(cci, smoothingLength, typeMA)
//Signal plotting lines ---------------------------------------------------------------------------------------------------------------------------
b1 = sd1ubreach<close and sd1ubreach>close[1] and mf>averageline and mf>smoothing and cci>smoothingLine
plotshape(b1, title="SD1 upper breach", text="SD1_U", textcolor=color.white, style=shape.labelup, location=location.belowbar, color=color.green, transp=0, size=size.tiny)
s1 = sd1lbreach>close and sd1lbreach<close[1] and mf<averageline and mf<smoothing and cci<smoothingLine
plotshape(s1, title="SD1 lower breach", text="SD1_L", textcolor=color.white, style=shape.labeldown, location=location.abovebar, color=color.red, transp=0, size=size.tiny)
b2 = sd2ubreach<close and sd2ubreach>close[1] and mf>averageline and mf>smoothing and cci>smoothingLine
plotshape(b2, title="SD2 upper breach", text="SD2_U", textcolor=color.white, style=shape.labelup, location=location.belowbar, color=color.green, transp=0, size=size.tiny)
s2 = sd2lbreach>close and sd2lbreach<close[1] and mf<averageline and mf<smoothing and cci<smoothingLine
plotshape(s2, title="SD2 lower breach", text="SD2_L", textcolor=color.white, style=shape.labeldown, location=location.abovebar, color=color.red, transp=0, size=size.tiny)
b3 = sd3ubreach<close and sd3ubreach>close[1] and mf>averageline and mf>smoothing and cci>smoothingLine
plotshape(b3, title="SD3 upper breach", text="SD3_U", textcolor=color.white, style=shape.labelup, location=location.belowbar, color=color.green, transp=0, size=size.tiny)
s3 = sd3lbreach>close and sd3lbreach<close[1] and mf<averageline and mf<smoothing and cci<smoothingLine
plotshape(s3, title="SD3 lower breach", text="SD3_L", textcolor=color.white, style=shape.labeldown, location=location.abovebar, color=color.red, transp=0, size=size.tiny)