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

My idea is like multi time frame analysis using ema, VWAP in watchlist column

1. if VWAP < close then statement show " Bullish " else VWAP > close then statement show " Bearish"
AssignBackgroundColor(if close > vwap then color.dark_green else color.dark_red);

2. if close > 9 EMA (5 min) then statement show " bullish" else close < 9 ema ( 5 min) then statement "bearish"
AssignBackgroundColor(if close > EMA then color.dark_green else color.dark_red);

3. if 16 ema ( 60 min chart) cross above 72 EMA (60 min chart) then statement show " bullish" else 16 EMA cross below 72 ema then statement "bearish"
AssignBackgroundColor(if 16 ema cross above> 72 ema then color.dark_green else 16 ema cross below 72 ema then color.dark_red);

Please help!!!
 

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

Vwap 9 ema crossover watchlist column.

# VWAP Watchlist
# tomsk
# 1.25.2020

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

input length = 9;

def ema = ExpAverage(close, length);
def vwapValue = reference VWAP();
def crossUp = ema crosses above vwapValue within 1 bars;
def crossDn = ema crosses below vwapValue within 1 bars;
AddLabel(yes, if EMA > VwapValue then "Bullish" else "Bearish", if EMA < vwapValue then Color.Black else Color.Black);
AssignBackgroundColor(if EMA > VWAPValue and EMA>EMA[1] then Color.Dark_green else if EMA < VWAPValue and EMA<EMA[1] then Color.Dark_red else color.black);

Alert(CrossUp, " ", Alert.Bar, Sound.Chimes);
Alert(CrossDn, " ", Alert.Bar, Sound.Bell);

# End VWAP Watchlist
 
16/72 ema crossover watchlist column.

# WalkingBallista EMA Lookback Cross
# https://usethinkscript.com/d/119-moving-average-crossover-watchlist-column-for-thinkorswim

declare lower;

input lookback = 2;
input ema1_len = 16;
input ema2_len = 72;
input averageType = AverageType.EXPONENTIAL;

def ema1 = MovAvgExponential(length=ema1_len);
def ema2 = MovAvgExponential(length=ema2_len);

def bull_cross = ema1 crosses above ema2;
def bear_cross = ema1 crosses below ema2;

def bull_lookback = highest(bull_cross, lookback);
def bear_lookback = highest(bear_cross, lookback);

AddLabel(yes, if EMA1 > EMA2 then "Bullish" else "Bearish", if EMA1 < EMA2 then Color.Black else Color.Black);
AssignBackgroundColor(if EMA1 > EMA2 then Color.Dark_green else if EMA1 < EMA2 then Color.Dark_red else color.black);

# End
 
Hi,

I want to submit the following chart study code that shows when the price crosses above VWAP. A blue arrow and sound is generated on the chart when this happens. This is useful when tracking a stock for a red to green move, especially a low float, low priced stock with a catalyst in the early time frame (9:30am to 11am). Please pass this on!

Thanks,
Sonny

n8tyw8P.png


Code:
#Price crosses above 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 price = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));
plot vwapValue = price;
plot crossingAbove = close[1] < vwapValue[1] and close > vwapValue;
crossingAbove.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
crossingAbove.SetDefaultColor(Color.CYAN);
crossingAbove.SetLineWeight(1);
Alert(crossingAbove[1], "Cross Above VWAP", Alert.BAR, Sound.Bell);
Would you happen to have a shared file ?
 
I tried adding this to the chart but it shows no label when the price action is within 1 standard deviation of the VWAP. How can we update that to show this?
Try this

{Edit - corrected vwapValuelower to reflect lowerband instead of upperband]




Code:
def vwapValueupper = reference VWAP("num dev dn" = -1.0, "num dev up" = 1.0).UpperBand;

def vwapValuelower = reference VWAP("num dev dn" = -1.0, "num dev up" = 1.0).LowerBand;



