Ok, looks like your code is placed before the day_low and day_high's are actually calculated.
Try putting it above the plot code, and below the if-then code. Then let me know how that goes.
Great, thanks man! this one is working now:
Code:
study("4C PreMarket High/Low", shorttitle="4C PM_H/L", overlay=true)
t = time("1440", "0000-0930")
is_first = na(t[1]) and not na(t) or t[1] < t
ending_hour = input(defval=9, title="Ending Hour", type=input.integer)
ending_minute = input(defval=30, title="Ending Minute", type=input.integer)
day_high = float(na)
day_low = float(na)
if is_first and barstate.isnew and (hour < ending_hour or hour >= 16 or hour == ending_hour and minute < ending_minute)
day_high := high
day_low := low
day_low
else
day_high := day_high[1]
day_low := day_low[1]
day_low
if high > day_high and ((hour < ending_hour or hour >= 16) and hour < 16 or hour == ending_hour and minute < ending_minute)
day_high := high
day_high
if low < day_low and ((hour < ending_hour or hour >= 16) and hour < 16 or hour == ending_hour and minute < ending_minute)
day_low := low
day_low
alertcondition(cross(close,day_high), message = 'Price crossed Pre Market level')
plot(day_high, style=plot.style_line, color=color.yellow, linewidth=1)
plot(day_low, style=plot.style_line, color=color.orange, linewidth=1)
Now i need to find a way so i get 1 alert for both the high and the low, probably something like this?
Code:
study("4C PreMarket High/Low", shorttitle="4C PM_H/L", overlay=true)
t = time("1440", "0000-0930")
is_first = na(t[1]) and not na(t) or t[1] < t
ending_hour = input(defval=9, title="Ending Hour", type=input.integer)
ending_minute = input(defval=30, title="Ending Minute", type=input.integer)
day_high = float(na)
day_low = float(na)
if is_first and barstate.isnew and (hour < ending_hour or hour >= 16 or hour == ending_hour and minute < ending_minute)
day_high := high
day_low := low
day_low
else
day_high := day_high[1]
day_low := day_low[1]
day_low
if high > day_high and ((hour < ending_hour or hour >= 16) and hour < 16 or hour == ending_hour and minute < ending_minute)
day_high := high
day_high
if low < day_low and ((hour < ending_hour or hour >= 16) and hour < 16 or hour == ending_hour and minute < ending_minute)
day_low := low
day_low
alertcondition(cross(close,day_high)or(cross(close,day_low)), message = 'Price crossed Pre Market level')
plot(day_high, style=plot.style_line, color=color.yellow, linewidth=1)
plot(day_low, style=plot.style_line, color=color.orange, linewidth=1)