# Highest/Lowest Between a Specified Time Period

#### bmn

##### Member
Hello

I would like to find the highest and lowest price of the day up until the "current point" with an user input that would either exclude or include pre-market price.

example:
Consider:
Ticker: /CL
Aggregation Type: time/ticker/range

(US) Market opens at 9 AM EST
I would like to plot a continuous line (sort of like MA lines) of the avg (or separate lines for both) of the highest high and lowest low from start of that day (from RTH start or from Pre start) to the current bar.
So for example, if I'm looking at 2D 2m time frame with RTH only selected as user input, then at 9:44 AM EST, I would like the current point of the line to represent the average of the highest high and lowest low between 9:00 to 9:44.
if I scroll left to to previous day's data and look at the bar @10:18 AM, then I would like the line's y axis value to represent the average of the highest high and lowest low between 9:00 to 10:18 of yesterday.
if I scroll a bit to the right on the previous day's data and look at the bar @12:56 PM, then it would be the avg of highest high and lowest low between yesterday's 9:00 to 12:56PM.

similar concept if pre-market hours were included, where starting point would be start of pre-hours instead of 9:00.

Solution
Thank you for the update. I was looking for a way to possibly get this data for more than a single day/wk/qt/etc. e.g. get high of past two days (length = 2). But now that I think about it, complexity in code, especially when it comes to calculating "Close" in that scenario is not worth the benefit and agree with your new approach.

Just one last thing, would it be possible to plot a cloud instead of one line of that bar for O/L/H/C? e.g. instead of plotting a line for prev High, draw a cloud that covers the bar that reached that highest price (similar for Open/Close/Low lines).
You're welcome

It seems you should be able to do the first idea by using multiple copies of the study and changing the inputs.

As to the clouds, here...
Any help would be appreciated.

Basically, I'm looking for a continuous line (e.g. MA line), that at represents the avg of the highest high and lowest low from either start of the that trading day or start or that pre until that point.

Hello

I would like to find the highest and lowest price of the day up until the "current point" with an user input that would either exclude or include pre-market price.

example:
Consider:
Ticker: /CL
Aggregation Type: time/ticker/range

(US) Market opens at 9 AM EST
I would like to plot a continuous line (sort of like MA lines) of the avg (or separate lines for both) of the highest high and lowest low from start of that day (from RTH start or from Pre start) to the current bar.
So for example, if I'm looking at 2D 2m time frame with RTH only selected as user input, then at 9:44 AM EST, I would like the current point of the line to represent the average of the highest high and lowest low between 9:00 to 9:44.
if I scroll left to to previous day's data and look at the bar @10:18 AM, then I would like the line's y axis value to represent the average of the highest high and lowest low between 9:00 to 10:18 of yesterday.
if I scroll a bit to the right on the previous day's data and look at the bar @12:56 PM, then it would be the avg of highest high and lowest low between yesterday's 9:00 to 12:56PM.

similar concept if pre-market hours were included, where starting point would be start of pre-hours instead of 9:00.
i don't think thinkscript can tell if a window is zoomed or which bars are visible on the screen, so i don't think it can do what you are asking.
..
can you elaborate on when you want to look for the lowest or the highest.
do you want a straight line, from the lowest to the highest?

i don't think thinkscript can tell if a window is zoomed or which bars are visible on the screen, so i don't think it can do what you are asking.
..
can you elaborate on when you want to look for the lowest or the highest.
do you want a straight line, from the lowest to the highest?
I don't mean the study to be "interactive" (think that's what you might be getting out of my convoluted post. haha sorry)

I am thinking of a moving average line that represents the average of highest high and lowest low from start of that day (or start of pre for that day).

We choose the calculate intraday high/low starting from open (other option would be to start from pre)
The market opens.
After the first bar (whatever the aggregation type is), we have a high and a low defined.. so our moving average start. Say high = \$4 and low = \$2. So our moving avg line starts at \$3.
Time passes where it doesn't make a higher high or lower low until 9:45 AM, at which point it makes a higher high of \$8. The moving average line will now move up to \$5 ((8+2)/2).
Time passes where it doesn't make a higher high or lower low until 12:18 PM, at which point it makes a higher high of \$12. The moving average line will now be plotted at \$7 going forward ((12+2)/2).
Time passes where it doesn't make a higher high or lower low until 03:01 PM, at which point it makes a lower low of \$1. The moving average line will now be plotted at \$6.5 going forward ((12+1)/2).
No newer higher high or lower low is made for the rest of the day so the moving average stays @\$6.5 until the next day.

