首页 > 解决方案 > 我如何绘制从今天开始关闭的会话?

问题描述

我创建了一个简单的脚本来绘制一个差距范围,但是,在这个迭代中,它不会在市场实际开盘之前绘制下一个会话的差距,所以你不能做任何盘前思考。我一直在通过将变量设为用户输入并手动输入关闭值来解决此问题,但我更愿意自动执行此操作。

它在哪里 vs 我想要它在哪里

这是当前形式的脚本:

//@version=4
study("Mastering the Gaps", overlay=true)

//Color
var color yellow = #FFFF99

//User defined variables
gapSize = input(defval = .20, title = "Gap width")
labelOffset = input(defval = 20)

//Data fetching
sClose = security(symbol = syminfo.tickerid, resolution = "D", expression = close[1], lookahead = true)

//Gap calculations
uGap = sClose + gapSize
dGap = sClose - gapSize

//Draw gap lines
line.new(x1 = bar_index -1, y1 = uGap, x2 = bar_index, y2 = uGap, extend = extend.both, color = color.new(yellow,50), width = 1)
line.new(x1 = bar_index -1, y1 = dGap, x2 = bar_index, y2 = dGap, extend = extend.both, color = color.new(yellow,50), width = 1)

//Gap Labels
var label uGapLabel = label.new(bar_index, uGap, "Upper Gap Range", style=label.style_label_down, color = color.new(yellow, 50))
var label dGapLabel = label.new(bar_index, dGap, "Lower Gap Range", style=label.style_label_up, color = color.new(yellow,50))

//Label location
label.set_xy(uGapLabel, bar_index - labelOffset, uGap)
label.set_xy(dGapLabel, bar_index - labelOffset, dGap)

我也尝试过这段代码,但是我只是收到一个研究错误,说分辨率“1600”无效。

sClose = security(symbol = syminfo.tickerid, resolution = '1600', expression = close[1], lookahead=barmerge.lookahead_on)

标签: pine-script

解决方案


不完全确定,但可能是这样的:

//@version=4
study("Mastering the Gaps", overlay=true)

//Color
var color yellow = #FFFF99

//User defined variables
gapSize = input(defval = 5, title = "Gap width")
labelOffset = input(defval = 20)

// var float sClose = na

var line l1 = line.new(na, na, na, na, xloc=xloc.bar_time, extend = extend.right, color = color.new(yellow,50), width = 1)
var line l2 = line.new(na, na, na, na, xloc=xloc.bar_time, extend = extend.right, color = color.new(yellow,50), width = 1)

//Data fetching
[sClose, sTime] = security(syminfo.tickerid, "D", [close[1],time_close[1]])

if not barstate.isrealtime and barstate.islast and barstate.isconfirmed
    sClose := close
    sTime  := time

//Gap calculations
uGap = sClose + gapSize
dGap = sClose - gapSize

//Draw gap lines
line.set_xy1(l1, sTime,   uGap)
line.set_xy2(l1, sTime+1, uGap)

line.set_xy1(l2, sTime,   dGap)
line.set_xy2(l2, sTime+1, dGap)

//Gap Labels
var label uGapLabel = label.new(bar_index, uGap, "Upper Gap Range", style=label.style_label_down, color = color.new(yellow, 50))
var label dGapLabel = label.new(bar_index, dGap, "Lower Gap Range", style=label.style_label_up, color = color.new(yellow,50))

//Label location
label.set_xy(uGapLabel, bar_index - labelOffset, uGap)
label.set_xy(dGapLabel, bar_index - labelOffset, dGap)

推荐阅读