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

@Jerseystranger I take it that the answer above it not what you are looking for?
Is it possible that you are asking if a vwap column can be added to the portfolio monitor tab???
The answer is no. ToS doesn't allow us to create custom scripts to that module. :(

If that isn't what you are asking. Can you provide screenshots of what you are looking for?
Unsure of how to upload screenshots to the forum, Here are directions.
 
Last edited:
@mohitdas

Redid original to include new label and arrows and alerts.

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


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 VWAP = price;

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

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

AddLabel(yes, "VWAP EXP Cross", if avgexp > vwap then Color.GREEN else color.RED);

input showBreakoutSignals = no;
plot UpSignal = avgexp crosses above vwap;
plot DownSignal = avgexp crosses below vwap;

UpSignal.SetHiding(!showBreakoutSignals);
DownSignal.SetHiding(!showBreakoutSignals);


UpSignal.SetDefaultColor(Color.UPTICK);
UpSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
DownSignal.SetDefaultColor(Color.DOWNTICK);
DownSignal.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

Alert(UpSignal, "Buy", Alert.Bar, Sound.Chimes);
Alert(DownSignal, "Sell", Alert.bar, Sound.Chimes);
@horserider @BenTen Can you please help me, I posted this code but its not working,

I just want think or swim to notify me when the 9EMA crosses VWAP on the 5 min chart up or down, UP = Bullish, Down = Bearish

I want this scanner on my watchlist of tech Giants, can you please tell me what I am doing wrong?
 
@horserider @BenTen Can you please help me, I posted this code but its not working,

I just want think or swim to notify me when the 9EMA crosses VWAP on the 5 min chart up or down, UP = Bullish, Down = Bearish

I want this scanner on my watchlist of tech Giants, can you please tell me what I am doing wrong?
I moved your thread here because there are 8 pages of examples of EMA/VWAP crosses.
This post is just one example: https://usethinkscript.com/threads/vwap-watchlist-label-scan-for-thinkorswim.110/page-2#post-11765

Read through the thread to find many more.
 
