high and low for specific time?


Hi Pete,

I tried searching for this but I didn’t have any luck.

I want to plot the high and low for a specific time period, 15:00 to 16:15 for example, but I also want the line to only plot during that time period if possible. I’ll show you what I tried, but it’s not correct.

def fifteen = if SecondsFromTime(1500) >= 0 and SecondsTillTime(1615) >= 0 then 1 else 0;

def Hourlyhigh = high(period = AggregationPeriod.hour)[0];
def HourlyLow = low(period = AggregationPeriod.hour)[0];

plot fifteenHigh = if fifteen then HourlyHigh else Double.NaN;
plot fifteenLow = if fifteen then HourlyLow else Double.NaN;

Thank you!

Marked as spam
Posted by (Questions: 2, Answers: 4)
Asked on October 15, 2019 4:06 pm
Private answer

The solution to this requires the use of recursive variables. This code makes use of very advanced techniques.

input startTime = 1500;
input endTime = 1615;
def targetPeriod = SecondsFromTime(startTime) >= 0 and SecondsTillTime(endTime) >= 0;
rec targetPeriodHigh = if targetPeriod and !targetPeriod[1] then high else if high > targetPeriodHigh[1] and targetPeriod then high else targetPeriodHigh[1];
rec targetPeriodLow = if targetPeriod and !targetPeriod[1] then low else if low > 0 and low < targetPeriodLow[1] and targetPeriod then low else targetPeriodLow[1];
def okToPlot = GetDay() == GetLastDay() and targetPeriod;
plot targetHigh = if okToPlot then HighestAll(if okToPlot then targetPeriodHigh else Double.NaN) else Double.NaN;
plot targetLow = if okToPlot then LowestAll(if okToPlot then targetPeriodLow else Double.NaN) else Double.NaN;

Marked as spam
Posted by (Questions: 36, Answers: 2220)
Answered on October 15, 2019 4:36 pm
Oh yeah, It's not likely that I would have figured that out. Thank you! Is it possible to make it plot the high and low for that time period on previous days as well? I tried making some adjustments, but again couldn't figure it out. Thank you!
( at October 15, 2019 9:21 pm)
There is no simple solution for that. The use of the HighestAll() and LowestAll() functions requires that we limit this to only display only on the current day's chart data. If this is absolutely critical you can submit a custom project request and pay for a more complex solution.
( at October 16, 2019 9:08 am)
Hi again. Thank you. I've also used this method to get the high, low and mid from 9:30 to 16:15 but I can't seem to get the chartbubble to show up using this line that I usually use for bubbles. addChartBubble (IsNaN(close[1]) and !IsNaN(close[2]), themid, "RTH Mid", color.cyan,yes); Is there a different script to add a bubble to this or another way to plot the RTH High, low, and mid that will accept chartbubbles? Thanks again.
( at October 18, 2019 9:57 pm)