Alert on stock touching the bottom/top vwap


Category:
0
0

Hello Pete,

Sorry that I initially posted my question in the wrong place. I want to know if VWAP code can be edited for chart study and for scanning. Here is the link for the code that you already shared. Currently, it only gives audible alert. How can we edit this code so it alerts with up/down arrow sign on the chart? I am planning to applied the study chart to my watch list as well if possible.

I really appreciate your help on this.

Thanks,

Shahrom

https://www.hahn-tech.com/ans/alert-on-stock-touching-the-bottom-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 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: 1, Answers: 1)
Asked on February 18, 2020 6:36 pm
372 views
0
Private answer

The signal which generates the alerts are as follows:

close > UpperBand

close < LowerBand

I took those right from the alert statements of the code you included in your question. We only need to add the word plot with a name for the plot and an equal sign at the beginning. Then a semicolon at the end:

plot crossAbove = close > UpperBand;

plot crossBelow = close < LowerBand;

That's it. Not kidding. You can adjust the plot settings through the Edit Studies window to display however you like. But if you want to assign default plot styles that display as arrows we simply add these two lines:

crossAbove.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
crossBelow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);

As for the scan, Thinkorswim allows you to build a scan for any of the plots on the VWAP with just a few clicks of the mouse. No need to use this code and in fact no need to know how to write any code at all. We do this by using the tool called Condition Wizard. Details here:

https://www.hahn-tech.com/thinkorswim-condition-wizard/

Once you learn to use this tool the custom watchlist column will be very simple to deploy as well. Details here:

https://www.hahn-tech.com/thinkorswim-condition-wizard-watchlist/

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on February 19, 2020 8:31 am
0
thank you very much !
( at February 20, 2020 4:20 pm)