add vertical line when it ending

shih90

Member
VIP
I love this program by @SleepyZ
https://usethinkscript.com/threads/...icator-for-thinkorswim.158/page-4#post-134041
I need help to add vertical line when it's done hh LL on that trendline slope.
Note: It had begin vertical line but it doesn't have at the end of that slope line. Thanks

Ruby:
#Trendline_HHLL_Period_Selected_at_Input_Type

input type = {default Chart, Day, Week, Month, Quarter, Year};
input back = 1;
input showvertical = yes;
input showlabel = yes;

def hh;
def ll;
def begin;
def bn = BarNumber();
def cond1;
def cond2;

#Days
def ymd = GetYYYYMMDD();
def ok = !IsNaN(close);
def capture = ok and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay = (HighestAll(dayCount) - dayCount) + 1 ;

#Weeks
def wk = GetWeek();
def capturewk = ok and wk != wk[1];
def wkCount = CompoundValue(1, if capturewk then wkCount[1] + 1 else wkCount[1], 0);
def thisweek = (HighestAll(wkCount) - wkCount) + 1 ;

#Months
def mo = GetMonth();
def capturemo = ok and mo != mo[1];
def moCount = CompoundValue(1, if capturemo then moCount[1] + 1 else moCount[1], 0);
def thismo = (HighestAll(moCount) - moCount) + 1 ;

#Quarters
def quarter = if GetMonth() == 1 then 1 else if GetMonth() == 4 then 2 else if GetMonth() == 7 then 3 else if GetMonth() == 10 then 4 else quarter[1];
def captureqtr = ok and quarter != quarter[1];
def qtrCount = CompoundValue(1, if captureqtr then qtrCount[1] + 1 else qtrCount[1], 0);
def thisqtr = (HighestAll(qtrCount) - qtrCount) + 1 ;

#Years
def yr = GetYear();
def captureyr = ok and yr != yr[1];
def yrCount = CompoundValue(1, if captureyr then yrCount[1] + 1 else yrCount[1], 0);
def thisyr = (HighestAll(yrCount) - yrCount) + 1 ;

switch (type) {
case Chart:
hh = high == HighestAll(high);
ll = low == LowestAll(low);
begin = if highestall(cond2)>highestall(cond1) then hh else ll;

case Day:
hh = high == if thisDay == back then high(period = AggregationPeriod.DAY) else hh[1];
ll = low == if thisDay == back then low(period = AggregationPeriod.DAY) else ll[1];
begin = thisDay[1] == back + 1 and thisDay == back;

case Week:
hh = high == if thisweek == back then high(period = AggregationPeriod.WEEK) else hh[1];
ll = low == if thisweek == back then low(period = AggregationPeriod.WEEK) else ll[1];
begin = thisweek[1] == back + 1 and thisweek == back;

case Month:
hh = high == if thismo == back then high(period = AggregationPeriod.MONTH) else hh[1];
ll = low == if thismo == back then low(period = AggregationPeriod.MONTH) else ll[1];
begin = thismo[1] == back + 1 and thismo == back;

case Quarter:
hh = high == if thisqtr == back then high(period = AggregationPeriod.QUARTER) else hh[1];
ll = low == if thisqtr == back then low(period = AggregationPeriod.QUARTER) else ll[1];
begin = thisqtr[1] == back + 1 and thisqtr == back;

case Year:
hh = high == if thisyr == back then high(period = AggregationPeriod.YEAR) else hh[1];
ll = low == if thisyr == back then low(period = AggregationPeriod.YEAR) else ll[1];
begin = thisyr[1] == back + 1 and thisyr == back;

}
;

cond1 = if hh then bn else cond1[1];
cond2 = if ll then bn else cond2[1];
AddVerticalLine(showvertical and begin, "Begin " + type, Color.WHITE);
#AddLabel(showlabel, "HH/LL Basis " + type, Color.YELLOW);

plot line = if bn == HighestAll(cond1) then high else if bn == HighestAll(cond2) then low else Double.NaN;
line.EnableApproximation();
line.SetDefaultColor(Color.WHITE);
line.SetLineWeight(2);

input show_bubbles = yes;
AddChartBubble(show_bubbles and cond1 and high == line, high, "HH: " + round(line), Color.GREEN);
AddChartBubble(show_bubbles and cond2 and low == Line, low, "LL: " + round(Line), Color.RED, no);


#end
 
Last edited by a moderator:
I love this program, I need help to add vertical line when it's done hh LL on that trendline slope.
Note: It had begin vertical line but it doesn't have at the end of that slope line. Thanks



#Trendline_HHLL_Period_Selected_at_Input_Type

input type = {default Chart, Day, Week, Month, Quarter, Year};
input back = 1;
input showvertical = yes;
input showlabel = yes;

