Previous HLC study show only today with label


Category:
0
0

Hi.. I have a great simple study to plot the HLC from the previous day (for intraday chart on current day) that I found here but would like it to plot only on the current day? (input showonlytoday = yes).. I believe I need some NaN values but can’t seem to get the sequence and I’m not that well acquainted with these functions, this is my main issue, I’d also like to show an optional label on the actual line (like YC, YL, YH) or similar.. Thanks so much

this code is simple and great but was just looking for a couple of added functions..

plot previousDayHigh = high(period = AggregationPeriod.DAY)[1];
previousDayHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
previousDayHigh.SetDefaultColor(Color.GREEN);

plot previousDayLow = low(period = AggregationPeriod.DAY)[1];
previousDayLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
previousDayLow.SetDefaultColor(Color.RED);

plot previousdayclose = close(period = aggregationPeriod.DAY)[1];
previousDayclose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
previousDayclose.SetDefaultColor(Color.white);

Marked as spam
Posted by (Questions: 1, Answers: 1)
Asked on January 18, 2023 9:10 am
104 views
0
Private answer

I think it's important to note there is a typo in your original title which I tried to correct. You listed this as OHL when in fact the code you provided includes only the HLC.

And let's make sure that everyone understand this is a pretty common request and has already been posted in a variety of forms throughout this forum. Many examples will define a specific period with a start time and end time. But others will show only for current day like the example below:

https://www.hahn-tech.com/ans/pre-market-hl-previous-days-hlc/

The following is a previous post that is nearly a perfect match for what you have requested:

https://www.hahn-tech.com/ans/plot-previous-hlc-without-extended-hours-on/

The key to this technique is creating a boolean variable statement which is used to "filter" the plot statements. I often name this variable "okToPlot" as follows:

def okToPlot = GetDay() == GetLastDay();

Now let's take the code you have provided and add this filter to it:

def okToPlot = GetDay() == GetLastDay();
plot previousDayHigh = if okToPlot then high(period = AggregationPeriod.DAY)[1] else Double.NaN;
previousDayHigh.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
previousDayHigh.SetDefaultColor(Color.GREEN);
plot previousDayLow = if okToPlot then low(period = AggregationPeriod.DAY)[1] else Double.NaN;
previousDayLow.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
previousDayLow.SetDefaultColor(Color.RED);
plot previousdayclose = if okToPlot then close(period = aggregationPeriod.DAY)[1] else Double.NaN;
previousDayclose.SetPaintingStrategy(PaintingStrategy.HORIZONTAL);
previousDayclose.SetDefaultColor(Color.white);
def lastBar = !IsNaN(close) and IsNaN(close[-1]);
AddChartBubble(lastBar, previousDayHigh, "YH");
AddChartBubble(lastBar, previousDayLow, "YL");
AddChartBubble(lastBar, previousDayClose, "YC");

Marked as spam
Posted by (Questions: 37, Answers: 4086)
Answered on January 18, 2023 10:14 am
0
Thanks so much for your reply.. I fixed the typo.. and I did spend some time on your site searching for a simplified code for my request, I guess I didn't use the best search criteria or I wasn't entirely sure what I was exactly looking for, I knew it must have been posted before because I've read enough of your posts to know that almost every question has had a post already addressing it.. haha.. anyway, thanks so much for this, I see your masterful use of this filter is what I was after.. Thank you so much for your time!!..
( at January 18, 2023 10:40 am)
0
Glad I could help. I like to provide as much context as possible for the benefit of the rest of our viewers. Many folks are tying to learn how to code by viewing these examples so I try to do a bit extra when I can. Speaking of which, I just realized I forgot to include the labels. So I updated my solution to include those labels.
( at January 18, 2023 10:45 am)
0
You are right many are trying to learn here by reading though the comments and solutions, I've learned a ton from all your hard work with videos and forum solutions!.. Thank you.. I understand we can't add text to a line in thinkscript so the line bubbles are great.. however these plot on the current bar.. is there a way to get them to plot at the left edge of the line?, I'm trying to fiddle with the code but I guess I'm still learning.. thanks so much again!..
( at January 18, 2023 11:05 am)
0
There are methods to "push" them to the left or right but that's a bit beyond the complexity of what I can provide here in the forum. I suggest you play around with the "lastBar" variable by placing an index value at the end at each of the AddChartBubble statements. Something like "lastBar[1]" may push them one bar to the right? Give it a shot.
( at January 18, 2023 11:08 am)
0
I Understand.. thanks for the tip.. I am playing around with it and have gotten the bubble to move.. or somehow trying to define the first bar but I will see if this is something I will even want moving forward.. Thanks so much again for all your hard work !!!..
( at January 18, 2023 11:32 am)
0
First bar of the trading session would be: def newDay = GetDay() GetDay()[1];
( at January 18, 2023 11:40 am)