Crossing VWAP Sound Alert

Is there is script that sound alerts you when candle crosses over or below vwap on the chart you are currently on. Sometimes you have multiple charts open and it would be nice to get an alert if a stock just touched vwap.


Try this, did it on the go so I have not tested it yet.

def bull_cross = close crosses above VWAP;
def bear_cross = close crosses below VWAP;

# Alerts
Alert(bull_cross, " ", Alert.Bar, Sound.Chimes);
Alert(bear_cross, " ", Alert.Bar, Sound.Bell);


Well-known member
Instead of cross we use the low of the then candle is below vwap and the high of the candle is above vwap ...this is better method of scanning for a crossing.


# Alerts
# TD Ameritrade IP Company, Inc. (c) 2011-2020

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 price = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));

plot VWAPx = price;
plot UpperBand = price + numDevUp * deviation;
plot LowerBand = price + numDevDn * deviation;

#instead of cross we use the low the then candle is below vwap and the high of the candle is above vwap
#this is better method of scanning for a crossing
def vwap_cross = low < vwapx and high > vwapx;

Alert(vwap_cross, " ", Alert.BAR, Sound.Chimes);

if you want lower the replace "def vwap_cross = low < vwapx and high > vwapx" with

def vwap_cross = low < LowerBandand and  high > LowerBand;
Last edited:


New member
Thank you very much @XeoNoX and @rad14733. I was actually looking for a way to reference the lower band of vwap without writing all the remaining code. I though we could use the existing VWAP Study from thinkorswim to get the lowerband value. What I was looking to do is :

def lowvwap = VWAP()."LowerBand";
def condition = low < lowvwap and close > lowvwap + ATR();
AddOrder(OrderType.BUY_TO_OPEN, condition, tradeSize = 1, tickcolor = Color.GREEN, arrowcolor = Color.GREEN, name = "L-vwap");

It looks like tos does not like VWAP()."LowerBand" either.

Thanks again!!


Well-known member
@ktrades You had

lowvwap + ATR();

You are adding the value of the lower VWAP and the value of the ATR, that in theory would be considered a big move... what are you trying to do?

Similar threads