Plotting New Established Low for a certain time intraday results to {EMPTY}

Hey everyone,

My goal in this code is to plot a new low every time it is established from 9:30 (Market open) until 10:00.

The idea is that whatever the lowest value by 10:00 should be considered the established low for the rest of the trading day.

Here's the code I have so far:

Plot( Close, "Close", colorDefault, styleCandle );
tm = TimeNum()/10000;

StartTime = 9.30; 
EndTime   = 10.00;
market_open = tm == StartTime;
tm_range = tm > StartTime AND tm <= EndTime;
time_ended = tm > EndTime;

idLow = StaticVarGet("Intraday_Low");	//intraday Low

StartBar = tm == StartTime;
EndBar = tm == EndTime;

idLow = IIf(market_open, L,
		IIf(tm_range AND L < Ref(idLow, -1), L,
		IIf(tm_range AND L > Ref(idLow, -1), Ref(idLow, -1),
		IIf(time_ended, ValueWhen(EndBar, LowestSince(StartBar,L)),
		idLow))));


StaticVarSet("Intraday_Low",idLow);	

Plot(idLow,"Day Level", colorAqua, style = styleLine,minvalue=0, maxvalue=0, XShift=0,Zorder=0,width=1);
printf("intraday Low = %s\n", NumToStr(idLow));

The issue I'm encountering is that sometimes the code works, but most of the time, between 9:30 AM and 10:00 AM, a gap in plotting is created because the established low becomes {EMPTY}.

Here's a screenshot showing the gap between the plotting that is {EMPTY}.

I'm wondering if I'm missing something in my approach. Any insights or suggestions would be greatly appreciated. Thanks in advance!

I think your code could be simplified to:

Plot( Close, "Close", colorDefault, styleCandle );
tm = TimeNum()/10000;

StartTime = 9.30; 
EndTime   = 10.00;
market_open = tm == StartTime;
tm_range = tm >= StartTime AND tm <= EndTime;

idLow = ValueWhen(tm_range, LowestSince (market_open, L));

Plot(idLow,"Day Level", colorAqua, style = styleLine,minvalue=0, maxvalue=0, XShift=0,Zorder=0,width=1);
printf("intraday Low = %s\n", NumToStr(idLow));
2 Likes

Wow! @mradtke that worked perfectly and solved the issue. you're a genius. I cant thank you enough. :saluting_face:

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.