Ok, after we have some clarification on what was requested we have a solution:
input numDevDn = -2.0;
input numDevUp = 2.0;
input timeFrame = {default DAY, WEEK, MONTH};
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));
def UpperBand = price + numDevUp * deviation;
def LowerBand = price + numDevDn * deviation;
def width = UpperBand - LowerBand;
def wider = width > width[1];
plot scan = wider and volume > volume[1];
Keep in mind that you posted this in the “Stock Scanners” topic. A stock scanner has nothing to do with a watchlist. There is no such thing as a “watchlist scan”. So this code does not work in a watchlist. It works as a Study Filter in a custom scan. (correct terminology is essential. so learn to use the correct terms)
If you need this to work in a watchlist, you will need to post a new request in the watchlist topic. You will also need to define which value to display in the watchlist column as well as any logic based dynamic background color to apply to the rows in the watchlist column.
Since you did not post a screenshot showing what this looks like on a chart I want to make sure I understand what this looks like. This two min bar has wider and VWAP bands than previous bar AND this two min bar has higher volume than previous bar. You see, “increasing volume” is a bit vague with many potential solutions. I have stated it in it’s purest form. Let me know if there are more details.
Hello Mr. Hahn,
I am looking for the two min bar to have wider vwap bands than the previous bar. Both top band and bottom band. Exactly what you mentioned.
Thanks,
P.S. I tried attaching a screenshot not sure if it went through.
Thank you very much Mr. Hahn, you are the only programmer who is willing to help.
Words can’t express how much I appreciate your help.