def Above = close > vwapValueupper;

def Below = close < vwapValuelower;

AddLabel(Above, “TRADE REVERSALS”, color.red);

AddLabel(Below, “TRADE REVERSALS”, color.green);



def NoTradeUpper = close < vwapValueupper;

def NoTradeLower = close > vwapValuelower;

AddLabel(NoTradeUpper, “DONT TRADE REVERSALS”, color.gray);

AddLabel(NoTradeLower, “DONT TRADE REVERESALS”, color.gray);

This is what I was able to come up with. How can I edit the code to only show the label once instead of twice on my screen? And for the label to print "TRADE REVERSALS" once the price action exceeds 1 standard deviation?

Thank you!
 
Last edited:
Is there anyway to create a scan that will search when the daily vwap has crossed stacked weekly and monthly vwaps? or when the weekly vwap crosses above or below the monthly vwap? I tried the following but it had an error

def VWAPW = VWAP(period = AggregationPeriod.WEEK);
def VWAPM = VWAP(period = AggregationPeriod.MONTH);

scan = Vwapw crosses vwapm;
 
Is there anyway to create a scan that will search when the daily vwap has crossed stacked weekly and monthly vwaps? or when the weekly vwap crosses above or below the monthly vwap? I tried the following but it had an error

def VWAPW = VWAP(period = AggregationPeriod.WEEK);
def VWAPM = VWAP(period = AggregationPeriod.MONTH);

scan = Vwapw crosses vwapm;

The vwap above is the fundamental price, vwap. The following will reference the vwap indicator and seems to work.

Ruby:
plot scan = reference VWAP("time frame" = "WEEK") crosses reference VWAP("time frame" = "MONTH");
 
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.

Shared WatchList Link: http://tos.mx/X7jLAge Click here for --> Easiest way to load shared links
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 there, I was wondering if you or anyone knows how to write a script which tells us the price difference between the VWAP Upperband and Lowerband. I attempted it but I couldn't Figure it out
 
Hello again Sir Ben, I am not able to see the numbers on the VWAP against the green in the column. Can you give me a hint on where to go in the code to change color? Thks

This is one I used: http://tos.mx/X7jLAge

See if the color.white for the plot vwap works better for you. If not, you can try other colors there until you find the best one.

Capture.jpg


Ruby:
plot vwap = vwap();
vwap.setdefaultColor(color.white);

AssignBackgroundColor(if close > vwap then Color.DARK_GREEN else if close < vwap then Color.DARK_RED else Color.Dark_ORANGE);
 
Hi Benten and all our good friends , please help me with below script
Code:
##
## Watchlist Column to ShowLabel - difference in value between UpperBand and lowerBand of VWAP ;
##
input numDevDn = -2.0;
input numDevUp = 2.0;
input timeFrame = {default DAY, WEEK, MONTH, YEAR};
input show_VWAP_label = no;
input VWAP_Label_Color_Choice = {default "magenta", "green", "pink", "cyan", "orange", "red", "blue", "gray", "violet"};
input show_VWAP_bands_label = yes;
input Bands_Label_Color_Choice = {default "magenta", "green", "pink", "cyan", "orange", "red", "blue", "gray", "violet"};


def cap = getAggregationPeriod();
def errorInAggregation =
timeFrame == timeFrame.DAY and cap >= AggregationPeriod.WEEK or
timeFrame == timeFrame.WEEK and cap >= AggregationPeriod.MONTH or
timeFrame == timeFrame.MONTH and cap >= AggregationPeriod.YEAR;
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);
case YEAR:
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;
VWAP.hide();
plot UpperBand = price + numDevUp * deviation;
UpperBand.hide();
plot LowerBand = price + numDevDn * deviation;
LowerBand.hide();

VWAP.setDefaultColor(getColor(0));
UpperBand.setDefaultColor(getColor(2));
LowerBand.setDefaultColor(getColor(4));

