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

Hi, Trying to create a scan that includes the condition that current price is within x% above OR Below VWAP. Any help is appreciated.

Price is within X% max of VWAP

Code:
#Price is within X% max of VWAP
# By XeoNoX via usethinkscript.com
#### Change percentvalue to decirect % in decimal format
###  Example .02 is 2%  and .025 is 2.5%
def percentvalue = .02;
def vw = reference vwap();
def s2 = vw*percentvalue;
plot scan = absvalue(close - vw) is less than or equal to s2;
 
Hi, I need a screener that will scan for stocks that are +/- 2 standard deviations away from VWAP. Possibly indicating over bought or over sold conditions. Thanks
 
Hi- Looking to setup alerts on my custom watch list, where "SimpleMovingAvg()."SMA" crosses above reference VWAP()."VWAP""

I would like to add a chime, ring alert along with background color change to green?

Greatly appreciated.
 
Ruby:
Alert(SimpleMovingAvg()."SMA" crosses above reference VWAP()."VWAP", "SMA xUp VWAP", Alert.BAR, Sound.Ding);
 
Post your complete study... The code, not a shared link... I'll take a look...
“SimpleMovingAvg()."SMA" crosses above reference VWAP()."VWAP""

that’s the code simple watchlist study where SMA crosses VWAP. I understand that you cannot add chime alert but looking for a background color indication where sma crosses vwap, the indicator changes from 0.0 to 1.0, need that box colors green when this change happens.
 
@korcari23 You can't send Alerts from a Watchlist column... I thought I'd already stated that in this topic... I know I did in one of todays topics...
 
@korcari23 This will change the watchlist column per crossover.

Code:
# SMA x VWAP crossover
# By BenTen of useThinkScript.com

declare upper;

# Moving Average
input priceMA = close;
input lengthMA = 9;
input displace = 0;
input showBreakoutSignals = yes;
input price = close;

def SMA = SimpleMovingAvg(priceMA[-displace], lengthMA);

# VWAP
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 priceVWAP = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(priceVWAP), 0));

plot VWAP = priceVWAP;

def bullish_signal = SMA crosses above priceVWAP;
def bearish_signal = SMA crosses below priceVWAP;

AssignBackgroundColor(if bullish_signal then color.dark_green else if bearish_signal then color.dark_red else color.gray);
 
@BenTen Done via Discord... For those wondering what we did, here it is...

Ruby:
plot data = SimpleMovingAvg(close, 9)."SMA" crosses above vwap;
data.AssignValueColor(if data then Color.GREEN else Color.RED);
AssignBackgroundColor(if data then Color.GREEN else Color.RED);

That gave @korcari23 a Watchlist column cell that shows Green or Red depending on whether SMA crossed above VWAP, as requested...

Corrected code to optimize...
 
Last edited:
Price is within X% max of VWAP

Code:
#Price is within X% max of VWAP
# By XeoNoX via usethinkscript.com
#### Change percentvalue to decirect % in decimal format
###  Example .02 is 2%  and .025 is 2.5%
def percentvalue = .02;
def vw = reference vwap();
def s2 = vw*percentvalue;
plot scan = absvalue(close - vw) is less than or equal to s2;
for this to work properly what does the aggregation period need to be set to? I want to use this to scan for stocks with last price within x percent of vwap.
Thank you!
 
Sorry for all the questions but I assume this will work to find last price above and below VWAP by simply changing less than to greater than. is this correct?
 
@PapaBear10 Your code had several syntax errors. Here is my version of a VWAP Watchlist that is painted green when 9 ema crosses above vwap within last 3 bars. It is painted red when 9 ema crosses below vwap within last 3 bars. Remember to select the aggregation period you are interested in when configuring this watchlist

Code:
# VWAP Watchlist
# tomsk
# 1.25.2020

# Watchlist that is painted green when 9 ema crosses above vwap within last 3 bars
# It is painted red when 9 ema crosses below vwap within last 3 bars

input length = 9;

def ema = ExpAverage(close, length);
def vwapValue = reference VWAP();
def crossUp = ema crosses above vwapValue within 3 bars;
def crossDn = ema crosses below vwapValue within 3 bars;
AddLabel(1, if crossUp then "X Up" else if crossDn then "X Down" else " ", Color.Black);
AssignBackgroundColor(if ema crosses above vwapValue then Color.GREEN
                      else if ema crosses below vwapValue then Color.RED
                      else Color.Gray);
# End VWAP Watchlist
Can anyone guide me . In this watchlist script if 9ema cross then green , cross below then red but no gray. I want it to stay green or red once cross up or down. Thanks in advance
 

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
477 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