# Plot Daily High & Low Lines upon Trigger

#### hugocsalazar

##### New member
HI!
Would like to have the day's high and the day's low plot if the zscore crosses its average
as found here.

The lines should plot when the trigger occurs and stay static.
Only change on the next occurrence of the trigger.

Sorry if I´m not that clear, my english is not the best!

Ruby:
declare upper;

input price = close;
input length = 20;
input ZavgLength = 20;

#Initialize values
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);

#Compute and plot Z-Score

DEF avgZscore = average(Zscorevalue,ZavgLength);
#avgZscore.setPaintingStrategy(paintingStrategy.LINE);

DEF Zscore = ((price-avgClose)/oneSD);

#Plot zero line and extreme bands
DEF zero = 0;
DEF two = 2;
DEF one = 1;
DEF negone = -1;
DEF negtwo = -2;
def three = 3;
def negthree = -3;

def condition1 = zscore crosses above avgZscore and avgzscore < -.75;
def condition2 = zscore crosses below avgZscore and avgzscore > .75;

# Plot arrows
plot UArrow = if condition1 is true then 1 else 0;
UArrow.SetDefaultColor(Color.white);
UArrow.SetPaintingStrategy(PaintingStrategy.Boolean_arrow_up);
Uarrow.setLineWeight(4);
plot DArrow = if condition2 is true then 1 else 0;
DArrow.SetDefaultColor(Color.white);
DArrow.SetPaintingStrategy(PaintingStrategy.Boolean_ARROW_DOWN);
Darrow.setLineWeight(4);

Last edited by a moderator:
Solution
HI!
Would like to have the day's high and the day's low plot if the zscore crosses its average
as found here.

The lines should plot when the trigger occurs and stay static.
Only change on the next occurrence of the trigger.

Sorry if I´m not that clear, my english is not the best!

Ruby:
declare upper;

input price = close;
input length = 20;
input ZavgLength = 20;

#Initialize values
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);

#Compute and plot Z-Score

DEF avgZscore =...
HI!
Would like to have the day's high and the day's low plot if the zscore crosses its average
as found here.

The lines should plot when the trigger occurs and stay static.
Only change on the next occurrence of the trigger.

Sorry if I´m not that clear, my english is not the best!

Ruby:
declare upper;

input price = close;
input length = 20;
input ZavgLength = 20;

#Initialize values
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);

#Compute and plot Z-Score

DEF avgZscore = average(Zscorevalue,ZavgLength);
#avgZscore.setPaintingStrategy(paintingStrategy.LINE);

DEF Zscore = ((price-avgClose)/oneSD);

#Plot zero line and extreme bands
DEF zero = 0;
DEF two = 2;
DEF one = 1;
DEF negone = -1;
DEF negtwo = -2;
def three = 3;
def negthree = -3;

def condition1 = zscore crosses above avgZscore and avgzscore < -.75;
def condition2 = zscore crosses below avgZscore and avgzscore > .75;

# Plot arrows
plot UArrow = if condition1 is true then 1 else 0;
UArrow.SetDefaultColor(Color.white);
UArrow.SetPaintingStrategy(PaintingStrategy.Boolean_arrow_up);
Uarrow.setLineWeight(4);
plot DArrow = if condition2 is true then 1 else 0;
DArrow.SetDefaultColor(Color.white);
DArrow.SetPaintingStrategy(PaintingStrategy.Boolean_ARROW_DOWN);
Darrow.setLineWeight(4);

Try this

Code:
declare upper;

input price = close;
input length = 20;
input ZavgLength = 20;

#Initialize values
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);

#Compute and plot Z-Score

def avgZscore = Average(Zscorevalue, ZavgLength);
#avgZscore.setPaintingStrategy(paintingStrategy.LINE);

def Zscore = ((price - avgClose) / oneSD);

#Plot zero line and extreme bands
def zero = 0;
def two = 2;
def one = 1;
def negone = -1;
def negtwo = -2;
def three = 3;
def negthree = -3;

def condition1 = Zscore crosses above avgZscore and avgZscore < -.75;
def condition2 = Zscore crosses below avgZscore and avgZscore > .75;

# Plot arrows
plot UArrow = if condition1 is true then 1 else 0;
UArrow.SetDefaultColor(Color.WHITE);
UArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_UP);
UArrow.SetLineWeight(4);
plot DArrow = if condition2 is true then 1 else 0;
DArrow.SetDefaultColor(Color.WHITE);
DArrow.SetPaintingStrategy(PaintingStrategy.BOOLEAN_ARROW_DOWN);
DArrow.SetLineWeight(4);

input lineweight = 5;
def zx = if condition1 or condition2 then 1 else 0;
def dh = if SecondsFromTime(0930) == 0 then high else Max(high, dh[1]);
def zh = if zx[1] == 0 and zx then dh else zh[1];
plot dhigh = zh;
dhigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
dhigh.SetLineWeight(lineweight);

def dl = CompoundValue(1, if SecondsFromTime(0930) == 0 then low else Min(low, dl[1]), low);
def zl = if zx[1] == 0 and zx then dl else zl[1];
plot dlow = zl;
dlow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
dlow.SetLineWeight(lineweight);

#

87k+ Posts
429 Online

## The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
• Exclusive indicators
• Proven strategies & setups
• Private Discord community
• Exclusive members-only content
• 1 full year of unlimited support

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?