def hh;
def ll;
def begin;
def bn = BarNumber();
def cond1;
def cond2;

#Days
def ymd = GetYYYYMMDD();
def ok = !IsNaN(close);
def capture = ok and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay = (HighestAll(dayCount) - dayCount) + 1 ;

#Weeks
def wk = GetWeek();
def capturewk = ok and wk != wk[1];
def wkCount = CompoundValue(1, if capturewk then wkCount[1] + 1 else wkCount[1], 0);
def thisweek = (HighestAll(wkCount) - wkCount) + 1 ;

#Months
def mo = GetMonth();
def capturemo = ok and mo != mo[1];
def moCount = CompoundValue(1, if capturemo then moCount[1] + 1 else moCount[1], 0);
def thismo = (HighestAll(moCount) - moCount) + 1 ;

#Quarters
def quarter = if GetMonth() == 1 then 1 else if GetMonth() == 4 then 2 else if GetMonth() == 7 then 3 else if GetMonth() == 10 then 4 else quarter[1];
def captureqtr = ok and quarter != quarter[1];
def qtrCount = CompoundValue(1, if captureqtr then qtrCount[1] + 1 else qtrCount[1], 0);
def thisqtr = (HighestAll(qtrCount) - qtrCount) + 1 ;

#Years
def yr = GetYear();
def captureyr = ok and yr != yr[1];
def yrCount = CompoundValue(1, if captureyr then yrCount[1] + 1 else yrCount[1], 0);
def thisyr = (HighestAll(yrCount) - yrCount) + 1 ;

switch (type) {
case Chart:
hh = high == HighestAll(high);
ll = low == LowestAll(low);
begin = if highestall(cond2)>highestall(cond1) then hh else ll;

case Day:
hh = high == if thisDay == back then high(period = AggregationPeriod.DAY) else hh[1];
ll = low == if thisDay == back then low(period = AggregationPeriod.DAY) else ll[1];
begin = thisDay[1] == back + 1 and thisDay == back;

case Week:
hh = high == if thisweek == back then high(period = AggregationPeriod.WEEK) else hh[1];
ll = low == if thisweek == back then low(period = AggregationPeriod.WEEK) else ll[1];
begin = thisweek[1] == back + 1 and thisweek == back;

case Month:
hh = high == if thismo == back then high(period = AggregationPeriod.MONTH) else hh[1];
ll = low == if thismo == back then low(period = AggregationPeriod.MONTH) else ll[1];
begin = thismo[1] == back + 1 and thismo == back;

case Quarter:
hh = high == if thisqtr == back then high(period = AggregationPeriod.QUARTER) else hh[1];
ll = low == if thisqtr == back then low(period = AggregationPeriod.QUARTER) else ll[1];
begin = thisqtr[1] == back + 1 and thisqtr == back;

case Year:
hh = high == if thisyr == back then high(period = AggregationPeriod.YEAR) else hh[1];
ll = low == if thisyr == back then low(period = AggregationPeriod.YEAR) else ll[1];
begin = thisyr[1] == back + 1 and thisyr == back;

}
;

cond1 = if hh then bn else cond1[1];
cond2 = if ll then bn else cond2[1];
AddVerticalLine(showvertical and begin, "Begin " + type, Color.WHITE);
#AddLabel(showlabel, "HH/LL Basis " + type, Color.YELLOW);

plot line = if bn == HighestAll(cond1) then high else if bn == HighestAll(cond2) then low else Double.NaN;
line.EnableApproximation();
line.SetDefaultColor(Color.WHITE);
line.SetLineWeight(2);

input show_bubbles = yes;
AddChartBubble(show_bubbles and cond1 and high == line, high, "HH: " + round(line), Color.GREEN);
AddChartBubble(show_bubbles and cond2 and low == Line, low, "LL: " + round(Line), Color.RED, no);


#end

End Vertical added

Screenshot 2024-04-05 152700.png

Code:
#Trendline_HHLL_Period_Selected_at_Input_Type

input type = {default Chart, Day, Week, Month, Quarter, Year};
input back = 1;
input showvertical = yes;
input showlabel = yes;

def hh;
def ll;
def begin;
def bn = BarNumber();
def cond1;
def cond2;

#Days
def ymd = GetYYYYMMDD();
def ok = !IsNaN(close);
def capture = ok and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay = (HighestAll(dayCount) - dayCount) + 1 ;

#Weeks
def wk = GetWeek();
def capturewk = ok and wk != wk[1];
def wkCount = CompoundValue(1, if capturewk then wkCount[1] + 1 else wkCount[1], 0);
def thisweek = (HighestAll(wkCount) - wkCount) + 1 ;