does that help?

Any help would be appreciated.

Basically, I'm looking for a continuous line (e.g. MA line), that at represents the avg of the highest high and lowest low from either start of the that trading day or start or that pre until that point.
I am not sure when the premarket begins for futures, so I used when TOS changes the trading day for both futures (1800) and stocks (0400). You can select whether you want premarket or rth at the input start, including selections all days or today only or show on expansion.

The picture below is of /CL with premarket and all days selected

Ruby:
``````input ShowTodayOnly = no;
input start         = {default rth, premarket};
input onexpansion   = no;
def ORActive = if start == start.premarket
then if ORActive[1] == 0 and
GetYYYYMMDD() != GetYYYYMMDD()[1]
then 1
else if ORActive[1] == 1 and
then 1
else 0
else if start == start.rth and
then 1
else 0;

def ORHigh   = if ORHigh[1] == 0 or
ORActive[1] == 0 and
ORActive == 1
then high
else if ORActive and
high > ORHigh[1]
then high
else ORHigh[1];
def ORLow    = if ORLow[1] == 0 or
ORActive[1] == 0 and
ORActive == 1
then low
else if ORActive and
low < ORLow[1]
then low
else ORLow[1];

def ORHexp = if IsNaN(close)
then ORHexp[1]
else ORHigh;
def ORLexp = if IsNaN(close)
then ORLexp[1]
else ORLow;

plot ORH = if (ShowTodayOnly and
GetDay() != GetLastDay()) or
!ORActive
then Double.NaN
else if onexpansion and IsNaN(close)
then ORHexp
else if !onexpansion
then ORHigh
else Double.NaN;
plot ORL = if (ShowTodayOnly and
GetDay() != GetLastDay()) or
!ORActive
then Double.NaN
else if onexpansion and IsNaN(close)
then ORLexp
else if !onexpansion
then ORLow
else Double.NaN;
plot MID = if (ShowTodayOnly and
GetDay() != GetLastDay()) or
!ORActive
then Double.NaN
else (ORH + ORL) / 2;

ORH.SetDefaultColor(Color.GREEN);
ORH.SetStyle(Curve.MEDIUM_DASH);
ORH.SetLineWeight(2);
ORL.SetDefaultColor(Color.RED);
ORL.SetStyle(Curve.MEDIUM_DASH);
ORL.SetLineWeight(2);
MID.SetDefaultColor(Color.LIGHT_ORANGE);
MID.SetStyle(Curve.MEDIUM_DASH);
MID.SetLineWeight(2);``````

@SleepyZ , back with another q. haha

Below is the DailyHighLow study from TD Ameritrade.

Suppose I want to get close or HL2 or some other fundamental type. how can an input like, 'input type = FundamentalType.CLOSE;' be utilized to achieve that?

Would you know how to code it to show/hide the plot during non-rth hours (without hardcodding start/end) based on a boolean input (e.g. input showOnlyDuringRTH = yes)

Rich (BB code):
``````input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;

plot DailyHigh;
plot DailyLow;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
DailyHigh = Double.NaN;
DailyLow = Double.NaN;
} else {
DailyHigh = Highest(high(period = aggregationPeriod)[-displace], length);
DailyLow = Lowest(low(period = aggregationPeriod)[-displace], length);
}

DailyHigh.SetDefaultColor(GetColor(4));
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(GetColor(4));
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);``````

@SleepyZ , back with another q. haha

Below is the DailyHighLow study from TD Ameritrade.

Suppose I want to get close or HL2 or some other fundamental type. how can an input like, 'input type = FundamentalType.CLOSE;' be utilized to achieve that?

Would you know how to code it to show/hide the plot during non-rth hours (without hardcodding start/end) based on a boolean input (e.g. input showOnlyDuringRTH = yes)

Rich (BB code):
``````input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;

plot DailyHigh;
plot DailyLow;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
DailyHigh = Double.NaN;
DailyLow = Double.NaN;
} else {
DailyHigh = Highest(high(period = aggregationPeriod)[-displace], length);
DailyLow = Lowest(low(period = aggregationPeriod)[-displace], length);
}

