Pine Script Pivot仅是最新的Pivot系列

时间:2019-09-28 20:27:02

标签: pine-script

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)

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

如果有可能用计数器决定退回两行

enter image description here

1 个答案:

答案 0 :(得分:1)

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

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

{"emID":65, ... the rest of my values ...}

enter image description here