# Plot Horizontal High of Day Line in ThinkorSwim

#### Tom4235

##### New member
Hey, can you provide the code for a simple horizontal line at high of day (HOD)? just need the visual, thank you v much

#### tomsk

##### Well-known member
VIP
Here we go, horizontal line at HOD, use this on an intraday chart

Code:
``````plot highLine = highestAll(if isNaN(close[-1])
then high(period = "Day")
else Double.NaN);``````

#### blake007

##### New member
How can do I do the LOD line similar to this one?

Code:
``````# Plot High and Low of RTH for Any Day Through Week
# Mobius
# Chat Room Request 04.22.2020

input DayOfWeek = {default Monday, Tuesday, Wednesday, Thursday, Friday};

def DOW;
switch (DayOfWeek)
{
case Monday:
DOW = 1;
case Tuesday:
DOW = 2;
case Wednesday:
DOW = 3;
case Thursday:
DOW = 4;
case Friday:
DOW = 5;
}
def RTH = getTime() >= RegularTradingStart(getYYYYMMDD()) and
def day = getDayOfWeek(getYYYYMMDD()) == DOW;
def hh = if day and RTH and !RTH[1]
then high
else if day and RTH and high > hh[1]
then high
else hh[1];
def xh = if high == hh
then barNumber()
else double.nan;
plot HighLine = if barNumber() >= highestAll(xh)
then highestAll(if isNaN(close[-1])
then hh
else double.nan)
else double.nan;
def ll = if day and RTH and !RTH[1]
then low
else if day and RTH and low < ll[1]
then low
else ll[1];
def xl = if low == ll
then barNumber()
else double.nan;
plot LowLine = if barNumber() >= highestAll(xl)
then highestAll(if isNaN(close[-1])
then ll
else double.nan)
else double.nan;``````

#### BenTen

Staff
VIP
@blake007 By switching high and highestAll to low and lowestAll.

Code:
``````plot lowLine = lowestAll(if isNaN(close[-1])
then low(period = "Day")
else Double.NaN);``````

##### New member
Hi, I am looking to add two labels that tell me the time of HOD and time of LOD. I have an example of a label for pre-market high time here but I am unable to create the same for HOD and LOD. I'd appreciate any help with this. Thank you.

Code:
``````def time = GetTime();
def isNewDay = GetYYYYMMDD() != GetYYYYMMDD()[1];
def isPreMarket = time < RegularTradingStart(GetYYYYMMDD());
def preHigh = if !isPreMarket then preHigh[1] else if isNewDay then high else Max(high, preHigh[1]);
def preHighTime = if preHigh != preHigh[1] then time else preHighTime[1];
def hours = Floor(preHighTime % AggregationPeriod.DAY / AggregationPeriod.HOUR)- 4 ;
def minutes = Floor(preHighTime % AggregationPeriod.HOUR / AggregationPeriod.MIN);
plot H = preHigh;
AddLabel(yes, "ONHtime = " + AsText(hours, "%2.0f") + ":" + AsText(minutes, "%2.0f"));``````

Last edited by a moderator:

#### jcga1981

##### Member
hello friends, I have tried to do it alone but I can't get what I'm looking for ... thinkorswim offers the possibility of adding "DailyOpen" as a base ... I would like to add the legend DailyOpen on the right side ... the most I have achieved is to add a cloud ... the problem is that when the price reaches that point the cloud bothers me by practically positioning itself on the candle ... is there a possibility that the text or the cloud is further to the right? Thank you

Code:
``````# Comparison HOD/LOD
# Paris | BLT
# 8.6.2017

# Plots a horizontal line on an INTRADAY chart corresponding to the
# time a HOD/LOD is made on a secondary symbol. Several versions were
# drafted. This final version is based on ideas from Mobius' High Low
# RTH study dated 1.31.2016. A big thanks to BLT for providing great
# input, cross checking the accuracy of the code as well as a debug
# section.
#
# BLT_: johngalt - if you still need your high/low by day, here is one
# way to do it using a mod of Paris' study, until an easier way can be
# found. The variable k is the loopback in days. If you want to change
# the symbol, just go into the code of one of the studies and change it
# there and it will change it for all.
#
# Paris: the original request was to plot a horizontal line on an INTRADAY
# chart corresponding to the time a HOD/LOD was made on a secondary
# symbol. I produced 2 separate scripts - one for HOD and another one
# for LOD. Then a few days ago, I decided to combine both into a single
# script and was obliged to revamp the code. It worked great. Today BLT
#
# BLT_: johngalt, here is another version of what I posted earlier, but
# all in one study and the bubbles with the number of days, 1-5, instead
# of a \$amount ...
#
# BLT_: here is an updated version with color choices. Just change the
# DefineGlobalColors MAGENTA and YELLOW to what you want. I just did window
# dressing to that code. It is the very fine work of Paris at the heart of
# the code.

declare hide_on_daily;