DailyHigh.SetDefaultColor(GetColor(4));
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(GetColor(4));
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);``````

This might help. It has an example of how to use the fundamental type input as well as an input to limit the Plots to RTH Only.

[Edited to reflect request in #8]
Ruby:
``````input type  = FundamentalType.HL2;
input aggregationPeriod = AggregationPeriod.DAY;
input length = 1;
input displace = -1;
input showOnlyLastPeriod = no;
input showOnlyRTH = yes;

plot DailyHigh;
plot DailyLow;
plot Daily_Type;
if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {
DailyHigh = Double.NaN;
DailyLow = Double.NaN;
Daily_Type = Double.NaN;
} else {
DailyHigh  = if IsNaN(close(period = aggregationPeriod))
then Double.NaN
else if showOnlyRTH and RTH or showOnlyRTH == no
then Highest(high(period = aggregationPeriod)[-displace], length)
else Double.NaN;
DailyLow   = if IsNaN(close(period = aggregationPeriod))
then Double.NaN
else if showOnlyRTH and RTH or showOnlyRTH == no
then Lowest(low(period = aggregationPeriod)[-displace], length)
else Double.NaN;
Daily_Type = if IsNaN(close(period = aggregationPeriod))
then Double.NaN
else if showOnlyRTH and RTH or showOnlyRTH == no
then Fundamental(type, period = aggregationPeriod)[-displace]
else Double.NaN;
}

DailyHigh.SetDefaultColor(Color.YELLOW);
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(Color.YELLOW);
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
Daily_Type.SetDefaultColor(Color.WHITE);
Daily_Type.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);``````

Last edited:
@SleepyZ : This is GREAT! Just what I was looking for. Thank you

Just a couple things.

1) Improvement: Is it possible to plot for the next (future) period only after the current period ends?

i.e.
if aggregationPeriod = day, plot data only for today (or past depending on showOnlyLastPeriod) period on the chart (during RTH or RTH + AH/PM depending on showOnlyRTH). As soon as that period portion of aggregationPeriod ends, plot the data for the subsequent period and current day would become "past"

e.g.
I'm viewing SPY at 5D 5m tf.
----------------------------------
My aggregationPeriod = day

When showOnlyLastPeriod = 1, only plot the lines on today's portion depending on showOnlyRTH. There should be no lines plotted on the right (expansion) area for future days. As soon as the day ends (depending on showOnlyRTH), the lines for tomorrow will show up and lines for current day will hide (becoming "past" period; to show it, showOnlyLastPeriod would need to be true).
----------------------------------
My aggregationPeriod = week
When showOnlyLastPeriod = 1, only plot the lines on current WEEK's portion depending on showOnlyRTH. There should be no lines plotted on the right (expansion) area for future weeks. As soon as the WEEK ends (depending on showOnlyRTH), the lines for next week will show up and lines for current week will hide (becoming "past" period; to show it, showOnlyLastPeriod would need to be true).

2) Bug: When I set tf to 5Y 1d and the study's aggregationPeriod = day (wk and etc), nothing is plotted for some reason.

Last edited:
@SleepyZ : This is GREAT! Just what I was looking for. Thank you

Just a couple things.

1) Improvement: Is it possible to plot for the next (future) period only after the current period ends?

i.e.
if aggregationPeriod = day, plot data only for today (or past depending on showOnlyLastPeriod) period on the chart (during RTH or RTH + AH/PM depending on showOnlyRTH). As soon as that period portion of aggregationPeriod ends, plot the data for the subsequent period and current day would become "past"

e.g.
I'm viewing SPY at 5D 5m tf.
----------------------------------
My aggregationPeriod = day

When showOnlyLastPeriod = 1, only plot the lines on today's portion depending on showOnlyRTH. There should be no lines plotted on the right (expansion) area for future days. As soon as the day ends (depending on showOnlyRTH), the lines for tomorrow will show up and lines for current day will hide (becoming "past" period; to show it, showOnlyLastPeriod would need to be true).
----------------------------------
My aggregationPeriod = week
When showOnlyLastPeriod = 1, only plot the lines on current WEEK's portion depending on showOnlyRTH. There should be no lines plotted on the right (expansion) area for future weeks. As soon as the WEEK ends (depending on showOnlyRTH), the lines for next week will show up and lines for current week will hide (becoming "past" period; to show it, showOnlyLastPeriod would need to be true).

