【问题标题】:Pine Script plot based on higher timeframe基于更高时间范围的 Pine 脚本图
【发布时间】:2022-10-15 07:22:48
【问题描述】:

我想在 TradingView Pine Script 上将当前的 TF 系列扩展到更高的分辨率/时间范围。

例如...

假设我有一个具有以下系列的变量(比如说result):

...,3,0,0,0,2,0,1,0,0,0,16,5,-2,0,0,0,...

这里假设上面的数据是在 1m(分钟)的 TF 上。

所以我遇到的问题是数据在 1m TF 上,所以当我尝试查看 HTF 上的指标时,例如3m、15m;我无法以理想的方式查看数据,而是以一种采样的方式查看数据。例如什么时候:

// 1m
...,9:00,9:01,9:02,9:03,4,5,6,7,8,(and so on)...
...,3,0,0,0,2,0,1,0,0,0,16,5,-2,0,0,0,...

这将是:

// 3m
...,9:00,9:03,9:06,9:09,12,15,(and so on)...
...,3,0,1,0,-2,...

看?虽然在上述情况下,诸如“16”之类的值在 1m 中是一个重要的值,但在 3m 中它被消除了。

作为对此的解决方案,我想查看 HTF 上的最高(最大值)/最低(最小值)值。

所以我在这里需要的是类似于:

// 3m
...,9:00,9:03,9:06,9:09,12,15,(and so on)...
...,3,2,1,16,-2,...

所以可以转换为:

// 1m
...,9:00,9:01,9:02,9:03,4,5,6,7,8,(and so on)...
...,3,3,3,2,2,2,1,1,1,16,16,16,-2,-2,-2,...

抱歉解释不佳,但基本上我想要实现的是在 1m TF 上绘制上述数据系列。

顺便说一句 security() 在这种情况下不起作用。那就是问题所在。 security() 不会复制系列值,但会重新计算系列。

// this does an another thing
plot(security(syminfo.tickerid, "3", result))

那么,我能做些什么呢?

【问题讨论】:

    标签: pine-script


    【解决方案1】:
    //@version=5
    indicator("min/max over higher tf", overlay = true)
    
    higher_tf = input.timeframe("3")
    
    tf_denom = timeframe.in_seconds(higher_tf) / timeframe.in_seconds(timeframe.period)
    
    if int(tf_denom) != tf_denom
        runtime.error("Higher timeframe must be divisible by Chart timeframe")
    
    new_higher_tf = timeframe.change(higher_tf)
    
    var float min = na
    var float max = na
    
    if new_higher_tf
        min := low
        max := high
    else
        min := math.min(min, low)
        max := math.max(max, high)
    
    plot(min, color = color.red)
    plot(max, color = color.green)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-15
      • 2023-02-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多