Color background from above/below based on VWAP


Category:
0
0

Hi Pete. I am referencing a previous post Questions – Equanimous Trading – Hahn-Tech, LLC in which you created a script that is working great. *see screenshot

I am attempting to do the same thing with VWAP so that when CLOSE < VWAP there is red from top of chart down to VWAP line, and if CLOSE > VWAP there is green from bottom of chart.

My terrible Script below:

def OverVWAP = close is greater than reference VWAP().”VWAP” ;
def UnderVWAP = close is less than reference VWAP().”VWAP” ;
plot VWAPflip = vwap;
vwapflip.DefineColor(“Up”, GetColor(1));
vwapflip.DefineColor(“Down”, GetColor(0));
vwapflip.AssignValueColor (if OverVWAP then vwapflip.color(“Up”) else vwapflip.color(“Down”));
AddCloud(if UnderVWAP then vwapflip else Double.POSITIVE_INFINITY,
if Double.NEGATIVE_INFINITY then vwapflip else vwapflip, Color.MAGENTA, Color.CYAN);
AddCloud(if Double.POSITIVE_INFINITY then vwapflip else vwapflip,
if UnderVWAP then vwapflip else Double.NEGATIVE_INFINITY, Color.CYAN, Color.MAGENTA);

 

Attachments:
Marked as spam
Posted by (Questions: 7, Answers: 1)
Asked on June 10, 2022 11:29 am
373 views
0
Private answer

The link you provided in your question was not a direct link to the previous post you mentioned. It was a link to a page which lists all of the questions you have posted. Since this is subject to change I will provide a direct link to the previous post here:

https://www.hahn-tech.com/ans/invert-shading-on-moving-average-columns/

The entire key to this technique is contained entirely within the last two lines of code from that previous post. I have included them here so you understand which portion of the code is doing ALL the work.

AddCloud(if maOne > maOne[1] then maOne else Double.POSITIVE_INFINITY,
if Double.NEGATIVE_INFINITY then maOne else maOne < maOne[1], Color.MAGENTA, Color.CYAN); AddCloud(if Double.POSITIVE_INFINITY then maOne else maOne > maOne[1],
if maOne < maOne[1] then maOne else Double.NEGATIVE_INFINITY, Color.CYAN, Color.MAGENTA);

There are many errors in the code you provided so I will be making extensive changes to it so that it will work correctly.

plot vwapValue = reference VWAP().VWAP;
vwapValue.DefineColor(“Up”, GetColor(1));
vwapValue.DefineColor(“Down”, GetColor(0));
vwapValue.AssignValueColor (if close > vwapValue then vwapValue.color(“Up”) else vwapValue.color(“Down”));
AddCloud(if close > vwapValue then vwapValue else Double.POSITIVE_INFINITY, if Double.NEGATIVE_INFINITY then vwapValue else close < vwapValue, vwapValue.color(“Down”), vwapValue.color(“Up”)); AddCloud(if Double.POSITIVE_INFINITY then vwapValue else close > vwapValue , if close < vwapValue then vwapValue else Double.NEGATIVE_INFINITY, vwapValue.color(“Up”), vwapValue.color(“Down”));

The only thing you needed to do is to plot the VWAP value and replace the references to maOne with the name of the plot "vwapValue". There were a few other minor tweaks but I will let you discover those on your own.

Marked as spam
Posted by (Questions: 37, Answers: 4087)
Answered on June 10, 2022 6:38 pm