Adding Vertical Cloud background to lower study - Z Score

BBDPDC

Member
Hello folks

Feel a bit silly for asking but I can't work it out hence falling on the mercy of the group for help.

I grabbed the ZScore lower study a while ago and have updated to just show a plotted line but with positive/negative colours to indicate trend (I find this traffic light colouring suits my simple brain).

I had an idea that I would combine this study as a background on a MACD_BB lower as I use the ZScore plot as a confirmation only and want to save space/simplify the chart.....so the question is, how do I covert my line colouring to a vertical cloud background. I got as far as the below but struggling with the code that includes the infinity statements to make it vertical and getting the 4 colours in that I wanted....is that even possible?

I don't remember where i got the original code from so thanks to the author and apologies if you think I've butchered the code unnecessarily.

sRMCbM4.png


Code:
#Computes and plots the Zscore
def ZavgLength = 20 ;
def oneSD = StDev(close, 20);
def avgClose = SimpleMovingAvg(close, 20);
def ofoneSD = oneSD * close[1];
def Zscorevalue = ((close - avgClose) / oneSD);
def avgZv = Average(Zscorevalue, 20);
def Zscore = ((close - avgClose) / oneSD);
# ########################################################
# charting & formatting:
declare lower;
#This is an optional plot that will display the momentum of the Z-Score average
DefineGlobalColor("LabelGreen",  CreateColor(0, 165, 0)) ;
plot pavgZscore = Average(Zscorevalue, ZavgLength);
plot momZAvg = (avgZv - avgZv[5]);
plot pZscore = Zscore;
plot zero = 0;

def pos1         = pavgZscore >= 0;
def neg1         = pavgZscore < 0;
def up1        = pavgZscore >= pavgZscore[1];
def dn1         = pavgZscore < pavgZscore[1];

def PosUp1 = pos1 and up1;
def PosDn1 = pos1 and dn1;
def NegDn1 = neg1 and dn1;
def NegUp1 = neg1 and up1;

pavgZscore.AssignValueColor(if PosUp1 then Color.GREEN else if PosDn1 then Color.DARK_GREEN else if NegDn1 then Color.RED else if NegUp1 then Color.YELLOW else Color.YELLOW);
zero.SetDefaultColor(GetColor(0));

AddCloud(posup1 or negup1, negdn1 or posdn1, Color.light_GREEN, Color.light_RED);

#=====================================
 
Hello folks

Feel a bit silly for asking but I can't work it out hence falling on the mercy of the group for help.

I grabbed the ZScore lower study a while ago and have updated to just show a plotted line but with positive/negative colours to indicate trend (I find this traffic light colouring suits my simple brain).

I had an idea that I would combine this study as a background on a MACD_BB lower as I use the ZScore plot as a confirmation only and want to save space/simplify the chart.....so the question is, how do I covert my line colouring to a vertical cloud background. I got as far as the below but struggling with the code that includes the infinity statements to make it vertical and getting the 4 colours in that I wanted....is that even possible?

I don't remember where i got the original code from so thanks to the author and apologies if you think I've butchered the code unnecessarily.

See if this helps.
Code:
#Computes and plots the Zscore
def ZavgLength = 20 ;
def oneSD = StDev(close, 20);
def avgClose = SimpleMovingAvg(close, 20);
def ofoneSD = oneSD * close[1];
def Zscorevalue = ((close - avgClose) / oneSD);
def avgZv = Average(Zscorevalue, 20);
def Zscore = ((close - avgClose) / oneSD);
# ########################################################
# charting & formatting:
declare lower;
#This is an optional plot that will display the momentum of the Z-Score average
DefineGlobalColor("LabelGreen",  CreateColor(0, 165, 0)) ;
plot pavgZscore = Average(Zscorevalue, ZavgLength);
plot momZAvg = (avgZv - avgZv[5]);
plot pZscore = Zscore;
plot zero = 0;

def pos1         = pavgZscore >= 0;
def neg1         = pavgZscore < 0;
def up1        = pavgZscore >= pavgZscore[1];
def dn1         = pavgZscore < pavgZscore[1];

def PosUp1 = pos1 and up1;
def PosDn1 = pos1 and dn1;
def NegDn1 = neg1 and dn1;
def NegUp1 = neg1 and up1;

pavgZscore.AssignValueColor(if PosUp1 then Color.GREEN else if PosDn1 then Color.DARK_GREEN else if NegDn1 then Color.RED else if NegUp1 then Color.YELLOW else Color.YELLOW);
zero.SetDefaultColor(GetColor(0));

#AddCloud(posup1 or negup1, negdn1 or posdn1, Color.light_GREEN, Color.light_RED);

def cond1 = if PosUp1
          then Double.POSITIVE_INFINITY
          else Double.NEGATIVE_INFINITY;
def cond2 = if Posdn1
          then Double.POSITIVE_INFINITY
          else Double.NEGATIVE_INFINITY;
def cond3 = if NegDn1
          then Double.POSITIVE_INFINITY
          else Double.NEGATIVE_INFINITY;
def cond4 = if NegUp1
          then Double.POSITIVE_INFINITY
          else Double.NEGATIVE_INFINITY;
input showclouds = yes;
AddCloud(if showclouds
         then cond1
         else double.nan,
         cond2,
         Color.GREEN, Color.Dark_Green);
AddCloud(if showclouds
         then cond3
         else double.nan,
         cond4,
         Color.Red, Color.Yellow);

#=====================================
Capture.jpg
 

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
491 Online
Create Post

Similar threads

Similar threads

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top