# Price Above or Below VWAP Watchlist Column for ThinkorSwim

#### Brain Monkey

##### New member
Just tried it works perfect on my screen.

W

#### wcsharron

##### New member
This is pretty cool @BenTen...is it possible to make it indicate/calculate a negative or positive percentage away from the VWAP? I am studying 2% as a good number for scalps.
I would love this as well - the original is great, but hard to tell strong deviations.

Thank you!

O

#### otmane

##### New member
I wanted to quickly know if the stock price is currently above or below VWAP (Volume Weighted Average Price). One of our developers were able to help me put together a watchlist column that shows just that. Here is what it looks like.

Notes:
• Green means price is currently above VWAP
• Red means price is currently below VWAP

### thinkScript Code

Rich (BB code):
``````plot vwap = vwap();
AssignBackgroundColor(if close > vwap then Color.DARK_GREEN else if close < vwap then Color.DARK_RED else Color.Dark_ORANGE);``````
Credit:
• WalkingBallista
hi ben check this one and let me know what you think

plot value =close is greater than reference VWAP("time frame" = "WEEK")."VWAP";
AssignBackgroundColor(if value == 1 then color.GREEN else color.red);
value.AssignValueColor(if value == 1 then color.BLACK else color.CURRENT);

E

#### evolernet

##### New member
Good day friends
who can help ???. this formula shows in the list where the price is now .. above or below VWAP .... is it possible to add a signal to the intersection of VWAP in cents in this script ... that is, to display stocks that crossed VWAP for a certain impulse in cents ... ..search for one bar at the intersection of VWAP for a certain number of cents plot vwap = vwap (); AssignBackgroundColor (if close> vwap then Color.DARK_GREEN else if close <vwap then Color.DARK_RED else Color.Dark_ORANGE;

P

#### Patrick_Hu

##### New member
VIP
Hi Ben,

Do you know whether I can find a script to create a column indicating whether the stock breaks yesterday high or low? If you have it, could you please share with me?

Thanks.

Staff
VIP

V

#### Vincenzo

##### New member
Hello all,

I found this code to add into my watch list to show when a stock is above VWAP:

plot vwap = vwap();

AssignBackgroundColor(if close > vwap then Color.DARK_GREEN else if close < vwap then Color.DARK_RED else Color.Dark_ORANGE);

I would like to get an alert if closes below VWAP

I have a watch list that is scanning for stocks that the last 20 five minute closes were above VWAP. I am now wanting to create a custom column in my watch list that will show me how close the stock is reaching vwap line. is this possible?

Thank you for the help

Last edited by a moderator:
C

#### C4men

##### Member
@BenTen is there a way to do this same thing for the upper band?

I typically see very bullish activity above the VWAP Upper line when set to 1 SD.

Hopeful this is an easy edit!!!

Wait - I think I figured it out!

plot VWAPUB1 = reference VWAP("num dev up" = 1.0)."UpperBand";

AssignBackgroundColor(if close > VWAPUB1 then Color.DARK_GREEN else if close < VWAPUB1 then Color.DARK_RED else Color.Dark_ORANGE);

Nope, I lied - I am still missing something...

Last edited by a moderator:

#### BenTen

Staff
VIP
@C4men Try this one:

Code:
``````#
# TD Ameritrade IP Company, Inc. (c) 2011-2020
#

input numDevDn = -1.0;
input numDevUp = 1.0;
input timeFrame = {default DAY, WEEK, MONTH};

def cap = getAggregationPeriod();
def errorInAggregation =
timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or
timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH;
assert(!errorInAggregation, "timeFrame should be not less than current chart aggregation period");

def yyyyMmDd = getYyyyMmDd();
def periodIndx;
switch (timeFrame) {
case DAY:
periodIndx = yyyyMmDd;
case WEEK:
periodIndx = Floor((daysFromDate(first(yyyyMmDd)) + getDayOfWeek(first(yyyyMmDd))) / 7);
case MONTH:
periodIndx = roundDown(yyyyMmDd / 100, 0);
}
def isPeriodRolled = compoundValue(1, periodIndx != periodIndx[1], yes);

def volumeSum;
def volumeVwapSum;
def volumeVwap2Sum;

if (isPeriodRolled) {
volumeSum = volume;
volumeVwapSum = volume * vwap;
volumeVwap2Sum = volume * Sqr(vwap);
} else {
volumeSum = compoundValue(1, volumeSum[1] + volume, volume);
volumeVwapSum = compoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap);
volumeVwap2Sum = compoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap));
}
def price = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));