## AddLabel(Show_VWAP_label, " VWAP = " + Round(VWAP, 2), GetColor(VWAP_Label_Color_Choice));
## AddLabel(Show_VWAP_bands_label, " UB - LB = " + round(UpperBand- lowerBand, 2) );
## AddLabel(Show_VWAP_bands_label, " VWAP Upper Band = " + round(UpperBand, 2) + " ... " + " VWAP Lower Band = " + round(LowerBand, 2), GetColor(Bands_Label_Color_Choice));

AddLabel(Show_VWAP_bands_label, round(UpperBand- lowerBand, 2) );
 
Last edited by a moderator:
This is my first post to you all! Nice to be here with all of you looking for better data for informed decisions.

Help Please?

I need results that are below VWAP and another for only above VWAP for a few other scans I have. I want it to scan about every 3-5 minutes and show current results in watchlists. This could eliminate a lot of manual filtering/scanning. I'll go back and reread but it didn't look like I saw anything that eliminated results above VWAP. I have a breakout watchlist and if I can eliminate entries above or below would be great!

I'd like to scan for entries that have gapped down or up and catch them as the change to an upward direction such as after a selloff or squeeze as it breaks open. I'm open to any suggestions on creating better dynamic watchlists or scanners to catch and alert for changes in momentum.

Code:
#Hint: The VWAP Scan filters for securities that have a current price above or below any given number of standard devation moves of the of the current VWAP. \n\nThe default aggregation period is 15 minutes. This period as well as the time frame used in VWAP can be changed in the scan.\n\nFor faster results choose to "Scan In" a subset of "All Symbols".
#Wizard text: The current price is
#Wizard input: choice
#Wizard input: numDev
#Wizard text: standard devation moves in the
#Wizard input: timeFrame
#Wizard text: VWAP

input numDev = 2.0;
input timeFrame = {default DAY, WEEK,  MONTH};
input Choice = {default "Greater Than", "Less Than"};
def cap = GetAggregationPeriod();
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;
def UpperBand = price + numDev * deviation;
def LowerBand = price - numDev * deviation;
plot scan;
switch (Choice){
case "Greater Than":
    scan = close > UpperBand;
case "Less than":
    scan = close < LowerBand;
}


Thank you for considering my request
 
Last edited:
Scanning for last 2 candles closing above VWAP
Can I get help with a script that Scans for tickers having their last 2 candles closing above VWAP?

Thanks.
 
Last edited by a moderator:
Can I get help with a script that Scans for tickers having their last 2 candles closing above VWAP?

Thanks.

This will find the last 2 bars, not including the last bar, that close above Vwp. If you want to include the last bar as one of the 2 bars, then reduce the values in all the brackets [ ] by 1.

Ruby:
def vwap = reference vwap();
plot scan = close[1] > vwap[1] and close[2] > vwap[2];
 
@Bung Bang A scan code that looks for EMA(9) crossing VWAP can be simply coded as follows. If you want this to lookback 2 bars, just change the value of the variable lookback to 2. Be default it is set to 0, which means it looks at the current bar.

Code:
def lookback = 0;
def EMA = ExpAverage(close, 9);
def vwapValue = VWAP()[lookback];

plot scan = EMA crosses vwapValue;
Can I change it to the crossover with cloud?

Thanks
 
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);

Edit: I'm an ***** - I think setting the timeframe in the watchlist code editor to '5 min' did the trick (maybe).
I was reading older posts and liked yours. Have you been using this since this post? Found it helpful? I’m currently just beginning in my journey with thinkscript and like the parameters you have set with the 4 different zones, and jw what your experience was in it ?
Tia
 
Hello. I need some help with this. Im trying to get this custom condition to work but it keeps selling my order before it happens. I want a custom condition that will sell my shares when the current price close gets below VWAP automatically. Im wondering if im using the right VWAP (Studies>VWAP or price> (VWAP)...Thanks.
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
325 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