#Months
def mo = GetMonth();
def capturemo = ok and mo != mo[1];
def moCount = CompoundValue(1, if capturemo then moCount[1] + 1 else moCount[1], 0);
def thismo = (HighestAll(moCount) - moCount) + 1 ;

#Quarters
def quarter = if GetMonth() == 1 then 1 else if GetMonth() == 4 then 2 else if GetMonth() == 7 then 3 else if GetMonth() == 10 then 4 else quarter[1];
def captureqtr = ok and quarter != quarter[1];
def qtrCount = CompoundValue(1, if captureqtr then qtrCount[1] + 1 else qtrCount[1], 0);
def thisqtr = (HighestAll(qtrCount) - qtrCount) + 1 ;

#Years
def yr = GetYear();
def captureyr = ok and yr != yr[1];
def yrCount = CompoundValue(1, if captureyr then yrCount[1] + 1 else yrCount[1], 0);
def thisyr = (HighestAll(yrCount) - yrCount) + 1 ;

switch (type) {
case Chart:
    hh = high == HighestAll(high);
    ll = low == LowestAll(low);
    begin = if HighestAll(cond2) > HighestAll(cond1) then hh else ll;
case Day:
    hh = high == if thisDay == back then high(period = AggregationPeriod.DAY) else hh[1];
    ll = low == if thisDay == back then low(period = AggregationPeriod.DAY) else ll[1];
    begin = thisDay[1] == back + 1 and thisDay == back;
case Week:
    hh = high == if thisweek == back then high(period = AggregationPeriod.WEEK) else hh[1];
    ll = low == if thisweek == back then low(period = AggregationPeriod.WEEK) else ll[1];
    begin = thisweek[1] == back + 1 and thisweek == back;
case Month:
    hh = high == if thismo == back then high(period = AggregationPeriod.MONTH) else hh[1];
    ll = low == if thismo == back then low(period = AggregationPeriod.MONTH) else ll[1];
    begin = thismo[1] == back + 1 and thismo == back;
case Quarter:
    hh = high == if thisqtr == back then high(period = AggregationPeriod.QUARTER) else hh[1];
    ll = low == if thisqtr == back then low(period = AggregationPeriod.QUARTER) else ll[1];
    begin = thisqtr[1] == back + 1 and thisqtr == back;
case Year:
    hh = high == if thisyr == back then high(period = AggregationPeriod.YEAR) else hh[1];
    ll = low == if thisyr == back then low(period = AggregationPeriod.YEAR) else ll[1];
    begin = thisyr[1] == back + 1 and thisyr == back;

}
;

cond1 = if hh then bn else cond1[1];
cond2 = if ll then bn else cond2[1];
AddVerticalLine(showvertical and begin, "Begin " + type, Color.WHITE);

#AddLabel(showlabel, "HH/LL Basis " + type, Color.YELLOW);

plot line = if bn == HighestAll(cond1) then high else if bn == HighestAll(cond2) then low else Double.NaN;
line.EnableApproximation();
line.SetDefaultColor(Color.WHITE);
line.SetLineWeight(2);

AddVerticalLine(showvertical and begin, "Begin " + type, Color.WHITE);
AddVerticalLine(showvertical and (high==line or low==line), "End " + type, Color.WHITE);

input show_bubbles = yes;
AddChartBubble(show_bubbles and cond1 and high == line, high, "HH: " + Round(line), Color.GREEN);
AddChartBubble(show_bubbles and cond2 and low == line, low, "LL: " + Round(line), Color.RED, no);

#end
 
Last edited:
I need 2 vertical lines showing at begin and the end of "HH" and "LL".
Thanks


I just receive your adjust but it's not show anything on 2nd line when it's done hh LL.
Please readjust it again. Thanks

Adjusted this line. Forgot low==line.
Code:
AddVerticalLine(showvertical and (high==line or low==line), "End " + type, Color.WHITE);
Corrected in above post's full code.
 
I'm forget one thing. Can you able add one more feature for watchlist column? when it hit to 2nd line "End Chart" and then it displays color green on watchlist column (assign column color green else color gray).
Thanks. I know you can do this. Thanks million times!!!
 
I'm forget one thing. Can you able add one more feature for watchlist column? when it hit to 2nd line "End Chart" and then it displays color green on watchlist column (assign column color green else color gray).
Thanks. I know you can do this. Thanks million times!!!

1. Modified verticallines to be Begin, HH and LL, all along with type.
2. This seems to work on a chart and watchlist column.
3. For watchlist, replace the same code in the script with the following for better visulaization
Code:
plot line = if bn == HighestAll(cond1) then high else if bn == HighestAll(cond2) then low else Double.NaN;
line.EnableApproximation();
line.AssignValueColor(if bn == Max(cond1, cond2) then Color.GREEN else Color.GRAY);
line.SetLineWeight(2);
4, You can comment out this code if you do not want the chart to change backgrounds
AssignBackgroundColor(if bn == Max(cond1, cond2) then Color.GREEN else Color.GRAY);

