Need Help With Line Extension

shizah

Member
I'm trying to get the line to touch the high and low of the candle with the line extending. Like the yellow line does at the mid-point of the candle. I know it's something simple, but I can't figure the code out.


Code:
def last = if isnan(close[-2]) and !isnan(close) then barnumber() else last[1];
def hilo = if hl2 then barnumber() else hilo[2];

def cond = if barNumber() == hilo then barNumber()-2 else double.nan;
def pbar = if barNumber() >= HighestAll(cond) and !last then 2 else double.nan;

input show50 = yes;
plot HalfBack = if show50 and !isnan(pbar) then hl2 else double.nan;
HalfBack.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HalfBack.SetDefaultColor(color.Yellow);
HalfBack.SetLineWeight(3);
def hbext    = if isnan(halfback) then hbext[1] else halfback;
plot hbextline = hbext;
hbextline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hbextline.SetDefaultColor(color.Yellow);
hbextline.SetLineWeight(3);

input show75 = yes;
plot Back75 = if show75 and !isnan(pbar) then low+(high-low)*.75 else double.nan;
Back75.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Back75.SetDefaultColor(color.white);
Back75.SetLineWeight(1);

input show25 = yes;
plot Back25 = if show25 and !isnan(pbar) then low+(high-low)*.25 else double.nan;
Back25.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Back25.SetDefaultColor(color.white);
Back25.SetLineWeight(1);

input bubblemover = 1;
def n1 = bubblemover + 1;
input showbubble_candle    = no;
input showbubble_expansion = no;
addchartBubble(showbubble_candle and barnumber()==highestall(last-1),high,"H: " +high,color.white,yes);
addchartBubble(showbubble_candle and barnumber()==highestall(last-1),low,"L: " +low,color.white,no);
addchartBubble(showbubble_expansion and isnan(close[bubblemover]) and !isnan(close[n1]),high[n1+1],"H: " +high[n1+1],color.white,yes);
addchartBubble(showbubble_expansion and isnan(close[bubblemover]) and !isnan(close[n1]),low[n1+1],"L: " +low[n1+1],color.white,no);
def h2 = if isnan(close) then h2[1] else high[2];
plot h2p = if barnumber()>=highestall(last) then h2 else double.nan;
h2p.setpaintingStrategy(PaintingStrategy.HORIZONTAL);
h2p.setdefaultColor(color.black);
input showcolor_light_gray = yes;
h2p.assignvalueColor(if showcolor_light_gray then color.black else color.black);
def l2 = if isnan(close) then l2[1] else low[2];
plot l2p = if barnumber()>=highestall(last) then l2 else double.nan;
l2p.setpaintingStrategy(PaintingStrategy.HORIZONTAL);
l2p.setdefaultColor(color.black);
l2p.assignvalueColor(if showcolor_light_gray then color.black else color.black);
 
I'm trying to get the line to touch the high and low of the candle with the line extending. Like the yellow line does at the mid-point of the candle. I know it's something simple, but I can't figure the code out.


Code:
def last = if isnan(close[-2]) and !isnan(close) then barnumber() else last[1];
def hilo = if hl2 then barnumber() else hilo[2];

def cond = if barNumber() == hilo then barNumber()-2 else double.nan;
def pbar = if barNumber() >= HighestAll(cond) and !last then 2 else double.nan;

input show50 = yes;
plot HalfBack = if show50 and !isnan(pbar) then hl2 else double.nan;
HalfBack.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HalfBack.SetDefaultColor(color.Yellow);
HalfBack.SetLineWeight(3);
def hbext    = if isnan(halfback) then hbext[1] else halfback;
plot hbextline = hbext;
hbextline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hbextline.SetDefaultColor(color.Yellow);
hbextline.SetLineWeight(3);

input show75 = yes;
plot Back75 = if show75 and !isnan(pbar) then low+(high-low)*.75 else double.nan;
Back75.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Back75.SetDefaultColor(color.white);
Back75.SetLineWeight(1);

input show25 = yes;
plot Back25 = if show25 and !isnan(pbar) then low+(high-low)*.25 else double.nan;
Back25.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Back25.SetDefaultColor(color.white);
Back25.SetLineWeight(1);

