Volume Weighted Moving Avg VWMA For ThinkorSwim

vro3

Member
Hey guys! I've really fallen in love with the 8 over the 26 as a buy and opposite for sell.
So many times, the lines are so close - I have to zoom in super close to see whats on top. There's gotta be a better way.
I don't know what, but is there a dead simple visual way to tell me if one is over the other?
Ideas I've had are a "yes or no" in the top left. a way to just change the background of the lower indicator. an alert? something dead simple?

Thanks!!

BenTen

Staff member
Staff
VIP
Are you talking about the 8 moving average and the 26 moving average? Do you want to see arrows when they crossover?

vro3

Member
Are you talking about the 8 moving average and the 26 moving average? Do you want to see arrows when they crossover?

actually - no. IT's the EMA8 and a VWMA26.
I'd love something as simple as "is the 8 over the 26 Y or N"
or, any other concept that I don't know about. would be awesome in a WL indicator too.

is that possible? any ideas?

Last edited:

vro3

Member
input length = 26;
def vwma = sum(volume * close, length) / sum(volume, length);
plot Value = vwma;

This is my VWMA script.

MerryDay

Staff member
Staff
VIP
There are several ways to accomplish what you need and because I have nothing better to do while I wait for my brownies to finish baking,
I wrote up some samples for you:

Code:
``````plot ema8 = ExpAverage(close, 8);
plot vwma26 = Sum(volume * close, 26) / Sum(volume, 26);
plot MAcrossUP = ema8 crosses above vwma26 ;
plot MAcrossDN = ema8 crosses below vwma26 ;

#this will make your EMA line change color whenever it is above your volume
ema8.assignValueColor(if ema8 > vwma26 then color.blue else color.magenta);
ema8.setlineWeight(2);

#this will give you an arrow whenever your EMA crosses above your volume
MAcrossUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
MAcrossUP.SetLineWeight(2);
MAcrossUP.SetDefaultColor(color.blue) ;

#this will give you an arrow whenever your EMA crosses below your volume
MAcrossDN.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);
MAcrossDN.SetLineWeight(2);
MAcrossDN.SetDefaultColor(color.magenta) ;

#this will give you a cloud of colors: green when above, pink when below
AddCloud(ema8, vwma26, color.green, color.pink);``````

HTH

vro3

Member
Soooo, I'm really happy the script, but please tell me more about these brownies.

No, but seriously, thank you so much! This is exactly the start I was looking for.
I'll put this into use and see how it helps.

vro3

Member
SO - I'm not sure WHAT/WHY, but i can see there's a difference between our EMA8 lines. I tried putting my code into your plot and it didnt work.
But also - i'm not sure which EMA8 is more true!

input price = close;
input length = 8;
input highLowLength = 10;

def multiplier1 = 2 / (length + 1);
def multiplier2 = AbsValue((close - Lowest(low, highLowLength)) - (Highest(high, highLowLength) - close)) / (Highest(high, highLowLength) - Lowest(low, highLowLength));
def alpha = multiplier1 * (1 + multiplier2);
def ma = CompoundValue(1, ma[1] + alpha * (price - ma[1]), Average(price, length));

plot AEMA = ma;
AEMA.SetDefaultColor(GetColor(1));
is my code.
It seems to be a little quicker, but i dont know that it means its better. It's just what I've been using. any input on THAT?

Also, I'm not sure what they're called - but the data boxes that live up in the top left corner of charts. Could that be used to display a simple "yes / no" as well?

THANK YOU!
There are several ways to accomplish what you need and because I have nothing better to do while I wait for my brownies to finish baking,
I wrote up some samples for you:

Code:
``````plot ema8 = ExpAverage(close, 8);
plot vwma26 = Sum(volume * close, 26) / Sum(volume, 26);
plot MAcrossUP = ema8 crosses above vwma26 ;
plot MAcrossDN = ema8 crosses below vwma26 ;

#this will make your EMA line change color whenever it is above your volume
ema8.assignValueColor(if ema8 > vwma26 then color.blue else color.magenta);
ema8.setlineWeight(2);

