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