Assigned color in watchlist for VWAP moving Average


Category:
0
0

Hello Pete.  I would like to assign a background color to my watchlist column which will let me know if the current VWAP is greater than or less than the 50 period exponential VWAP moving average.  If the VWAP is greater than the 50 period exponential moving average of VWAP the background color will appear as green.  If the VWAP is less than the moving average the background would appear as red.  Thank you for your help!

Marked as spam
Posted by (Questions: 19, Answers: 18)
Asked on November 1, 2019 8:09 am
265 views
0
Private answer

To save space I will use a reference to the built-in study named VWAP instead of the entire code used to generate it.

Here is your custom wacthlist column:

input maLength = 50;
input maType = AverageType.EXPONENTIAL;
input timeFrame = {default DAY, WEEK, MONTH};
def vwapValue = reference VWAP(-2, 2, timeFrame)."VWAP";
def ma = MovingAverage(maType, vwapValue, maLength);
plot diff = ma - vwapValue;
diff.AssignValueColor(if diff == 0 then Color.CURRENT else Color.BLACK);
AssignBackgroundColor(if diff > 0 then Color.GREEN else if diff < 0 then Color.RED else Color.CURRENT);

Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on November 1, 2019 12:45 pm
0
Thank you Pete!
( at November 1, 2019 2:32 pm)