PPS trend to color background outside bollinger bands


Category:
0
0

Hello, I was wondering if you can show me how to correctly addclouds outside bollingerband and color them accordingly, green if trending up and red if its trending down.

I can only seem to color half portion of the background,  and my color condition doesn’t seem to work accordingly.

Please see attached text file for reference.

Thank you.

 

Attachments:
Marked as spam
Posted by (Questions: 8, Answers: 2)
Asked on February 18, 2023 10:02 am
200 views
0
Private answer

Your original title for this question was far too vague to be useful to the rest of our viewers. I updated the title to include all of the most important details. This will help other viewers to locate this question using the search function.

This request is mostly answered by the following previous post:

https://www.hahn-tech.com/ans/color-background-from-abovebelow-based-on-vwap/

However that solution only provided shading above and below a single line (the VWAP). This solution is a bit more complex in that it must deal with 2 plots. And if we want to add shading to above and below the bollinger bands we have to use 4 separate AddCloud() statements.

Can it be down with 2? Perhaps. But this is what I was able to complete within the restricted time period I have for free solutions I provide in this forum.

input showCloud = yes;
#===bollingerbands
input price = close;
input displace = 0;
input length = 9;
input Num_Dev_Dn = -2.0;
input Num_Dev_up = 2.0;
def sDev = StDev(data = price[-displace], length = length);
plot midLine = ExpAverage(data = price[-displace], length = length);
midLine.SetDefaultColor(Color.white);
Midline.Setstyle(Curve.short_DASH);
Midline.SetlineWeight(2);
plot lowerBand = midLine + Num_Dev_Dn * sDev;
lowerBand.SetDefaultColor(Color.white);
lowerBand.SetLineWeight(1);
plot upperBand = midLine + Num_Dev_up * sDev;
upperBand.SetDefaultColor(Color.white);
upperBand.SetLineWeight(1);
#========PPS BUY AND SELL SIGNALS
plot buy = !IsNaN(PPS()."buySignal");
buy.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
buy.SetDefaultColor(Color.white);
buy.SetLineWeight(5);
plot sell = !IsNaN(PPS()."SellSignal");
sell.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
sell.SetDefaultColor(Color.MAGENTA);
sell.SetLineWeight(5);
#=====PPS Trend====
def ppsTrend = if buy then 1 else if sell then 0 else ppsTrend[1];
def upTrend = ppsTrend == 1;
def downTrend = ppsTrend == 0;
AddCloud(if showCloud and upTrend then upperBand else Double.NaN, if showCloud and upTrend then Double.POSITIVE_INFINITY else Double.NaN, Color.GREEN, Color.GREEN);
AddCloud(if showCloud and upTrend then lowerBand else Double.NaN, if showCloud and upTrend then Double.NEGATIVE_INFINITY else Double.NaN, Color.GREEN, Color.GREEN);
AddCloud(if showCloud and downTrend then lowerBand else Double.NaN, if showCloud and downTrend then Double.NEGATIVE_INFINITY else Double.NaN, Color.RED, Color.RED);
AddCloud(if showCloud and downTrend then upperBand else Double.NaN, if showCloud and downTrend then Double.POSITIVE_INFINITY else Double.NaN, Color.RED, Color.RED);

I have included a screenshot below showing how this solution appears on the chart.

Attachments:
Marked as spam
Posted by (Questions: 37, Answers: 4118)
Answered on February 18, 2023 10:44 am