# need help with a horizontal line code

#### JJJJJJ11111

##### Member
I'm trying to create a line on the bar.
which will use the last close bar as reference.
then plot these horizontal lines (ideally these lines can be only shown to next bar only or able to define how many days ahead be plotted on the chart.)
1. +30%
2.+5%
3. -5%
4. -30%

I'm trying to create a line on the bar.
which will use the last close bar as reference.
then plot these horizontal lines (ideally these lines can be only shown to next bar only or able to define how many days ahead be plotted on the chart.)
1. +30%
2.+5%
3. -5%
4. -30%

Input offset to locate desired close.
Input length to determine the number of bars from that close to plot forward

Code:
``````input offset = 1;
input length = 2;
input H1 = 5;
input H2 = 30;
input L1 = 5;
input L2 = 30;
def  bn  = BarNumber();
def xbn  = HighestAll(if close[offset] then bn else Double.NaN);
def   c  = if IsNaN(close) then c[1] else close[offset];

plot x   = if Between(bn, xbn - 1, xbn + length) then c else Double.NaN;
plot xH1 = x * (1 + H1 / 100);
plot xH2 = x * (1 + H2 / 100);
plot xL1 = x * (1 - L1 / 100);
plot xL2 = x * (1 - L2 / 100);
x.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
xH1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
xH2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
xL1.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
xL2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);``````

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?