Can anyone help with a tos column script for 9EMA and vwap cross......red when 9EMA is below green when (EMA is above VWAP and white when they are touching/Crossing?......and could it have a changable timeframe IE 1,3,5 minutes?
 
Can anyone help with a tos column script for 9EMA and vwap cross......red when 9EMA is below green when (EMA is above VWAP and white when they are touching/Crossing?......and could it have a changable timeframe IE 1,3,5 minutes?


@wes refer to post above yours
 
HI Ben - I am using your MA Cross Overs with alerts on a simple set up I am trading on /YM futures. I made some labels for myself, but the label plots with four decimal points after the whole number. I wonder if you could give me a tip or two on how to limit the label to just the whole number. Would be much appreciated. I tried researching this, but I did not see how to affect the label.


AddLabel(yes, "VWAP 3:" + FastMA, Color.PLUM);
AddLabel(yes, "VWAP 5:" + SlowMA, Color.PLUM);
 
HI Ben - I am using your MA Cross Overs with alerts on a simple set up I am trading on /YM futures. I made some labels for myself, but the label plots with four decimal points after the whole number. I wonder if you could give me a tip or two on how to limit the label to just the whole number. Would be much appreciated. I tried researching this, but I did not see how to affect the label.


AddLabel(yes, "VWAP 3:" + FastMA, Color.PLUM);
AddLabel(yes, "VWAP 5:" + SlowMA, Color.PLUM);
Here ya go:
AddLabel(yes, "VWAP 3:" + round(FastMA,0), Color.PLUM);
AddLabel(yes, "VWAP 5:" + round(SlowMA,0), Color.PLUM);
 
Last edited:
@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;
Hi this is great. One question on the "lookback" variable. If I set the lookback variable 5 does it include any crossovers which happened up to 5 bars ago OR only 5 bars ago? Thanks for your time.
 
Hi this is great. One question on the "lookback" variable. If I set the lookback variable 5 does it include any crossovers which happened up to 5 bars ago OR only 5 bars ago? Thanks for your time.
The lookback in this case is the number of the candle.
VWAP()[1] =previous bar
VWAP()[2] =2 bars ago
VWAP()[5] =5 bars ago

EMA crosses VWAP()[5]
is scanning for when the EMA crosses the value of the VWAP from 5 bars ago.
 
Greetings! I am trying to figure out how to AddCloud between VWAP and 50EMA. These indicators are defined in the capture below. The VWAP upper/lower bands are not a consideration.

hnarvyP.jpg


I came across this code in an earlier forum that was provided by Welkin which I believe is close to what I'm after, but I just can't get it right:

input price = VWAP;
input length1 = 5;
input length2 = 25;
input AverageType1 = AverageType.SIMPLE;
input AverageType2 = AverageType.SIMPLE;

plot MA1 = MovingAverage(AverageType1, price, length1);
plot MA2 = MovingAverage(AverageType2, price, length2);
AddCloud(MA1, MA2, Color.GREEN, Color.RED, no);

Can someone help out with a solution for this request, please? Maybe I missed a different forum that addresses this. Thanks!

=Aaron=
 
Last edited:
Greetings! I am trying to figure out how to AddCloud between VWAP and 50EMA. These indicators are defined in the capture below. The VWAP upper/lower bands are not a consideration.

hnarvyP.jpg


I came across this code in an earlier forum that was provided by Welkin which I believe is close to what I'm after, but I just can't get it right:

input price = VWAP;
input length1 = 5;
input length2 = 25;
input AverageType1 = AverageType.SIMPLE;
input AverageType2 = AverageType.SIMPLE;

plot MA1 = MovingAverage(AverageType1, price, length1);
plot MA2 = MovingAverage(AverageType2, price, length2);
AddCloud(MA1, MA2, Color.GREEN, Color.RED, no);

Can someone help out with a solution for this request, please? Maybe I missed a different forum that addresses this. Thanks!

=Aaron=

The vwap in your image is the indicator VWAP versus the fundamental price of vwap. The code you posted is the fundamental price of vwap. To reference the indicator vwap, see the code below. The clouds and the coloring of the moving average and the vwap indicator are based upon the input cloud_basis. You can choose one of these and/or create your own and add it to the switch statement.

Capture.jpg
Ruby:
input cloud_basis = {default close, direction};
input length1 = 50;
input AverageType1 = AverageType.EXPONENTIAL;

plot MA1 = MovingAverage(AverageType1, close, length1);
plot vwap = reference VWAP();

def up;
def dn;

switch (cloud_basis) {
case close:
    up = close >= MA1 and close >= vwap;
    dn = close <= MA1 and close <= vwap;
case direction:
    up = MA1 >= MA1[1] and vwap >= vwap[1];
    dn = MA1 <= MA1[1] and vwap <= vwap[1];
}

AddCloud(if up then MA1 else Double.NaN, vwap,  Color.GREEN,  Color.GREEN, no);
AddCloud(if dn then MA1 else Double.NaN, vwap, Color.RED, Color.RED, no);
AddCloud(if !up or !dn then MA1 else Double.NaN, vwap, Color.GRAY, Color.GRAY);

ma1.setpaintingStrategy(paintingStrategy.LINE);
MA1.AssignValueColor(if
                       if cloud_basis == cloud_basis.close
                       then close >= MA1
                       else MA1 >= MA1[1]
                     then Color.GREEN
                     else Color.RED);
vwap.SetPaintingStrategy(PaintingStrategy.LINE_VS_POINTS);
vwap.AssignValueColor(if
                        if cloud_basis == cloud_basis.close
                        then close >= vwap
                        else vwap >= vwap[1]
                      then Color.GREEN
                      else Color.RED);
 
This is an amazing script, SleepyZ . . . beautiful. Thank you very much! Although the resulting visual will take a bit of getting used to, as a confirmation study I can already see this is quite powerful. I'll be going through this code line-by-line to try understanding each step; a lot of this right now is going completely over my head. I sure appreciate the work. =A=
 
@Vincenzo It's actually not complicated at all and you don't even need any external script.

Start by setting up a scanner to look for close crossing above VWAP.

xBen1h9.png


Adjust the within X bars value. By default, it's set to one, so it will be scanning for the latest bar. This field is optionable. I would leave it as 1.

Next, select the timeframe before you hit the Scan button.

HUSAnar.png
This works great thank you. Just trying to get the watchlist to work with some back ground color. this is what thinkscript has now: it’s showing a 1 if true and 0 if not. So just wanted to add green and red to the back ground for fast look. Can you please tell me what to add to this to make that happen.
close crosses above reference VWAP()."VWAP"
 
Is it possible to alert when the 9EMA crosses VWAP on the 15m time frame within one candle? and make a watchlist script for it?

For example, something on the watchlist that shows green when 9EMA crosses VWAP to the upside and red for the downside. Blank when the cross happened more than 1 candle ago.

Essentially my strategy is waiting to cross on the 15m near support/resistance then getting the same cross on 5m for an entry trigger. Works very well however I'd like to be able to more easily scan for this setup.

Any help is appreciated I've learned a lot from this forum so thank you guys!
 
This Might work, haven't used it in a while .
Code:
# 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 "BUY" else "SELL", if EMA < vwapValue then Color.Black else Color.Black);
AssignBackgroundColor(if EMA > VWAPValue  and EMA>EMA[1] then Color.green else if EMA < VWAPValue  and EMA<EMA[1] then Color.red else color.black);
 
Alert(CrossUp, " ", Alert.Bar, Sound.Chimes);
Alert(CrossDn, " ", Alert.Bar, Sound.Bell);

# End VWAP Watchlist
 
Last edited:
This Might work, haven't used it in a while .
Code:
# 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 "BUY" else "SELL", if EMA < vwapValue then Color.White else Color.White);
AssignBackgroundColor(if EMA > VWAPValue then color.GREEN else  color.RED);

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

# End VWAP Watchlist
Everything has a buy or sell which means it's not showing the within one bar part of it

It should be something like: green if 9 ema crosses > vwap within 1 bar else red if 9 ema cross < vwap within 1 bar else black

I just don't know how to code it
 
Good afternoon traders,

I wanted to know if there is a way to add a label to the chart that says when the price action is greater than the 1 standard devotion (upper band) and below 1 standard deviation (lower band).

I was able to figure out how to create the label to say when price action is above VWAP, but I'm not sure how to make the label state when price is above or below 1 standard deviation.

Thank you in advance!

Code:
def vwapValue = reference VWAP()."VWAP";

def Above = close > vwapValue;
def Below = close < vwapValue;
AddLabel(Above, “Above VWAP”, color.green);
AddLabel(Below, “Below VWAP”, color.red);

AddLabel(yes, Concat("VWAP: ", vwapValue), Color.White);
 
Good afternoon traders,

I wanted to know if there is a way to add a label to the chart that says when the price action is greater than the 1 standard devotion (upper band) and below 1 standard deviation (lower band).

I was able to figure out how to create the label to say when price action is above VWAP, but I'm not sure how to make the label state when price is above or below 1 standard deviation.

Thank you in advance!

Code:
def vwapValue = reference VWAP()."VWAP";

def Above = close > vwapValue;
def Below = close < vwapValue;
AddLabel(Above, “Above VWAP”, color.green);
AddLabel(Below, “Below VWAP”, color.red);

AddLabel(yes, Concat("VWAP: ", vwapValue), Color.White);

Try this

{Edit - corrected vwapValuelower to reflect lowerband instead of upperband]
Ruby:
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 Aboveupper = close > vwapValueupper;
def Belowlower = close < vwapValuelower;
AddLabel(Aboveupper, “Above VWAPupper”, Color.GREEN);
AddLabel(Belowlower, “Below VWAPlower”, Color.RED);
 
Last edited:

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