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

The following will limit the plot of arrows when yes to the number of x arrows:
input limit_arrow_plot = yes;
input show_x_arrows = 1;

The following set to 1 will plot the arrow on the cross. If set higher it will move the arrow to the right from the cross by that increase:
input show_within_bars = 1;
I appended this code to the original @horserider code and it looks like it works, but there isn't logic in place to shift the crosses when i change the ema. Is it possible to adjust that? Also, this only displays an UP arrow, any way to add a Down arrow too? Love the implementation and the idea of only showing "x" arrows so not to clutter the chart. Turning off the lines would also free up space to add other items in the price area
Thanks!.

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
#
#Example_cond_limit_plot

input limit_arrow_plot = yes;
input show_x_arrows    = 1;
input show_within_bars = 1;

def bullish = reference VWAP()."VWAP" crosses above MovAvgExponential("length" = 5)."AvgExp" within show_within_bars bars;
def dataCount = CompoundValue(1, if IsNaN(dataCount[1]) then 0 else if bullish then dataCount[1] + 1 else dataCount[1], 0);

plot upArrow = if limit_arrow_plot and HighestAll(dataCount) - dataCount <= show_x_arrows - 1
               then bullish
               else if !limit_arrow_plot
               then bullish
               else Double.NaN;
upArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
upArrow.SetDefaultColor(CreateColor(145, 210, 144));
upArrow.SetLineWeight(4);


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);
 
Last edited:

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

I appended this code to the original @horserider code and it looks like it works, but there isn't logic in place to shift the crosses when i change the ema. Is it possible to adjust that? Also, this only displays an UP arrow, any way to add a Down arrow too? Love the implementation and the idea of only showing "x" arrows so not to clutter the chart. Turning off the lines would also free up space to add other items in the price area
Thanks!.

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
#
#Example_cond_limit_plot

input limit_arrow_plot = yes;
input show_x_arrows    = 1;
input show_within_bars = 1;

def bullish = reference VWAP()."VWAP" crosses above MovAvgExponential("length" = 5)."AvgExp" within show_within_bars bars;
def dataCount = CompoundValue(1, if IsNaN(dataCount[1]) then 0 else if bullish then dataCount[1] + 1 else dataCount[1], 0);

plot upArrow = if limit_arrow_plot and HighestAll(dataCount) - dataCount <= show_x_arrows - 1
               then bullish
               else if !limit_arrow_plot
               then bullish
               else Double.NaN;
upArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
upArrow.SetDefaultColor(CreateColor(145, 210, 144));
upArrow.SetLineWeight(4);


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

Revised code and added down arrows, optional lines and labels

Screenshot 2024-04-18 115141.png
Code:
#AvgEMA_cross_VWAP_xArrows_within_xBars
# 5 EMA and VWAP cross. Modified 2 ToS studies and added labels for crosses. By Horserider 7/21/2019

input showlines        = yes;
input showlabels       = yes;
input limit_arrow_plot = yes;
input show_x_arrows    = 1;
input show_within_bars = 1;
input arrowweight      = 3;
input lineweight       = 3;

#VWAP
input timeFrame = {default DAY, WEEK, MONTH};
plot VWAP = reference VWAP(timeframe = timeFrame);
VWAP.SetDefaultColor(GlobalColor("V"));
VWAP.SetLineWeight(lineweight);
VWAP.SetHiding(!showlines);

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

plot AvgExp = ExpAverage(price2[-displace], length);
AvgExp.SetDefaultColor(GlobalColor("A"));
AvgExp.SetLineWeight(lineweight);
AvgExp.SetHiding(!showlines);

#Colors
DefineGlobalColor("A", Color.WHITE);
DefineGlobalColor("V", Color.CYAN);
DefineGlobalColor("U", Color.GREEN);
DefineGlobalColor("D", Color.RED);

#Arrows_limit_plot

def bullish   = AvgExp crosses above VWAP within show_within_bars bars;
def bullCount = CompoundValue(1, if IsNaN(bullCount[1]) then 0 else if bullish then bullCount[1] + 1 else bullCount[1], 0);

plot upArrow  = if limit_arrow_plot and HighestAll(bullCount) - bullCount <= show_x_arrows - 1
                then bullish
                else if !limit_arrow_plot
                then bullish
                else Double.NaN;
upArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
upArrow.SetDefaultColor(GlobalColor("U"));
upArrow.SetLineWeight(arrowweight);

def bearish   = AvgExp crosses below VWAP within show_within_bars bars;
def bearCount = CompoundValue(1, if IsNaN(bearCount[1]) then 0 else if bearish then bearCount[1] + 1 else bearCount[1], 0);

plot dnArrow  = if limit_arrow_plot and HighestAll(bearCount) - bearCount <= show_x_arrows - 1
                then bearish
                else if !limit_arrow_plot
                then bearish
                else Double.NaN;
dnArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
dnArrow.SetDefaultColor(GlobalColor("D"));
dnArrow.SetLineWeight(arrowweight);


AddLabel(showlabels, "Buy ", if AvgExp > VWAP then GlobalColor("U") else Color.GRAY);
AddLabel(showlabels, "Sell", if AvgExp < VWAP then GlobalColor("D") else Color.GRAY);

#
 

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

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