#this will give you an arrow whenever your EMA crosses above your volume
MAcrossUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
MAcrossUP.SetLineWeight(2);
MAcrossUP.SetDefaultColor(color.blue) ;

#this will give you an arrow whenever your EMA crosses below your volume
MAcrossDN.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_down);
MAcrossDN.SetLineWeight(2);
MAcrossDN.SetDefaultColor(color.magenta) ;

#this will give you a cloud of colors: green when above, pink when below
AddCloud(ema8, vwma26, color.green, color.pink);``````

HTH
day one. LOVE the cloud. that is definately a great help. The arrows get lost a little in the lines / candle sticks. working on the right color scheme for those. I didn't set the colors well for the color change. (im also slightly color blind, which is part of my need for visual help with this.! small colors just become a blur for me!)

Either way - this is such a help. Can I turn this into a WL category too? Say, white if over 26 and black if under?

MerryDay

Staff member
Staff
VIP
1. You have the definition of an AEMA. You can read more about AEMA's here: https://tlc.thinkorswim.com/center/reference/Tech-Indicators/studies-library/A-B/AdaptiveEMA.html. I don't use them and couldn't find any in-depth discussions about them on this site. If it is giving you the results you want, then continue to use it.
2. If you are having difficulty viewing the colors, they can be changed to suit your needs. A list of colors available are here: https://tlc.thinkorswim.com/center/reference/thinkScript/Constants/Color
3. I updated your study w/ your version of AEMA instead of the EMA.
4. Another way to highlight your moving average crosses is to change the candle color. I added an example at the end of this code:
Code:
``````# Put a '#' at the beginning of any of the scenarios you don't want to use.  Or just delete those lines.
# AEMA - VWMA crossover study
# compiled by vro3
input price = close;
input length = 8;
input highLowLength = 10;

def multiplier1 = 2 / (length + 1);
def multiplier2 = AbsValue((close - Lowest(low, highLowLength)) - (Highest(high, highLowLength) - close)) / (Highest(high, highLowLength) - Lowest(low, highLowLength));
def alpha = multiplier1 * (1 + multiplier2);
def ma = CompoundValue(1, ma[1] + alpha * (price - ma[1]), Average(price, length));

plot AEMA = ma;
AEMA.SetDefaultColor(GetColor(1));
plot vwma26 = Sum(volume * close, 26) / Sum(volume, 26);
# ########################################################
# charting and formatting:

#this will make your EMA line change color whenever it is above your volume
AEMA.AssignValueColor(if AEMA > vwma26 then Color.BLUE else Color.MAGENTA);
AEMA.SetLineWeight(2);

#this will give you an arrow whenever your EMA crosses above your volume
plot MAcrossUP = AEMA crosses above vwma26 ;
MAcrossUP.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
MAcrossUP.SetLineWeight(2);
MAcrossUP.SetDefaultColor(Color.BLUE) ;

#this will give you an arrow whenever your EMA crosses below your volume
plot MAcrossDN = AEMA crosses below vwma26 ;
MAcrossDN.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
MAcrossDN.SetLineWeight(2);
MAcrossDN.SetDefaultColor(Color.MAGENTA) ;

#this will give you a cloud of colors: green when above, pink when below
AddCloud(AEMA, vwma26, Color.GREEN, Color.PINK);

#############################  NEW --- Changes candle color ################################
#this will change the color of the candles on your chart each time your averages cross:
AssignPriceColor(if AEMA crosses above vwma26 then Color.YELLOW else if AEMA crosses below vwma26 then Color.MAGENTA else Color.CURRENT);
#############################  NEW --- Changes candle color ################################``````

vro3

Member
I dont know who you are, but I am incredibly thankful for you!

PT_Scalper

Member
VIP
I'm using 2 VWMA indicators - one for when it's up (Green Plot) and one for when it comes down (Red Plot).

Can someone help with 2 items?