2) Bug: When I set tf to 5Y 1d and the study's aggregationPeriod = day (wk and etc), nothing is plotted for some reason.
I have edited the code above in post #7 to
1) eliminate the future plots.
2) Bug, is not a bug, but you do need to set input showOnlyRTH to NO as there are no RTH on a daily, weekly., etc ... chart.

@SleepyZ ... WOW! Thank you!! and your second point makes sense.

While testing this, I thought of something else maybe you can help me with.

When either Open, Low, High, or Close is selected for "type" input, can the study (optionally) draw cloud of the range of that bar instead of the line?

e.g. for the same setup as above example.

input type = FundamentalType.Open;
input drawRange = yes; #Only applies when type is either O, L, H, or C
input drawRangeForEntireBar = yes; #Only applies when drawRange is yes

For this scenario, instead of the line @ prev Open for the selected aggregation period, draw a cloud for the range of the entire previous Open bar, wick-to-wick.

input type = FundamentalType.High;
input drawRange = yes; #Only applies when type is either O, L, H, or C
input drawRangeForEntireBar = no; #Only applies when drawRange is yes

For this scenario, instead of the line @ prev Highest high for the selected aggregation period, draw a cloud for the range of the body of the previous bar that defined Highest high, just between open and close (body)

Hi @SleepyZ , just checking in case you missed my previous comment.

Another question I had was, what's the difference between hardcoded for DailyHigh/DailyLow vs choosing High/Low for "input type" (Daily_Type) Do you see it not working the same under certain situations?

Hi @SleepyZ , just checking in case you missed my previous comment.

Another question I had was, what's the difference between hardcoded for DailyHigh/DailyLow vs choosing High/Low for "input type" (Daily_Type) Do you see it not working the same under certain situations?
The Daily_Type will only be affected by the displace value, whereas the DailyHigh/Low will as be affected by the Highest/Lowest length value.

