简体   繁体   中英

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

I want to draw the highest price of the previous month horizontally in the lower timeframes. How to draw a line that starts from the first candle of the previous month in lower timeframes?

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

Get the high value of the previous month with the request.security() function.

Then use the built-in variable time and built-in function timestamp() to figure out first candle of the month.

//@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)

在此处输入图像描述

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