首页 > 解决方案 > 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

我的观点是5​​m图表。我想要每天的差距

还是有更简单的方法来获得差距?

标签: pine-script

解决方案


您正在以“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)

在此处输入图像描述


推荐阅读