Having filled in the gaps in the list of conditions, here is the solution. I have not tested this, other than to check for errors. It’s plot without error.
This request seems to me to have little value to the rest of our audience. I really appreciate your participation in the Q&A forum. However your projects tend to be very narrow in scope and only benefit yourself. Leaving the rest of our audience out of the loop. In the future, I will require you submit requests of this nature as a custom project, subject to our rates and terms. There is no point in cluttering up the Q&A forum with one-off solutions to fit only the needs of one individual.
input timeFrame = {default DAY, WEEK, MONTH};
#---------- EMA Section
def ema = ExpAverage(close, 9);
#---------- VWAP Section
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 theVwap = volumeVwapSum / volumeSum;
#---------- Conditions Section
def dayVolume = volume(period = AggregationPeriod.DAY);
def inbound = dayVolume >= 1000000 and dayVolume < 1500000; def noShort = dayVolume >= 1500000;
def priceAboveEmaVwap = close > ema and close > theVwap and dayVolume < 1000000;
def priceBelowEmaVwap = close < ema and close < theVwap and dayVolume < 1000000;
AddLabel(yes,
if inbound then "SQUEEZE INBOUND" else if noShort then "DO NOT SHORT" else if priceAboveEmaVwap then "COVER SHORT" else if priceBelowEmaVwap then "READY FOR SHORT" else "NULL",
if inbound then Color.YELLOW else if noShort then Color.RED else if priceAboveEmaVwap then Color.GREEN else if priceBelowEmaVwap then Color.YELLOW else Color.WHITE);
Just a quick followup. There is a reason I have not provided a solution to this request. I have been waiting for you to come back and read your post again and realize the gaps and errors you left in your specification. I was expecting you to find them and add a comment to your request that corrected the problems.
You didn’t not specify how to handle daily volume greater than 1 million and less than 1.5 million.
Specification 3 contains an error: “with less than more than”. Which is it? It cannot be both.
I see, there is a logic error.
If the volume is greater than 1 million but less than 1.5million. THEN label should say “Squeeze Inbound” with a yellow background.
For specification 3, it should be LESS THAN