script hl2nd {
input k = 2;
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;

input symbol = "AAPL";
input usePrice = {default HIGH, LOW}; #hint usePrice: Set to HIGH to test for HOD, or to LOW to test for LOD for the secondary symbol.

def SecPrice;
def location;
def bn;

def Active = thisDay == k and SecondsFromTime(0930) >= 0 and SecondsTillTime(1600) >= 0;

def useHigh = usePrice == usePrice.HIGH;
def useLow = usePrice == usePrice.LOW;

if Active[1] and !Active[2] {
SecPrice = if useHigh then high(symbol) else low(symbol);
location = close;
bn = BarNumber();
}
else if Active and ((useHigh and high(symbol) > SecPrice[1]) or
(useLow  and low(symbol)  < SecPrice[1])) {
SecPrice = if useHigh then high(symbol) else low(symbol);
location = close;
bn = BarNumber();
}
else {
SecPrice = SecPrice[1];
location = location[1];
bn = bn[1];
}

AddLabel(1, "Secondary Symbol: " + symbol + (if useHigh then "   HOD: " else "   LOD: ") + SecPrice,
(if useHigh then Color.MAGENTA else Color.YELLOW));

plot data = if BarNumber() >= HighestAll(bn) then location else Double.NaN;
data.SetPaintingStrategy(PaintingStrategy.DASHES);
data.AssignValueColor((if useHigh then Color.MAGENTA else Color.YELLOW));
data.SetLineWeight(2);
}

input symbol_ = "AAPL";
plot data1h = hl2nd(k = 1,symbol=symbol_);
plot data2h = hl2nd(k = 2,symbol=symbol_);
plot data3h = hl2nd(k = 3,symbol=symbol_);
plot data4h = hl2nd(k = 4,symbol=symbol_);
plot data5h = hl2nd(k = 5,symbol=symbol_);
plot data1l = hl2nd(k = 1, "use price" = "LOW",symbol=symbol_);
plot data2l = hl2nd(k = 2, "use price" = "LOW",symbol=symbol_);
plot data3l = hl2nd(k = 3, "use price" = "LOW",symbol=symbol_);
plot data4l = hl2nd(k = 4, "use price" = "LOW",symbol=symbol_);
plot data5l = hl2nd(k = 5, "use price" = "LOW",symbol=symbol_);

DefineGlobalColor(name = "HLine", color = Color.MAGENTA);
DefineGlobalColor(name = "LLine", color = Color.YELLOW);

data1h.SetDefaultColor(GlobalColor("HLine"));
data2h.SetDefaultColor(GlobalColor("HLine"));
data3h.SetDefaultColor(GlobalColor("HLine"));
data4h.SetDefaultColor(GlobalColor("HLine"));
data5h.SetDefaultColor(GlobalColor("HLine"));
data1l.SetDefaultColor(GlobalColor("LLine"));
data2l.SetDefaultColor(GlobalColor("LLine"));
data3l.SetDefaultColor(GlobalColor("LLine"));
data4l.SetDefaultColor(GlobalColor("LLine"));
data5l.SetDefaultColor(GlobalColor("LLine"));

input bubblemover = 100;

def n = bubblemover;
def n1 = n + 1;

AddChartBubble(IsNaN(close[n]) and !IsNaN(close[n1]), data1h[n1], symbol_ + (if data1h then " HOD : " else " LOD : ") + 1,
(if data1h then Color.MAGENTA else Color.YELLOW));
AddChartBubble(IsNaN(close[n]) and !IsNaN(close[n1]), data2h[n1], symbol_ + (if data2h then " HOD : " else " LOD : ") + 2,
(if data2h then Color.MAGENTA else Color.YELLOW));
AddChartBubble(IsNaN(close[n]) and !IsNaN(close[n1]), data3h[n1], symbol_ + (if data3h then " HOD : " else " LOD : ") + 3,
(if data3h then Color.MAGENTA else Color.YELLOW));
AddChartBubble(IsNaN(close[n]) and !IsNaN(close[n1]), data4h[n1], symbol_ + (if data4h then " HOD : " else " LOD : ") + 4,
(if data4h then Color.MAGENTA else Color.YELLOW));
AddChartBubble(IsNaN(close[n]) and !IsNaN(close[n1]), data5h[n1], symbol_ + (if data5h then " HOD : " else " LOD : ") + 5,
(if data5h then Color.MAGENTA else Color.YELLOW));
AddChartBubble(IsNaN(close[n]) and !IsNaN(close[n1]), data1l[n1], symbol_ + (" LOD : ") + 1,
(Color.YELLOW));
AddChartBubble(IsNaN(close[n]) and !IsNaN(close[n1]), data2l[n1], symbol_ + (" LOD : ") + 2,
(Color.YELLOW));
AddChartBubble(IsNaN(close[n]) and !IsNaN(close[n1]), data3l[n1], symbol_ + (" LOD : ") + 3,
(Color.YELLOW));
AddChartBubble(IsNaN(close[n]) and !IsNaN(close[n1]), data4l[n1], symbol_ + (" LOD : ") + 4,
(Color.YELLOW));
AddChartBubble(IsNaN(close[n]) and !IsNaN(close[n1]), data5l[n1], symbol_ + (" LOD : ") + 5,
(Color.YELLOW));

# END CODE``````

#### BenTen

@jcga1981 You would need to use `AddChartBubble` for this.