Here is the full revised code
Screenshot 2024-04-07 090220.png
Screenshot 2024-04-07 085745.png
Code:
#Trendline_HHLL_Period_Selected_at_Input_Type

input type = {default Chart, Day, Week, Month, Quarter, Year};
input back = 1;
input showvertical = yes;
input showlabel = yes;

def hh;
def ll;
def begin;
def bn = BarNumber();
def cond1;
def cond2;

#Days
def ymd = GetYYYYMMDD();
def ok = !IsNaN(close);
def capture = ok and ymd != ymd[1];
def dayCount = CompoundValue(1, if capture then dayCount[1] + 1 else dayCount[1], 0);
def thisDay = (HighestAll(dayCount) - dayCount) + 1 ;

#Weeks
def wk = GetWeek();
def capturewk = ok and wk != wk[1];
def wkCount = CompoundValue(1, if capturewk then wkCount[1] + 1 else wkCount[1], 0);
def thisweek = (HighestAll(wkCount) - wkCount) + 1 ;

#Months
def mo = GetMonth();
def capturemo = ok and mo != mo[1];
def moCount = CompoundValue(1, if capturemo then moCount[1] + 1 else moCount[1], 0);
def thismo = (HighestAll(moCount) - moCount) + 1 ;

#Quarters
def quarter = if GetMonth() == 1 then 1 else if GetMonth() == 4 then 2 else if GetMonth() == 7 then 3 else if GetMonth() == 10 then 4 else quarter[1];
def captureqtr = ok and quarter != quarter[1];
def qtrCount = CompoundValue(1, if captureqtr then qtrCount[1] + 1 else qtrCount[1], 0);
def thisqtr = (HighestAll(qtrCount) - qtrCount) + 1 ;

#Years
def yr = GetYear();
def captureyr = ok and yr != yr[1];
def yrCount = CompoundValue(1, if captureyr then yrCount[1] + 1 else yrCount[1], 0);
def thisyr = (HighestAll(yrCount) - yrCount) + 1 ;

switch (type) {
case Chart:
    hh = high == HighestAll(high);
    ll = low == LowestAll(low);
    begin = if HighestAll(cond2) > HighestAll(cond1) then hh else ll;
case Day:
    hh = high == if thisDay == back then high(period = AggregationPeriod.DAY) else hh[1];
    ll = low == if thisDay == back then low(period = AggregationPeriod.DAY) else ll[1];
    begin = thisDay[1] == back + 1 and thisDay == back;
case Week:
    hh = high == if thisweek == back then high(period = AggregationPeriod.WEEK) else hh[1];
    ll = low == if thisweek == back then low(period = AggregationPeriod.WEEK) else ll[1];
    begin = thisweek[1] == back + 1 and thisweek == back;
case Month:
    hh = high == if thismo == back then high(period = AggregationPeriod.MONTH) else hh[1];
    ll = low == if thismo == back then low(period = AggregationPeriod.MONTH) else ll[1];
    begin = thismo[1] == back + 1 and thismo == back;
case Quarter:
    hh = high == if thisqtr == back then high(period = AggregationPeriod.QUARTER) else hh[1];
    ll = low == if thisqtr == back then low(period = AggregationPeriod.QUARTER) else ll[1];
    begin = thisqtr[1] == back + 1 and thisqtr == back;
case Year:
    hh = high == if thisyr == back then high(period = AggregationPeriod.YEAR) else hh[1];
    ll = low == if thisyr == back then low(period = AggregationPeriod.YEAR) else ll[1];
    begin = thisyr[1] == back + 1 and thisyr == back;

}
;

cond1 = if hh then bn else cond1[1];
cond2 = if ll then bn else cond2[1];

plot line = if bn == HighestAll(cond1) then high else if bn == HighestAll(cond2) then low else Double.NaN;
line.EnableApproximation();
line.SetDefaultColor(Color.WHITE);
line.SetLineWeight(2);

AddVerticalLine(showvertical and begin, "Begin " + type, Color.WHITE);
AddVerticalLine(showvertical and (high == line), "HH " + type, Color.WHITE);
AddVerticalLine(showvertical and (low == line), "LL " + type, Color.WHITE);

AssignBackgroundColor(if bn == Max(cond1, cond2) then Color.GREEN else Color.GRAY);

input show_bubbles = yes;
AddChartBubble(show_bubbles and cond1 and high == line, high, "HH: " + Round(line), Color.GREEN);
AddChartBubble(show_bubbles and cond2 and low == line, low, "LL: " + Round(line), Color.RED, no);

#end
 

Attachments

  • 1712505876073.png
    1712505876073.png
    11.4 KB · Views: 24

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