Price Crosses Above VWAP Indicator for ThinkorSwim

Sonny

Active member
VIP
Hi,

I want to submit the following chart study code that shows when the price crosses above VWAP. A blue arrow and sound is generated on the chart when this happens. This is useful when tracking a stock for a red to green move, especially a low float, low priced stock with a catalyst in the early time frame (9:30am to 11am). Please pass this on!

Thanks,
Sonny

n8tyw8P.png


Code:
#Price crosses above 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 price = volumeVwapSum / volumeSum;
def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0));
plot vwapValue = price;
plot crossingAbove = close[1] < vwapValue[1] and close > vwapValue;
crossingAbove.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
crossingAbove.SetDefaultColor(Color.CYAN);
crossingAbove.SetLineWeight(1);
Alert(crossingAbove[1], "Cross Above VWAP", Alert.BAR, Sound.Bell);
 
Last edited by a moderator:

TXJ111

New member
Thanks for the code. Is there anyway to get an alert via email or text using a 1 or 5 minute time frame if you are not at your computer?
 

BenTen

Administrative
Staff member
Staff
VIP
Adding to what @Sonny said, you can also create a scanner for this indicator, save it as a watclist, and then get alerted for new changes within that watchlist.
 

Similar threads

Top