set text and color of label when price above or below EMA and VWAP


Category:
0
0

Hello Hahn,

I wanted to know if you could create a chart label for the 5 minute chart. The label conditions should be

 

  1. By default, if the stock has done more than 1.5 million shares of volume already on the day, the value should always say “DO NOT SHORT” regardless of where the price is located with a red background and white text

2.  If the price (close) is above the 9EMA and VWAP on chart with less than 1 million shares of volume traded on the the day, THEN label should say        “COVER SHORT” with a green background)

3.   If the price (close) is below the 9EMA on VWAP chart with less than more than 1 million shares of volume traded on the day, THEN label should say “Ready for SHORT” with a yellow background).

 

 

 

Thank you

Marked as spam
Posted by (Questions: 22, Answers: 63)
Asked on September 4, 2018 11:23 am
436 views
0

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.

( at September 8, 2018 12:25 pm)
0

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

( at September 9, 2018 4:40 am)
0
Private answer

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);

Marked as spam
Posted by (Questions: 37, Answers: 4117)
Answered on September 10, 2018 9:40 am