VWAP Indicator for Current Day Only


Category:
0
0

Hello Hahn!

I was wondering if you could help me create a VWAP Script that displays only for the current trading day. For example, if I change the time length to 10 day 15 minute chart, I only need the VWAP to show for the most recent day. Thank you so much!

Marked as spam
Posted by (Questions: 9, Answers: 4)
Asked on December 3, 2021 11:44 am
97 views
1
Private answer

The solution is very simple and can be applied to any plot you want to display on a chart:

def currentDay = GetDay() == GetLastDay();

That line of code creates a filter that limits any plot to display only on the current day. You need to insert this into your plot statements using an if/then/else statement to filter out the unwanted section of the plots.

Here is the entire code for the VWAP that plots only on the current day:

def vwapValue = reference VWAP().VWAP;
def upper = reference VWAP().UpperBand;
def lower = reference VWAP().LowerBand;
def currentDay = GetDay() == GetLastDay();
plot vwap = if currentDay then vwapValue else Double.NaN;
plot upperBand = if currentDay then upper else Double.NaN;
plot lowerBand = if currentDay then lower else Double.NaN;
vwap.setDefaultColor(getColor(0));
upperBand.setDefaultColor(getColor(2));
lowerBand.setDefaultColor(getColor(4));

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on December 3, 2021 12:08 pm