Looking for EMA crossover VWAP indicator

C

Craighaber71

Member
2019 Donor
Warehouse
VIP
Hey guys I'm looking for a watchlist script for a 9EMA cross Vwap..With the background color coded to the up/downside....also plot how many bars ago this happened...I've found many online but not like this...

Thanks
 
markos

markos

Well-known member
VIP
@Craighaber71 1st- look in the tutorials for creating watchlists. 2nd- it should look akin to this hack: EMA(9) crosses vwap in the editor.
 
BenTen

BenTen

Administrative
Staff
VIP
Give this a try

Code:
# Price crossing above or below 9 EMA and VWAP
# 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 EMA = ExpAverage(priceMA[-displace], lengthMA);
def UpSignal = priceMA crosses above EMA;
def DownSignal = priceMA crosses below EMA;

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

def VWAP = priceVWAP;
#plot UpperBand = priceVWAP + numDevUp * deviation;
#plot LowerBand = priceVWAP + numDevDn * deviation;
def UpVWAP = price > VWAP;
def DownVWAP = price < VWAP;

def bullish_signal = UpSignal and UpVWAP;
def bearish_signal = DownSignal and DownVWAP;

# Plot Signals
plot bullish = bullish_signal;
bullish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
bullish.SetDefaultColor(Color.CYAN);
bullish.SetLineWeight(3);

plot bearish = bearish_signal;
bearish.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
bearish.SetDefaultColor(Color.CYAN);
bearish.SetLineWeight(3);
 
C

Craighaber71

Member
2019 Donor
Warehouse
VIP
Awesome...Will that work in a watch list
 
wilmanv

wilmanv

Member
Warehouse
VIP
Any VWAP Cross Over Indicator with Moving Average.
 
horserider

horserider

Well-known member
VIP
Please explain more detail of what you want. Not sure what you asked makes much sense.
 
wilmanv

wilmanv

Member
Warehouse
VIP
Thanks to all, I thinks that script above resolve my question
👍 👍 👍
 
B

Bung Bang

New member
Hi! I am trying to get a TOS scanner for EMA(9) crosses VWAP by certain lookback bars (1bar, 2 bars, 3 bars etc) for intraday trading? I am not sure how to change the codes in the watchlist above.; can anybody help ?
 
T

tomsk

Well-known member
VIP
@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;
 
L

Lees

New member
VIP
Is there a way to color code watchlist stocks with custom filed based on price Cross over vwap upper band and vwap lower band and vwap?

i saw a post to mark bullish and bearish when price move above and below vwap but i would like to leave rage that to identify vwap upper and lower band cross also with different coloring so that it will be easy for us to watch the stock when it reaches those levels.
 
P

PapaBear10

New member
2019 Donor
Hi

@BenTen @tomsk , or anyone else available to help, I was wondering if I could get some help to finish up this TOS code for watch-list that I was trying to complete, to show green when 9 ema crosses above vwap within last 3 bars, customizable for timeframes, and opposite as well, if 9 ema crosses below vwap within last 3 bars; Here is what I have gotten started:


input maLengthOne = 9;
input maType=AverageType, EXPONENTIAL
input timeFrame = {default DAY, WEEK, MONTH};
def vwapValue = reference VWAP(-2, 2, timeFrame)."VWAP";
def ma = MovingAverage(maType, vwapValue, maLength);
inputbarsAfterCross = 3;
def crossAbove = maLengthOne > vwap
def crossBelow = maLengthOne < vwap
diff.AssignValueColor(if ma == vwap then Color.CURRENT else Color.BLACK);
AssignBackgroundColor(if diff > 0 then Color. GREEN else if diff < 0 then Color.RED else Color.CURRENT);

Thank you

Papa
 
P

PapaBear10

New member
2019 Donor
Just a follow up, as I previously did not state the issues I was having:
I am getting the messages invalid statements at the certain lines 2, 7 and 10.
If anyone could advise would be great, I am not a coder, but attempted to piece together what I could;
Thanks in advance @BenTen @tomsk @horserider @netarchitech or anyone else who can help me with this!

input maLengthOne = 9;
input maType=AverageType, EXPONENTIAL
input timeFrame = {default DAY, WEEK, MONTH};
def vwapValue = reference VWAP(-2, 2, timeFrame)."VWAP";
def ma = MovingAverage(maType, vwapValue, maLength);
inputbarsAfterCross = 3;
def crossAbove = maLengthOne > vwap
def crossBelow = maLengthOne < vwap
diff.AssignValueColor(if ma == vwap then Color.CURRENT else Color.BLACK);
AssignBackgroundColor(if diff > 0 then Color. GREEN else if diff < 0 then Color.RED else Color.CURRENT)

Invalid statement: input at 2:1
Invalid statement: def at 7:1
Invalid statement: AssignBackgroundC... at 10:1
 
T

tomsk

Well-known member
VIP
@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
 
Last edited:
S

scottrades

New member
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.
Tom, what would I change here to track price crossing? I've got the following; how to I blend them together? I really like the 3-bars approach, so that it will disappear after the cross happens. I've tried swapping out the input length, etc.

plot vwap = vwap();
AssignBackgroundColor(if close > vwap then Color.DARK_GREEN else if close < vwap then Color.DARK_RED else Color.Dark_ORANGE);
 
H

humanz27

New member
Hello - Has anyone seen a scanner that shows the list of stocks that satisfy the condition where the 9 SMA has crossed VWAP x mins ago (x can be configured or default to 5 mins)??
 

Top