pine-script - 我如何绘制从今天开始关闭的会话?
问题描述
我创建了一个简单的脚本来绘制一个差距范围,但是,在这个迭代中,它不会在市场实际开盘之前绘制下一个会话的差距,所以你不能做任何盘前思考。我一直在通过将变量设为用户输入并手动输入关闭值来解决此问题,但我更愿意自动执行此操作。
这是当前形式的脚本:
//@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)
解决方案
不完全确定,但可能是这样的:
//@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)
推荐阅读
- numpy - 创建没有内存副本的共享内存 Numpy ndarray
- sandbox - ICICI IMPS 支付 API 不适用于邮递员
- node.js - 关于使用 MongoDB 托管 Express 应用程序的问题
- python - 无法创建临时目录“C:\CONDA_~1\2\conda-
\" - reactjs - 如何通过反应路由器重定向登录和注册页面
- lua - 如何添加“状态”?不和谐
- instantsearch.js - 需要在 meilisearch 即时搜索的过滤器中传递自定义文本框值
- c# - 如何在 asp.net core mvc C# 中将 List 对象转换为 Viewmodel 对象?
- jsp - 有没有在 JSP 模板中转换百里香模板的解决方案?
- java - 如何同时实现n个目标的搜索算法