1- Combine the two scripts into one Script
2- Instead of having the Plots on the chart, an alternative option where Green Plot stays green until it turns red

VWMA Crossover Up (Green Plot);
Code:
``````# MyVWMACrossoverUp

input vwmaLength = 20;
input maLength = 20;
input averageType = AverageType.simple;

def VWMA = Sum(volume * close, vwmaLength) / Sum(volume, vwmaLength);
def MA = MovingAverage(averageType, close, maLength);

def priceCrossAboveSMA = VWMA [1] < MA [1] and VWMA > MA;

plot Scan1 = priceCrossAboveSMA;``````

VWMA Crossover Down (Red Plot);
Code:
``````# MyVWMACrossoverDown

input vwmaLength = 20;
input maLength = 20;
input averageType = AverageType.SIMPLE;

def VWMA = Sum(volume * close, vwmaLength) / Sum(volume, vwmaLength);
def MA = MovingAverage(averageType, close, maLength);

def priceCrossBelowSMA = VWMA [1] > MA [1] and VWMA < MA;

plot Scan1 = priceCrossBelowSMA;``````

Here is what it looks like on my chart;

Thank you!

horserider

Well-known member
VIP
Code:
``````input vwmaLength = 20;
input maLength = 20;
input averageType = AverageType.SIMPLE;

def VWMA = Sum(volume * close, vwmaLength) / Sum(volume, vwmaLength);
def MA = MovingAverage(averageType, close, maLength);

def priceCrossBelowSMA = VWMA [1] > MA [1] and VWMA < MA;

plot Scandown = priceCrossBelowSMA;

def priceCrossAboveSMA = VWMA [1] < MA [1] and VWMA > MA;

plot Scanup = priceCrossAboveSMA;``````

PT_Scalper

Member
VIP
Hi @horserider,

EDIT: Thanks for this. Weird but I have to add "Declare Lower;" to the script then move it to the top but it works great as one Study.

Now if I can get some help in plotting it similar to this;
- Green above and Red Below (it's a SuperTrend Study)

Thanks again.

Last edited:

horserider

Well-known member
VIP
Code:
``````input vwmaLength = 20;

plot VWMA = Sum(volume * close, vwmaLength) / Sum(volume, vwmaLength);

VWMA.AssignValueColor(if VWMA > close then Color.RED else Color.GREEN);``````

mansor

Active member
Code:
``````input vwmaLength = 20;
input maLength = 20;
input averageType = AverageType.SIMPLE;

def VWMA = Sum(volume * close, vwmaLength) / Sum(volume, vwmaLength);
def MA = MovingAverage(averageType, close, maLength);

def priceCrossBelowSMA = VWMA [1] > MA [1] and VWMA < MA;

plot Scandown = priceCrossBelowSMA;

def priceCrossAboveSMA = VWMA [1] < MA [1] and VWMA > MA;

plot Scanup = priceCrossAboveSMA;``````
what should I do to have this script produce inverted spikes (spiking down) for scandown? Using this as lower script & trying to aling w/ deepwater lower script, for those who want to know my reasoning for using it as a lower script using 1d2m chart. TIA everyone

PT_Scalper

Member
VIP
Unfortunately the scripts aren't doing what I'd like them to do.

Thanks anyway.

horserider

Well-known member
VIP
Unfortunately the explanations of what you want are not clear. You were talking about a VWMA and then seem to switch to a parabolic sar type chart example.

PT_Scalper

Member
VIP
Unfortunately the explanations of what you want are not clear. You were talking about a VWMA and then seem to switch to a parabolic sar type chart example.

No worries... I was just looking for any ideas that would make the chart easy on the eyes.

Well-known member
VIP
No worries... I was just looking for any ideas that would make the chart easy on the eyes.

Perhaps using boolean arrows would be more elegant... Those full chart trigger spikes are brutal imho...

skaboy

New member
No worries... I was just looking for any ideas that would make the chart easy on the eyes.

"plot Scanup = priceCrossAboveSMA;"

what do you want your plot to look like?
Lines, dots, dashes?