【问题标题】:Trading View - Gap calc - How to tell if the day trading session started vs a state where market is closed?Trading View - Gap calc - 如何判断当日交易时段是否开始与市场关闭的状态?
【发布时间】:2020-04-22 17:30:20
【问题描述】:

我正在尝试制作一个进行间隙计算的脚本, 我为了计算差距,我有两种情况: 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 图表。我想要每日间隔

或者有没有更简单的方法来获得差距?

【问题讨论】:

    标签: pine-script


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-23
      • 1970-01-01
      • 2020-11-29
      • 1970-01-01
      • 2013-03-01
      • 2010-09-27
      相关资源
      最近更新 更多