input bubblemover = 1;
def n1 = bubblemover + 1;
input showbubble_candle    = no;
input showbubble_expansion = no;
addchartBubble(showbubble_candle and barnumber()==highestall(last-1),high,"H: " +high,color.white,yes);
addchartBubble(showbubble_candle and barnumber()==highestall(last-1),low,"L: " +low,color.white,no);
addchartBubble(showbubble_expansion and isnan(close[bubblemover]) and !isnan(close[n1]),high[n1+1],"H: " +high[n1+1],color.white,yes);
addchartBubble(showbubble_expansion and isnan(close[bubblemover]) and !isnan(close[n1]),low[n1+1],"L: " +low[n1+1],color.white,no);
def h2 = if isnan(close) then h2[1] else high[2];
plot h2p = if barnumber()>=highestall(last) then h2 else double.nan;
h2p.setpaintingStrategy(PaintingStrategy.HORIZONTAL);
h2p.setdefaultColor(color.black);
input showcolor_light_gray = yes;
h2p.assignvalueColor(if showcolor_light_gray then color.black else color.black);
def l2 = if isnan(close) then l2[1] else low[2];
plot l2p = if barnumber()>=highestall(last) then l2 else double.nan;
l2p.setpaintingStrategy(PaintingStrategy.HORIZONTAL);
l2p.setdefaultColor(color.black);
l2p.assignvalueColor(if showcolor_light_gray then color.black else color.black);

The defs h and l and plots hh and ll should do that

Screenshot-2022-11-18-092228.png
Ruby:
def last = if IsNaN(close[-2]) and !IsNaN(close) then BarNumber() else last[1];
def hilo = if hl2 then BarNumber() else hilo[2];

def cond = if BarNumber() == hilo then BarNumber() - 2 else Double.NaN;
def pbar = if BarNumber() >= HighestAll(cond) and !last then 2 else Double.NaN;

def h = if IsNaN(close) then h[1] else if !IsNaN(pbar) then high else h[1];
plot hh = h;
hh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
def l = if IsNaN(close) then l[1] else if !IsNaN(pbar) then low else l[1];
plot ll = l;
ll.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

input show50 = yes;
plot HalfBack = if show50 and !IsNaN(pbar) then hl2 else Double.NaN;
HalfBack.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
HalfBack.SetDefaultColor(Color.YELLOW);
HalfBack.SetLineWeight(3);
def hbext    = if IsNaN(HalfBack) then hbext[1] else HalfBack;
plot hbextline = hbext;
hbextline.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
hbextline.SetDefaultColor(Color.YELLOW);
hbextline.SetLineWeight(3);

input show75 = yes;
plot Back75 = if show75 and !IsNaN(pbar) then low + (high - low) * .75 else Double.NaN;
Back75.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Back75.SetDefaultColor(Color.WHITE);
Back75.SetLineWeight(1);

input show25 = yes;
plot Back25 = if show25 and !IsNaN(pbar) then low + (high - low) * .25 else Double.NaN;
Back25.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Back25.SetDefaultColor(Color.WHITE);
Back25.SetLineWeight(1);

input bubblemover = 1;
def n1 = bubblemover + 1;
input showbubble_candle    = no;
input showbubble_expansion = no;
AddChartBubble(showbubble_candle and BarNumber() == HighestAll(last - 1), high, "H: " + high, Color.WHITE, yes);
AddChartBubble(showbubble_candle and BarNumber() == HighestAll(last - 1), low, "L: " + low, Color.WHITE, no);
AddChartBubble(showbubble_expansion and IsNaN(close[bubblemover]) and !IsNaN(close[n1]), high[n1 + 1], "H: " + high[n1 + 1], Color.WHITE, yes);
AddChartBubble(showbubble_expansion and IsNaN(close[bubblemover]) and !IsNaN(close[n1]), low[n1 + 1], "L: " + low[n1 + 1], Color.WHITE, no);
def h2 = if IsNaN(close) then h2[1] else high[2];
plot h2p = if BarNumber() >= HighestAll(last) then h2 else Double.NaN;
h2p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
h2p.SetDefaultColor(Color.BLACK);
input showcolor_light_gray = yes;
h2p.AssignValueColor(if showcolor_light_gray then Color.BLACK else Color.BLACK);
def l2 = if IsNaN(close) then l2[1] else low[2];
plot l2p = if BarNumber() >= HighestAll(last) then l2 else Double.NaN;
l2p.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
l2p.SetDefaultColor(Color.BLACK);
l2p.AssignValueColor(if showcolor_light_gray then Color.BLACK else Color.BLACK);
 

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
461 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