# Expansion Line

#### UncleTerry

##### New member
More specifically, Im trying to code a horizontal line that is auto drawn across the an intraday chart when the price chart crates a candle wick instead of just an arrow at the bottom of the wick. Is it possible to code using horizontal lines instead of arrows? It would look similar to Robert's on researchtrade.com and on the "Fun with thinkscript" thread but instead of peaks and valleys, it would be candle wicks of a specific body type. (I do not own the rights to this picture)

I created a code the draws an arrow when a candle wick is created on the TOS chart. When ever a candle wick is generated on anytime frame, it creates an arrow at the bottom of the candle. I am sorry if my explanation was unclear. The wick tail setting I have would be 1.5 times the body. I wanted to know if there is a line of code that creates a line extension across the chart from the wick candle signal to the right side of the chart to possibly create a future pridiction of possible inflection points.

Below is what I've been using that is the closet to what I was trying to describe.

#Start
input magnitude =30;

# define top and bottom of candle body
def bodytop = max(open, close);
def bodybottom = min(open, close);

# define and plot the most recent valley
def valley = bodybottom <= Lowest(bodybottom[1], magnitude) and bodybottom <= Lowest(bodybottom[-magnitude], magnitude);
def valleyValue = if BarNumber() < magnitude then Double.NaN else if valley then bodybottom else valleyValue[1];
plot valleyline = valleyValue;
valleyline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
valleyline.SetDefaultColor(Color.magenta);

# extend the current valley line to the right edge of the chart
def countt = if IsNaN(valley) and !IsNaN(valley[1]) then 1 else countt[1] + 1;
plot valleyext = if IsNaN(valley) then GetValue(valleyline, countt) else Double.NaN;
valleyext.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
valleyext.SetDefaultColor(Color.magenta);

# continue the previous valley as a dashed line, but not all the way to the far right of the screen
def oldvalley = if BarNumber() < magnitude then Double.NaN else if valley then valleyValue[1] else oldvalley[1];
plot oldvalleyline = oldvalley;
oldvalleyline.SetPaintingStrategy(PaintingStrategy.DASHES);
oldvalleyline.SetDefaultColor(Color.magenta);

#End Code

Solution
More specifically, Im trying to code a horizontal line that is auto drawn across the an intraday chart when the price chart crates a candle wick instead of just an arrow at the bottom of the wick. Is it possible to code using horizontal lines instead of arrows? It would look similar to Robert's on researchtrade.com and on the "Fun with thinkscript" thread but instead of peaks and valleys, it would be candle wicks of a specific body type. (I do not own the rights to this picture)

I created a code the draws an arrow when a candle wick is created on the TOS chart. When ever a candle wick is generated on anytime frame, it creates an arrow at the bottom of the candle. I am sorry if my explanation was unclear. The wick tail setting I...
More specifically, Im trying to code a horizontal line that is auto drawn across the an intraday chart when the price chart crates a candle wick instead of just an arrow at the bottom of the wick. Is it possible to code using horizontal lines instead of arrows? It would look similar to Robert's on researchtrade.com and on the "Fun with thinkscript" thread but instead of peaks and valleys, it would be candle wicks of a specific body type. (I do not own the rights to this picture)

I created a code the draws an arrow when a candle wick is created on the TOS chart. When ever a candle wick is generated on anytime frame, it creates an arrow at the bottom of the candle. I am sorry if my explanation was unclear. The wick tail setting I have would be 1.5 times the body. I wanted to know if there is a line of code that creates a line extension across the chart from the wick candle signal to the right side of the chart to possibly create a future pridiction of possible inflection points.

Below is what I've been using that is the closet to what I was trying to describe.

#Start
input magnitude =30;

# define top and bottom of candle body
def bodytop = max(open, close);
def bodybottom = min(open, close);

# define and plot the most recent valley
def valley = bodybottom <= Lowest(bodybottom[1], magnitude) and bodybottom <= Lowest(bodybottom[-magnitude], magnitude);
def valleyValue = if BarNumber() < magnitude then Double.NaN else if valley then bodybottom else valleyValue[1];
plot valleyline = valleyValue;
valleyline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
valleyline.SetDefaultColor(Color.magenta);

# extend the current valley line to the right edge of the chart
def countt = if IsNaN(valley) and !IsNaN(valley[1]) then 1 else countt[1] + 1;
plot valleyext = if IsNaN(valley) then GetValue(valleyline, countt) else Double.NaN;
valleyext.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
valleyext.SetDefaultColor(Color.magenta);

# continue the previous valley as a dashed line, but not all the way to the far right of the screen
def oldvalley = if BarNumber() < magnitude then Double.NaN else if valley then valleyValue[1] else oldvalley[1];
plot oldvalleyline = oldvalley;
oldvalleyline.SetPaintingStrategy(PaintingStrategy.DASHES);
oldvalleyline.SetDefaultColor(Color.magenta);

#End Code

sorry, i am not sure what you are trying to do. you typed a lot of words talking about wicks and arrows but you never defined what condition you are looking for.
you mentioned a code that draws arrows, but didn't post it.
you mentioned a wick at some size compared to the body.

try starting over and just describe what condition(s) you want to look for.
then describe what you want to see on the chart.

a condition formula could be created that compares the wicks to the body.
that condition could be used to trigger a line to draw , from the trigger bar to the right to the last bar.
but, if you want more than one horizontal line, the study will have to have a plot and and supporting formulas , for each line.

sorry, i am not sure what you are trying to do. you typed a lot of words talking about wicks and arrows but you never defined what condition you are looking for.
you mentioned a code that draws arrows, but didn't post it.
you mentioned a wick at some size compared to the body.

try starting over and just describe what condition(s) you want to look for.
then describe what you want to see on the chart.

a condition formula could be created that compares the wicks to the body.
that condition could be used to trigger a line to draw , from the trigger bar to the right to the last bar.
but, if you want more than one horizontal line, the study will have to have a plot and and supporting formulas , for each line.
Hi Halcyonguy, do you have the codes for the chart shown above with the lines touching the high and low?

Hi Halcyonguy, do you have the codes for the chart shown above with the lines touching the high and low?
it's ok @MerryDay , i have read many of roberts posts and know where to find the code for the above image.

robert , peak valley horizontal lines

Difference Between Two Zigzag High Pivot Points
post17
british43
Oct 14, 2021
halcyonguy
here is a link to a forum that robert payne hosted. this link should take you to a post that makes horz lines from peaks and valleys.

another link to the same post

===========

updated version.

robertpayne
The code you are basing your peaks / valleys on is from when I was first getting started. The way it is constructed works in the past, but results in a Double.NaN on the right edge of the charts. That is to say, it doesn't have a value on the most recent candle. That's why your scan isn't working.

I have since developed a better way of identifying swing highs / lows (peaks / valleys). Please see this example. It will work for you.

post10
ZigZag High Low with Supply & Demand Zones for ThinkorSwim

87k+ Posts
142 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?