Alert on stock touching the bottom vwap


Category:
1
0

How do I set an alert in TOS when price touches the bottom VWAP? This would be useful as a good time to know when a stock is oversold and potentially a good buy. For example, I’d like to be alerted when JNUG hits the bottom VWAP at the two points in the snapshot. Thanks.

Attachments:
Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on October 22, 2018 6:25 pm
1524 views
0

One question before I proceed with the solution. You posted this in the “Chart Studies” topic and are requesting an alert. So unless you explain further, the solution will be for a chart study that sounds an audible alert while the symbol currently plotted on the chart reaches your specification.

( at October 23, 2018 7:38 am)
0

That is correct. I am looking for an audible alert for the chart study. Please proceed. thanks.

( at October 26, 2018 11:01 am)
1
Private answer

So what we do here is we copy the code from the standard VWAP study that comes with Thinkorswim and add two lines at the very end. This is the final result:

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 VWAP = price;
plot UpperBand = price + numDevUp * deviation;
plot LowerBand = price + numDevDn * deviation;
VWAP.setDefaultColor(getColor(0));
UpperBand.setDefaultColor(getColor(2));
LowerBand.setDefaultColor(getColor(4));
Alert(close > UpperBand, "Close above lower band", Alert.BAR, Sound.RING);
Alert(close < LowerBand, "Close below lower band", Alert.BAR, Sound.RING);

Marked as spam
Posted by (Questions: 37, Answers: 4084)
Answered on October 26, 2018 11:13 am