如何在 Pine 脚本的较低时间范围内绘制上个月的最高价?

How to draw highest price of the previous month in the lower timeframes in Pine script?

我想在较低的时间范围内水平绘制上个月的最高价。 如何在较低的时间范围内绘制一条从上个月的第一根蜡烛开始的线?

line.new(x1 = time[1] , y1 = a, x2 = time , y2 = a, xloc = xloc.bar_time)

request.security()函数得到上月最高值

然后使用内置变量 time 和内置函数 timestamp() 计算出当月的第一根蜡烛。

//@version=5
indicator("My Script", overlay=true)

high_month = request.security(syminfo.tickerid, "M", high[1], lookahead=barmerge.lookahead_on)

targetDate = time >= timestamp(year(timenow), month(timenow), 1, 0, 0, 0)
beginMonth = not targetDate[1] and targetDate

var line l_high_month = na

if (beginMonth)
    l_high_month := line.new(bar_index, high_month, bar_index+1, high_month, extend=extend.right, color=color.green)
    line.delete(l_high_month[1])

plotshape(beginMonth, "T", shape.triangleup, location.belowbar, size=size.small)