def VWAP = price;
plot UpperBand = price + numDevUp * deviation;
#plot LowerBand = price + numDevDn * deviation;

AssignBackgroundColor(if close > UpperBand then Color.DARK_GREEN else Color.Gray);``````

C

#### C4men

##### Member
Thanks @BenTen!

I am pretty close, wondering if I might ask one more favor. I am trying to color it based on 4 different "conditions", but when I put in this code at the bottom, the colors don't always match the reality on the chart.

Above the Upper = Strong Bull
Between Upper and VWAP = Bullish
Between VWAP and Lower = Bear
Below the Lower = Strong Bearish

I typically trade on the 5 min chart - if that makes a difference - and price crossing above the VWAP Upper at 1 StDev has been a good signal.

Can you take a look and tell me what I am missing (Note: I replace UpperBand with VWAP_Upper)?

Code:
``````def VWAP_Upper = price + numDevUp * deviation;
def VWAP_Lower = price + numDevDn * deviation;

def VWAP_StrongBull = close > VWAP_Upper;
def VWAP_Bull = close < VWAP_Upper and close > price;
def VWAP_Bear = close > VWAP_Lower and close < price;
def VWAP_StrongBear = close < VWAP_Lower;

plot VWAP_Num = if VWAP_StrongBull is true then 2 else if VWAP_Bull is true then 1 else if VWAP_Bear is true then -1 else if VWAP_StrongBear is true then -2 else 0;

AssignBackgroundColor(if VWAP_Num == 2 then Color.DARK_GREEN else if VWAP_Num == 1 then color.GREEN else if VWAP_Num == -1 then color.RED else if VWAP_Num == -2 then Color.Dark_Red else Color.White);``````

C

#### C4men

##### Member
Thanks @BenTen!

I am pretty close, wondering if I might ask one more favor. I am trying to color it based on 4 different "conditions", but when I put in this code at the bottom, the colors don't always match the reality on the chart.

Above the Upper = Strong Bull
Between Upper and VWAP = Bullish
Between VWAP and Lower = Bear
Below the Lower = Strong Bearish

I typically trade on the 5 min chart - if that makes a difference - and price crossing above the VWAP Upper at 1 StDev has been a good signal.

Can you take a look and tell me what I am missing (Note: I replace UpperBand with VWAP_Upper)?

Code:
``````def VWAP_Upper = price + numDevUp * deviation;
def VWAP_Lower = price + numDevDn * deviation;

def VWAP_StrongBull = close > VWAP_Upper;
def VWAP_Bull = close < VWAP_Upper and close > price;
def VWAP_Bear = close > VWAP_Lower and close < price;
def VWAP_StrongBear = close < VWAP_Lower;

plot VWAP_Num = if VWAP_StrongBull is true then 2 else if VWAP_Bull is true then 1 else if VWAP_Bear is true then -1 else if VWAP_StrongBear is true then -2 else 0;

AssignBackgroundColor(if VWAP_Num == 2 then Color.DARK_GREEN else if VWAP_Num == 1 then color.GREEN else if VWAP_Num == -1 then color.RED else if VWAP_Num == -2 then Color.Dark_Red else Color.White);``````
I'm an idiot - I think setting the timeframe in the watchlist code editor to '5 min' did the trick (maybe).