【问题标题】:Pine Script Pivot just the newest Pivot linesPine Script Pivot 只是最新的 Pivot 行
【发布时间】:2019-09-28 20:27:02
【问题描述】:
study("Pivot Points Standard", shorttitle="Pivots Std", overlay=true) 

//var higherTF = input("D", type=input.resolution)

higherTF = iff(timeframe.isminutes,iff(timeframe.period == "15", "D", "W"), iff(timeframe.isdaily, "M", "12M"))

prevCloseHTF = security(syminfo.tickerid, higherTF, close[1], lookahead=true)
prevOpenHTF = security(syminfo.tickerid, higherTF, open[1], lookahead=true)
prevHighHTF = security(syminfo.tickerid, higherTF, high[1], lookahead=true)
prevLowHTF = security(syminfo.tickerid, higherTF, low[1], lookahead=true)

pLevel = (prevHighHTF + prevLowHTF + prevCloseHTF) / 3
r1Level = pLevel * 2 - prevLowHTF
s1Level = pLevel * 2 - prevHighHTF

var line r1Line = na
var line pLine = na
var line s1Line = na


if not na(pLine) and line.get_x2(pLine) != bar_index
    line.set_color(pLine,color.green)
    line.set_x2(r1Line, bar_index)
    line.set_x2(pLine, bar_index)
    line.set_x2(s1Line, bar_index)


if pLevel[1] != pLevel
    line.set_color(pLine,color.blue)
    line.set_x2(r1Line, bar_index)
    line.set_x2(pLine, bar_index)
    line.set_x2(s1Line, bar_index)
    r1Line := line.new(bar_index, r1Level, bar_index, r1Level, extend=extend.none)
    pLine := line.new(bar_index, pLevel, bar_index, pLevel, width=3, extend=extend.none)
    s1Line := line.new(bar_index, s1Level, bar_index, s1Level, extend=extend.none)
    label.new(bar_index, r1Level, "R1", style=label.style_none)
    label.new(bar_index, pLevel, "P", style=label.style_none)
    label.new(bar_index, s1Level, "S1", style=label.style_none)

我的代码是蓝色的。但我只想要最新的 2 行,比如棕色的 任何想法如何做到这一点?

如果有可能用一个计数器来决定一两行

enter image description here

【问题讨论】:

    标签: pine-script


    【解决方案1】:

    此代码使用此处解释的技术:http://www.pinecoders.com/faq_and_code/#how-can-i-keep-only-the-last-x-labels-or-lines

    您可以更改要保留的最后一行数:

    //@version=4
    maxBarsBack = 2000
    study("Pivot Points Standard", "Pivots Std", true, max_bars_back = maxBarsBack)
    
    //var higherTF = input("D", type=input.resolution)
    keepLastLines = input(2)
    
    higherTF = iff(timeframe.isminutes,iff(timeframe.period == "15", "D", "W"), iff(timeframe.isdaily, "M", "12M"))
    
    prevCloseHTF = security(syminfo.tickerid, higherTF, close[1], lookahead=true)
    prevOpenHTF = security(syminfo.tickerid, higherTF, open[1], lookahead=true)
    prevHighHTF = security(syminfo.tickerid, higherTF, high[1], lookahead=true)
    prevLowHTF = security(syminfo.tickerid, higherTF, low[1], lookahead=true)
    
    pLevel = (prevHighHTF + prevLowHTF + prevCloseHTF) / 3
    r1Level = pLevel * 2 - prevLowHTF
    s1Level = pLevel * 2 - prevHighHTF
    
    var line r1Line = na
    var line pLine = na
    var line s1Line = na
    // Create series which will hold line and label ids as they are created.
    line r1Line2 = na
    line pLine2 = na
    line s1Line2 = na
    label r1Lbl2 = na
    label pLbl2 = na
    label s1Lbl2 = na
    
    
    if not na(pLine) //and line.get_x2(pLine) != bar_index
        line.set_color(pLine,color.green)
        line.set_x2(r1Line, bar_index)
        line.set_x2(pLine, bar_index)
        line.set_x2(s1Line, bar_index)
    
    
    if pLevel[1] != pLevel
        line.set_color(pLine,color.blue)
        line.set_x2(r1Line, bar_index)
        line.set_x2(pLine, bar_index)
        line.set_x2(s1Line, bar_index)
        r1Line := line.new(bar_index, r1Level, bar_index, r1Level, extend=extend.none)
        pLine := line.new(bar_index, pLevel, bar_index, pLevel, width=3, extend=extend.none)
        s1Line := line.new(bar_index, s1Level, bar_index, s1Level, extend=extend.none)
        // Save line and label ids as they are created.
        r1Line2 := r1Line
        pLine2 := pLine
        s1Line2 := s1Line
        r1Lbl2 := label.new(bar_index, r1Level, "R1", style=label.style_none)
        pLbl2 := label.new(bar_index, pLevel, "P", style=label.style_none)
        s1Lbl2 := label.new(bar_index, s1Level, "S1", style=label.style_none)
    
    // ————— Delete all required lines.
    // Loop from previous bar into the past, looking for bars where a line was created.
    // Delete all lines found in last "maxBarsBack" bars after the required count has been left intact.
    lineCount = 0
    for i = 1 to maxBarsBack
        if not na(pLine2[i])
            lineCount := lineCount + 1
            if lineCount > keepLastLines
                line.delete(r1Line2[i])
                line.delete(pLine2[i])
                line.delete(s1Line2[i])
                label.delete(r1Lbl2[i])
                label.delete(pLbl2[i])
                label.delete(s1Lbl2[i])
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-01
      • 1970-01-01
      • 2016-01-29
      • 2013-04-17
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多