VWAP Crosses, Format, Watchlist, Label, Scan for ThinkorSwim

@BenTen

Thanks for making this script! I am trying to adjust the code to paint the arrows on the chart for every time price crosses vwap. Which part needs to be taken out to remove the abnormal volume req?

Thanks!
 
I am wondering if someone could reverse engineer this indicator I found on Twitter. It looks very interesting and seems to be accurate. I don’t know coding so this would be very difficult for me to try and code it myself. I am wondering if someone would be interested in taking a stab at it. I would really appreciate it.

The strategy is very simple:

The Strategy:
Scalping Strategy
Used for stocks that have gapped up or down but can also be used on any stock.
2nd Candle determines the trend
5 Minute Time Frame

Simplifying the strategy, there are 2 scenarios...
1) close of candle 2 > close of candle 1 ----> Long below VWAP
2) close of candle 2 < close of candle 1 ---> Short above VWAP

If the second 5 minute candle closes above the close of the first 5 minute candle then you go long when price is below VWAP. The indicator will place a wedge above the second candle to identify it and green arrows on every candle that crosses below VWAP as an indication to go long. The arrows will show to go short throughout the day every time price crosses below VWAP.

If the second 5 minute candle closes below the close of the first 5 minute candle then you go short when price is above VWAP. The indicator will place a wedge below the second candle to identify it and red arrows on every candle that crosses above VWAP as an indication to go short. The arrows will show to go short throughout the day every time price crosses above VWAP.

There are also labels that show in the upper right corner of the chart. “BAR 2> BAR 1”. In green “Bar 2 < Bar 1” in red and also a label that says: “Basic=Active: Long Below VWAP” in Green and “Basic =Active: Short Above VWAP” in Red.

I have attached some images as examples.
https%3A//i.imgur.com/TIk9RNC.png[/img]']
TIk9RNC.png

https%3A//i.imgur.com/ddZfzUg.png[/img]']
ddZfzUg.png

https%3A//i.imgur.com/aM2qIPV.png[/img]']
aM2qIPV.png
 
@geebeeaye In dark mode the font is white. There is technically no changing that.
But.... If we change the element to a label then there are more editing options.
Here it is as a label w/ black text...
Ruby:
def calc_vwap = (close-vwap())/close*100;
def vwap = round(calc_vwap,1);
AddLabel(yes, vwap, color.black);
AssignBackgroundColor(if vwap > 0 then Color.GREEN else if vwap < 0 then Color.RED else Color.BLACK);
View attachment 868
Hello , Is there an Alert for that to add ??
 
@TradeUp there's a guy on twitter who had been working on creating something similar (@C4men) back in August. I'm not sure if he's still working on it now but you could reach out to him and see if he'd be okay with you modifying his code so that you don't have to start from scratch.
 
Last edited by a moderator:
@tradelex20 Add these statements to the bottom of your study:
Ruby:
AddOrder(OrderType.BUY_AUTO, condition = bullish_signal);
AddOrder(OrderType.SELL_AUTO, condition = bearish_signal);
 
Last edited:
@zeek See if this works. You can turn off the plots if confirm it is working.

9bjqsba.png


Code:
# 5 EMA and VWAP cross. Modified 2 ToS studies and added labels for crosses. By Horserider 7/21/2019

# TD Ameritrade IP Company, Inc. (c) 2011-2019
#

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;


plot VWAP = price;


# TD Ameritrade IP Company, Inc. (c) 2017-2019
#

input price2 = close;
input length = 5;
input displace = 0;


plot AvgExp = ExpAverage(price2[-displace], length);


AddLabel(yes, "Buy ", if avgexp > vwap then Color.GREEN else color.GRAY);

AddLabel(yes, "Sell", if avgexp < vwap then Color.RED else color.GRAY);

couldn't VWAP value be obtained just by doing the following?

Code:
reference VWAP()."VWAP"
 
Hi,

I am trying to create a scanner off 2nd std deviation off VWAP . Basically I want a scanner that shows when Bid or Market price is approaching the 2nd std deviation ("lowerband") of vwap or near it within 5-10 candles. I tried doing it myself but I ran into issues where the script doesn't allow duplicate aggregation periods. I also tried editing the conditions but I am not sure it takes a negative number for value. I see that it does for a positive number.

VWAP = daily aggregation
Bid or market price = 1 minute candles

Thank you,

Alex
 
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.

7P8f0QI.png


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 BenTen , I use this code and I'm looking for an alert for this when the price will go up or away at least 1% from the VWAP, something like that , thanks
 
I'm not at a think or swim editor, just here in the forum text editing, but something along these lines:

Code:
plot condition = if close > vwap() or close[1] > vwap()[1] then 1 else double.nan;

you can change the or to be an and if you want to get both the latest and the previous candle closes above vwap.

happy trading,
mashume
 
Greetings! I'm trying to fashion a scanner that will display results for close price within x% above VWAP (on a 5 min chart), with x being a variable that I would determine, i.e. 1%.

I tried finding the solution using the TOS condition wizard without success and I searched the forums here but can't locate a topic addressing this. Thanks in advance for your assistance with this request.

=Aaron=
 
Last edited:
I have more ten 15 stocks on my portfolio, I wanted to know if there is an alert when a stock reaches vwap, instead of me checking now then

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

I added this code on thinkorswim, it turns the whole page into orange, green.

It is no where like the above image which show on the portfolio
 
Last edited by a moderator:
@Jerseystranger It sounds like you might be a little confused on how to add a watchlist column
1. First, you need a portfolio watchlist. See instructions to create one:​
2. Now you can add your VWAP watchlist column to your portfolio watchlist:​
 
@Jerseystranger
To get alerts when an equity in the Portfolio Watchlist (that you created above) reaches VWAP
  1. Open Scan Hacker
  2. Change the Scan In Box to only scan whatever you called the Portfolio Watchlist you created
  3. Put in your VWAP criteria: close crosses below VWAP()
  4. SAVE! (must be saved BEFORE setting up alerts)
  5. Click on the hamburger menu icon
    aHamburger.png
    right above the results.
  6. Choose Alert when scan results change.
ITAEWl3.png
 
Last edited:
Plots the Previous Day's VWAP and the Current VWAP ( volume weighted average price )

Appreciation goes a long way... Remember to this the like button if you found this post useful.

h3dVErK.png


Code:
#
# Plot Previous Days VWAP
# By XeoNoX via https://usethinkscript.com/
#

input numDevDn = -2.0;
input numDevUp = 2.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));

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


input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;
plot PrevDayVWAP;
if showOnlyLastPeriod and !IsNaN(vwap(period = aggregationPeriod)[-1]) {
    PrevDayVWAP = Double.NaN;
} else {
    PrevDayVWAP = Highest(vwap(period = aggregationPeriod)[-displace], length);
}
PrevDayVWAP.SetDefaultColor(GetColor(9));
PrevDayVWAP.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
@XeoNoX If I want only the prior day vwap, how do I edit out current day vwap from your code?
 
Hi Ben
Wanted to know if there is a code for vwap crossover where I'am able the view on left of thonkorswim my portfolio colum where it turns red or green.
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
475 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top