pine-script - Trading View - Gap calc - 如何判断当日交易时段是否开始与市场关闭的状态?
问题描述
我正在尝试制作一个进行差距计算的脚本,我命令计算差距,我有两种情况:1.在市场收盘期间我想使用最后延长时间的价格 2.当市场开盘时我想使用开盘价/昨天收盘价
is_newbar(res) =>
change(time(res,session.regular)) != 0
new_day = is_newbar("D") ? 1 : 0
// new_day returns 0 even during the market hours.
o = security(tick, "D", open)
c = security(tick, "D", close)
extended_close = new_day ? o : get_extended_last("5")
session_close = new_day ? c[1] : c
gap = extended_close / session_close
我的观点是5m图表。我想要每天的差距
还是有更简单的方法来获得差距?
解决方案
您正在以“D”分辨率测试常规会话,因此条件永远不会正确。我不明白您对何时使用哪个价格的要求,但使用这些条件您应该能够获得您需要的价格。如果没有,请发表评论。
//@version=4
study("")
regularSession() =>
time(timeframe.period, session.regular)
regularSessionBegins = regularSession() and not regularSession()[1]
plotchar(regularSessionBegins, "regularSessionBegins", "▲", location.top)
plotchar(regularSession(), "regularSession()", "•", location.bottom)
推荐阅读
- javascript - 我的 Django/Bootstrap 4 网站上的下拉导航栏菜单适用于除主页之外的任何地方
- java - Java - 尝试从另一个类访问一个类时出错
- python - 小数舍入错误:在 pandas 系列上使用时,numpy floor 和 trunc 在 python 中无法正常工作
- vector - 是否有更有效的方法来调整表示为 Vec 的二维网格的大小
? - makefile - Makefile 找不到规则
- azure-resource-manager - 如何有效地开发 Azure 蓝图?
- javascript - 根据用户的浏览器语言或国家/地区加载 JavaScript 文件
- javascript - 扩展另一个类时原型 instanceof 为假
- c - 读取随机文本行的分段错误?
- flutter - Firestore 查询文档的子集合