3 EMA and VWAP Crossover?



New member
I am new to the forum so wanted to say Hello to everyone. I have a question and hope to get some help.
I wonder if there is a script for knowing when the 9 EMA, 21 EMA and 55 EMA are within a certain range (maybe 5 or 10 cents for example) of the VWAP.
This is similar to the Golden cross over but including VWAP. Attaching 3 samples of the way this signal helps with understanding the trend. Any help will be appreciated.
Thank You


Active member
problem I see is the 3 moving averages will come within your location perimeter at varying times so what is the actual event you want to trigger the cross


New member
Thats true ... these do come close to each other frequently and what I have found is when the 3 ema's and vwap cross over either ascending or descending is a very good signal for taking a position (9 ema crossing over 21 ema and 21 ema crossing over 55 ema....when vwap crosses these three as close possible is a very good indicator). So an arrow showing when this happens or some other type of alert, or maybe if we can set this as a scanner. I was trying to copy few images to show what I mean. How do I attach an image in the post? Thanks a lot.


Active member
upload image to imgur.com and put link in room


Active member
@smvatkar Here is a template indicator I have involving an EMA and VWAP in one https://tos.mx/OWEY8Di . I would probably say that the addition you would try to tack on to this code would need to be in however an alert (or maybe a scan/market watch alert to make it easier to see across multiple assets) where the math looks like: EMA > (VWAP - .2).... to put EMA within 20cents range of VWAP for example. I am not a professional coder, nor have I created any alerts or scanners for my indicators so I cannot assist more than this at the moment. Maybe someone wants to take the idea and run with it


New member
@tradebyday Thanks for sharing. I have seen this one. Please check the images that I just added with the overall 3 ema's crossing with the vwap.


Active member
@smvatkar Here is your template basically. Now just have to add scanning or alerts/labels to identify specifically what you are looking for
# VWAP w/ MovingAvgCrossover

#Created by TradebyDay

input price1 = close;

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

input length = 50;
input length2 = 50;
input length3 = 50;
input displace = 0;

assert(length > 0, "'length' must be positive: " + length);

def EMA = compoundValue(1, EMA[1] + 2 / (length + 1) * (price1[-displace] - EMA[1]), price1[-displace]);
def EMA2 = compoundValue(1, EMA2[1] + 2 / (length2 + 1) * (price1[-displace] - EMA2[1]), price1[-displace]);
def EMA3 = compoundValue(1, EMA3[1] + 2 / (length3 + 1) * (price1[-displace] - EMA3[1]), price1[-displace]);

plot LegacyEMA = EMA;
plot LegacyEMA2 = EMA2;
plot LegacyEMA3 = EMA3;

# End Code


New member
@tradebyday Thanks a lot. I added your code to TOS and have the 3 emas and vwap as shown in the image below.
Now the real challenge is to add the code that can define the proximity of the 3 ema's and vwap within a given range in $ and use this defined range to trigger an alert (or auto refresh scanner).

Similar threads