简体   繁体   中英

Pinescript - Plotting hline at lowest price candle within specific time range

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])

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)

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM