# zscore_rng_00
#https://usethinkscript.com/threads/painting-horizontal-clouds.14019/
#def cond3 = (if((zscore > -0.01 and zscore < 0.01))
# https://usethinkscript.com/threads/z-score-lower-indicator-modification-for-thinkorswim-plotting-a-z-score-for-a-composite-symbol-below-a-chart-of-the-ndx-nasdaq-100.6714/
[QUOTE="halcyonguy, post: 116477, member: 10697"]
this will draw a cloud when a trigger happens and continue until the end of day
i used a zscore study i had, not sure if it is the same one you mentioned.
new code added to the end of the zscore study
[CODE]# zscore_rng_00
#https://usethinkscript.com/threads/painting-horizontal-clouds.14019/
#def cond3 = (if((zscore > -0.01 and zscore < 0.01))
# https://usethinkscript.com/threads/z-score-lower-indicator-modification-for-thinkorswim-plotting-a-z-score-for-a-composite-symbol-below-a-chart-of-the-ndx-nasdaq-100.6714/
declare lower;
input price = close;
input length = 20;
input ZavgLength = 20;
def oneSD = stdev(price,length);
def avgClose = simpleMovingAvg(price,length);
def ofoneSD = oneSD*price[1];
def Zscorevalue = ((price-avgClose)/oneSD);
def avgZv = average(Zscorevalue,20);
plot Zscore = ((price-avgClose)/oneSD);
Zscore.setPaintingStrategy(paintingStrategy.HISTOGRAM);
Zscore.setLineWeight(2);
Zscore.assignValueColor(if Zscore > 0 then color.dark_green else color.dark_green);
plot avgZscore = average(Zscorevalue,ZavgLength);
avgZscore.setPaintingStrategy(paintingStrategy.LINE);
plot zero = 0;
plot one = 1;
plot negone = -1;
plot two = 2;
plot negtwo = -2;
zero.setDefaultColor(color.black);
#-------------------------------
# add new code
def na = double.nan;
input end = 1600;
# stop cloud at end of day
def stop = if secondsfromTime(end) >= 0 then 1 else 0;
# check if a new day starts
def newday = getday() != getday()[1];
# set a condition to 1 if triggered
# if a newday , reset to 0
# if end of day, reset
# repeat previoius value, till end of day
def cond3 = if newday then 0
else if stop then 0
else if (zscore > -0.01 and zscore < 0.01) then 1
else cond3[1];
# set top and bottom values for cloud
def top = if cond3 and !stop then double.positive_infinity else na;
def bot = double.negative_infinity;
# draw a cloud when a trigger occurs, and continue cloud for the remainder of the day
AddCloud(top , bot , Color.yellow, Color.yellow);
#