Pine脚本:绘制时段内上午9点至上午10点的最高最低价

时间:2020-11-08 22:40:29

标签: pine-script

有人可以帮我做脚本吗?

  • 在上午9点至上午10点绘制最高价格水平
  • 在上午9点至上午10点绘制最低价格水平

这两行都是我当天的交易指南(1分钟图表), 将一直绘图到会话结束(下午5点)

1 个答案:

答案 0 :(得分:0)

这是您要找的吗?

//@version=4
study("My Script", overlay=true)

var int trackingStartHour = input(9, "Tracking start hour", minval=0, maxval=23)
var float hi = na
var float lo = na
var line_hi  = line.new(x1=na, y1=na, x2=na, y2=na, xloc=xloc.bar_time, extend=extend.right, color=color.green, style=line.style_dashed)
var line_lo  = line.new(x1=na, y1=na, x2=na, y2=na, xloc=xloc.bar_time, extend=extend.right, color=color.red,   style=line.style_dashed)

f_moveLine(_id, _x, _y) =>
    line.set_xy1(_id, _x,   _y)
    line.set_xy2(_id, _x+1, _y)
    
bool isNewDate = change(time("D"))

if isNewDate
    hi := na
    lo := na
    
if (hour == trackingStartHour)
    hi := max(nz(hi), high)
    lo := min(lo ? lo : 1.0e23, low)

canPlot    = hour >  trackingStartHour
showDashed = hour > trackingStartHour

plot(canPlot ? hi : na, "hi", color.green, style=plot.style_linebr)
plot(canPlot ? lo : na, "lo", color.red, style=plot.style_linebr)

if (showDashed and year(time)==year(timenow) and month(time)==month(timenow) and dayofmonth(time)==dayofmonth(timenow))
    f_moveLine(line_hi, time, hi)
    f_moveLine(line_lo, time, lo)