The Daily_Type will only be affected by the displace value, whereas the DailyHigh/Low will as be affected by the Highest/Lowest length value.
Understood. Would it then be correct to say that, with "HL2" selected as a type, displacement of -1, length of 2, and aggprd = day, it would get mid-point of yesterday instead of the last two days? If so, I'm assuming the length potion was left out in Daily_Type calculation because it's not possible to do due to thinkscript limitation right? (not sure if there's anything like "highest" or "lowest" for those situations).

Hi, I would like to show a label on top chart that prints an average of Open to High for past 5 days (call it, "Avg OTH = \$##.."). Would that be possible to do in ToS?

Understood. Would it then be correct to say that, with "HL2" selected as a type, displacement of -1, length of 2, and aggprd = day, it would get mid-point of yesterday instead of the last two days? If so, I'm assuming the length potion was left out in Daily_Type calculation because it's not possible to do due to thinkscript limitation right? (not sure if there's anything like "highest" or "lowest" for those situations).
Since you are using the code with different input lengths, the Daily_Type becomes problematic and I have removed it from the following code. Since HL2 is merely the average of HL, I have made it an option to show and correspond to any length you might enter.

Ruby:
``````input showHL2  = yes;

input aggregationPeriod = AggregationPeriod.DAY;
input length   = 1;
input displace = -1;

input showOnlyLastPeriod = no;
input showOnlyRTH        = yes;

plot DailyHigh;
plot DailyLow;
plot DailyHL2;

if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {

DailyHigh = Double.NaN;
DailyLow = Double.NaN;
DailyHL2 = Double.NaN;

} else {

DailyHigh  = if IsNaN(close(period = aggregationPeriod))
then Double.NaN
else if showOnlyRTH and RTH or showOnlyRTH == no
then Highest(high(period = aggregationPeriod)[-displace], length)
else Double.NaN;
DailyLow   = if IsNaN(close(period = aggregationPeriod))
then Double.NaN
else if showOnlyRTH and RTH or showOnlyRTH == no
then Lowest(low(period = aggregationPeriod)[-displace], length)
else Double.NaN;
DailyHL2   = if showHL2 then (DailyHigh + DailyLow) / 2 else Double.NaN;
}

DailyHigh.SetDefaultColor(Color.YELLOW);
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(Color.YELLOW);
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyHL2.SetDefaultColor(Color.YELLOW);
DailyHL2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);``````

Since you are using the code with different input lengths, the Daily_Type becomes problematic and I have removed it from the following code. Since HL2 is merely the average of HL, I have made it an option to show and correspond to any length you might enter.
Thank you!

And open can simply be the following ("length" doesn't play a role for open right?)

def open = open(period = aggregationPeriod)[-displace];

What about close? length = 2 would mean show me close of the period that consists of 2 aggregationPeriod (I think the following would be incorrect).
def close = close(period = aggregationPeriod)[-displace];

Hi, I would like to show a label on top chart that prints an average of Open to High for past 5 days (call it, "Avg OTH = \$##.."). Would that be possible to do in ToS?
Try this
Ruby:
``````input days = 2;
def diff   = high(period = AggregationPeriod.DAY) - open(period = AggregationPeriod.DAY);
AddLabel(1, "Avg OTH = " + AsDollars(Sum(diff, days) / days), Color.YELLOW);``````

Thank you!

And open can simply be the following ("length" doesn't play a role for open right?)

def open = open(period = aggregationPeriod)[-displace];

What about close? length = 2 would mean show me close of the period that consists of 2 aggregationPeriod (I think the following would be incorrect).
def close = close(period = aggregationPeriod)[-displace];

Based upon your further questions, it appears that you want the actual daily highs, lows, closes, opens based upon how many days you want to lookback. Since the DaillyHigh/DailyLow were not doing that as it used highest/lowest over a length there was a mismatch with the closes/opens when you changed the inputs length/displace. So I have reworked the code to using the actual amounts based upon the displace/length combined into just displace.

Ruby:
``````input showHL2   = yes;
input showOpen  = yes;
input showClose = yes;
input aggregationPeriod = AggregationPeriod.DAY;
input displace = 1;

input showOnlyLastPeriod = no;
input showOnlyRTH        = yes;

plot DailyHigh;
plot DailyLow;
plot DailyHL2;

if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {

DailyHigh = Double.NaN;
DailyLow = Double.NaN;
DailyHL2 = Double.NaN;

} else {

DailyHigh  = if IsNaN(close(period = aggregationPeriod))
then Double.NaN
else if showOnlyRTH and RTH or showOnlyRTH == no
then high(period = aggregationPeriod)[displace]
else Double.NaN;
DailyLow   = if IsNaN(close(period = aggregationPeriod))
then Double.NaN
else if showOnlyRTH and RTH or showOnlyRTH == no
then low(period = aggregationPeriod)[displace]
else Double.NaN;
DailyHL2   = if showHL2 then (DailyHigh + DailyLow) / 2 else Double.NaN;
}

DailyHigh.SetDefaultColor(Color.MAGENTA);
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(Color.MAGENTA);
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyHL2.SetDefaultColor(Color.WHITE);
DailyHL2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot DailyOpen  = if !showopen or IsNaN(close(period = aggregationPeriod))
then Double.NaN
else if showOnlyRTH and RTH or showOnlyRTH == no
then open(period = aggregationPeriod)[displace]
else Double.NaN;

plot DailyClose = if !showclose or IsNaN(close(period = aggregationPeriod))
then Double.NaN
else if showOnlyRTH and RTH or showOnlyRTH == no
then close(period = aggregationPeriod)[displace]
else Double.NaN;

DailyOpen.SetDefaultColor(Color.CYAN);
DailyOpen.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyClose.SetDefaultColor(Color.YELLOW);
DailyClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);``````

Based upon your further questions, it appears that you want the actual daily highs, lows, closes, opens based upon how many days you want to lookback. Since the DaillyHigh/DailyLow were not doing that as it used highest/lowest over a length there was a mismatch with the closes/opens when you changed the inputs length/displace. So I have reworked the code to using the actual amounts based upon the displace/length combined into just displace.
Thank you for the update. I was looking for a way to possibly get this data for more than a single day/wk/qt/etc. e.g. get high of past two days (length = 2). But now that I think about it, complexity in code, especially when it comes to calculating "Close" in that scenario is not worth the benefit and agree with your new approach.

Just one last thing, would it be possible to plot a cloud instead of one line of that bar for O/L/H/C? e.g. instead of plotting a line for prev High, draw a cloud that covers the bar that reached that highest price (similar for Open/Close/Low lines).

Thank you for the update. I was looking for a way to possibly get this data for more than a single day/wk/qt/etc. e.g. get high of past two days (length = 2). But now that I think about it, complexity in code, especially when it comes to calculating "Close" in that scenario is not worth the benefit and agree with your new approach.

Just one last thing, would it be possible to plot a cloud instead of one line of that bar for O/L/H/C? e.g. instead of plotting a line for prev High, draw a cloud that covers the bar that reached that highest price (similar for Open/Close/Low lines).
You're welcome

It seems you should be able to do the first idea by using multiple copies of the study and changing the inputs.

As to the clouds, here is something to look at that I have not spent much time evaluating their usefulness or correctness.

Ruby:
``````input showHL2   = yes;
input showOpen  = yes;
input showClose = yes;
input aggregationPeriod = AggregationPeriod.DAY;
input displace = 1;

input showOnlyLastPeriod = no;
input showOnlyRTH        = yes;

plot DailyHigh;
plot DailyLow;
plot DailyHL2;

if showOnlyLastPeriod and !IsNaN(close(period = aggregationPeriod)[-1]) {

DailyHigh = Double.NaN;
DailyLow = Double.NaN;
DailyHL2 = Double.NaN;

} else {

DailyHigh  = if IsNaN(close(period = aggregationPeriod))
then Double.NaN
else if showOnlyRTH and RTH or showOnlyRTH == no
then high(period = aggregationPeriod)[displace]
else Double.NaN;
DailyLow   = if IsNaN(close(period = aggregationPeriod))
then Double.NaN
else if showOnlyRTH and RTH or showOnlyRTH == no
then low(period = aggregationPeriod)[displace]
else Double.NaN;
DailyHL2   = if showHL2 then (DailyHigh + DailyLow) / 2 else Double.NaN;
}

DailyHigh.SetDefaultColor(Color.MAGENTA);
DailyHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyLow.SetDefaultColor(Color.MAGENTA);
DailyLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyHL2.SetDefaultColor(Color.WHITE);
DailyHL2.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

plot DailyOpen  = if !showOpen or IsNaN(close(period = aggregationPeriod))
then Double.NaN
else if showOnlyRTH and RTH or showOnlyRTH == no
then open(period = aggregationPeriod)[displace]
else Double.NaN;

plot DailyClose = if !showClose or IsNaN(close(period = aggregationPeriod))
then Double.NaN
else if showOnlyRTH and RTH or showOnlyRTH == no
then close(period = aggregationPeriod)[displace]
else Double.NaN;

DailyOpen.SetDefaultColor(Color.CYAN);
DailyOpen.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
DailyClose.SetDefaultColor(Color.YELLOW);
DailyClose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);

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

def bn = BarNumber();
def dhbar = if thisDay == displace and RTH and high == high(period = AggregationPeriod.DAY) then bn else dhbar[1];
def dhh   = if bn == dhbar then high else dhh[1];
def dhl   = if bn == dhbar then low else dhl[1];
plot xdhh = if thisDay == 0 and RTH then dhh else Double.NaN;
plot xdhl = dhl;

def dlbar = if thisDay == displace and RTH and low == low(period = AggregationPeriod.DAY) then bn else dlbar[1];
def dlh   = if bn == dlbar then high else dlh[1];
def dll   = if bn == dlbar then low else dll[1];
plot xdlh = if thisDay == 0 and RTH then dlh else Double.NaN;
plot xdll = dll;

def dobar = if thisDay == displace and open==open(period = AggregationPeriod.DAY) then bn else dobar[1];
def doh   = if bn == dobar then high else doh[1];
def dol   = if bn == dobar then low else dol[1];
plot xdoh = if thisDay == 0 and RTH then doh else Double.NaN;
plot xdol = dol;

def dcbar = if thisDay == displace and close(period = AggregationPeriod.DAY) then bn else dcbar[1];
def dch   = if bn == dcbar then high else dch[1];
def dcl   = if bn == dcbar then low else dcl[1];
plot xdch = if thisDay == 0 and RTH then dch else Double.NaN;
plot xdcl = dcl;

xdhh.hide();
xdhl.hide();
xdlh.hide();
xdll.hide();
xdoh.hide();
xdol.hide();
xdch.hide();
xdcl.hide();

#``````

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