【问题标题】:Find the highest and lowest value for a time frame in the pine editor在 pine 编辑器中查找时间范围内的最高和最低值
【发布时间】:2021-04-18 14:46:40
【问题描述】:

作为一个全新的初学者,我正在尝试使用 Tradingview 的 pine 编辑器。 我写了一个简单的脚本来绘制 ema 和 dema 之间的区别。此外,我想获得所选时间范围内的最高和最低值。

假设在 600 万个时间框架内,一只股票的最高收盘价为 120.3 美元,最低收盘价为 49.41 美元。我想绘制这两条水平线,分别代表特定时间范围内的历史最高点和历史最低点。

//@version=4
study(title="Test")

biggest(series) =>
    max = 0.0
    max := nz(max[1], series)
    if series > max
        max := series
    max

smallest(series) =>
    min = 0.0
    min := nz(min[1], series)
    if series < min
        min := series
    min

fast = 14, slow = 50

length = input(fast, minval=1)
src = input(close, title="Source")
e1 = ema(src, length)
e2 = ema(e1, length)
dema = 2 * e1 - e2

band4 = hline(0, "Upper Band", color=#ff0000)

fastEMA = ema(close, fast)
slowEMA = ema(close, slow)
test = (dema - slowEMA)//(high1-low1)
plot(test,color=color.white)

【问题讨论】:

    标签: pine-script highest


    【解决方案1】:
    //@version=4
    study(title="Help (Test)")
    
    biggest(series) =>
        max = 0.0
        max := nz(max[1], series)
        if series > max
            max := series
        max
    
    smallest(series) =>
        min = 0.0
        min := nz(min[1], series)
        if series < min
            min := series
        min
    
    fast = 14, slow = 50
    
    length = input(fast, minval=1)
    src = input(close, title="Source")
    e1 = ema(src, length)
    e2 = ema(e1, length)
    dema = 2 * e1 - e2
    
    band4 = hline(0, "Upper Band", color=#ff0000)
    
    fastEMA = ema(close, fast)
    slowEMA = ema(close, slow)
    test = (dema - slowEMA)//(high1-low1)
    plot(test,color=color.black)
    
    //[ADDON]
    period = input("6M", "Period hi/lo detect", input.resolution) //  Six Months
    
    var hi = 0.0
    var lo = 10e10
    var br = 0
    var lnhi = line.new(na, na, na , na)
    var lnlo = line.new(na, na, na , na)
    
    if change(time(period))
        hi := test
        lo := test
        br := bar_index
        lnhi := line.new(br, hi , br, hi, color=color.red, width=2)
        lnlo := line.new(br, lo , br, lo, color=color.green, width=2)
        float(na)
    else
        hi := max(test, hi)
        lo := min(test, lo)
    
    line.set_xy1(lnhi, br, hi)
    line.set_xy2(lnhi, bar_index, hi)
    line.set_xy1(lnlo, br, lo)
    line.set_xy2(lnlo, bar_index, lo)
    

    您的情节test 具有六个月时间范围内的绝对最高和最低值。

    【讨论】:

      【解决方案2】:

      您可以使用highest()lowest() 函数。

      因此,使用您的示例,您可以按如下方式添加最高和最低频段:

      //@version=4
      study(title="Test")
      
      hiloperiod = 200 // track highest/lowest of the last 200 periods
      fast = 14, slow = 50
      
      length = input(fast, minval=1)
      src = input(close, title="Source")
      e1 = ema(src, length)
      e2 = ema(e1, length)
      dema = 2 * e1 - e2
      
      band4 = hline(0, "Upper Band", color=#ff0000)
      
      fastEMA = ema(close, fast)
      slowEMA = ema(close, slow)
      test = (dema - slowEMA)//(high1-low1)
      plot(test,color=color.white)
      
      // Plot the highest and lowest values for the last hilo period.
      hi=highest(hiloperiod)
      lo=lowest(hiloperiod)
      plot(hi, color=color.green, linewidth=2)
      plot(lo, color=color.green, linewidth=2)
      

      例如在比特币价格上使用它会产生这个图表。请注意绿线如何移动以表示该时间范围内的最高和最低价格

      【讨论】:

      • 谢谢,但我只想绘制绝对最高值和最低值。因此,在我的例子中,两条水平线代表特定时间范围内的历史最高点和历史最低点
      猜你喜欢
      • 1970-01-01
      • 2015-05-22
      • 2015-08-13
      • 1970-01-01
      • 2017-08-26
      • 1970-01-01
      • 2019-02-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多