Reputation: 25
I was able to create a Hline on price low at a specific time (ex.10:00) in the main chart. How should I go about if I wanted to create a Hline at the lowest price of a time range (say 10:00 - 10:05) in a 1min chart?
//@version=5
indicator("My Script", overlay=true)
_h = 10 // Hour: 10
_m = 0 // Minute: 0
inWindow = (hour(time) == _h) and (minute(time) == _m)
var line l = na
if (inWindow)
l := line.new(bar_index, low, bar_index + 1, low, extend=extend.right, color=color.orange, width=2)
line.delete(l[1])
Upvotes: 0
Views: 880
Reputation: 21121
You can use the input.session()
to get the time frame and time()
to see if you are in the selected time window.
//@version=5
indicator("My script", overlay=true)
time_window = input.session("0900-1500", "Session")
is_in_window = time(timeframe.period, time_window + ":1234567")
var float _lowest = na
if is_in_window
if (not is_in_window[1])
_lowest := low
else
_lowest := math.min(low, _lowest)
else
_lowest := na
plot(_lowest, "Lowest", color.red, 1, plot.style_circles)
Upvotes: 1