延长 Pine Script 中的枢轴高点和低点线。

huangapple go评论62阅读模式
英文:

extending pivot high and low lines in pine script

问题

//@version=5
indicator(title='s/r', shorttitle='s/r', overlay=true, max_bars_back=1000)

leftBars = input(10, title='左边柱数')
rightBars = input(10, title='右边柱数')
volumeThresh = input(20, title='成交量阈值')
highUsePivot = fixnan(ta.pivothigh(leftBars, rightBars)1)
lowUsePivot = fixnan(ta.pivotlow(leftBars, rightBars)1)
r1 = plot(highUsePivot, color=ta.change(highUsePivot) ? na : color.green, linewidth=1, offset=-(rightBars + 1), title='阻力')
s1 = plot(lowUsePivot, color=ta.change(lowUsePivot) ? na : color.green, linewidth=1, offset=-(rightBars + 1), title='支撑')
这段代码用于绘制枢轴高低支撑和阻力线。

如何将这些线延伸到右侧?

谢谢

英文:
//@version=5
indicator(title='s/r', shorttitle='s/r', overlay=true, max_bars_back=1000)


leftBars = input(10, title='Left Bars ')

rightBars = input(10, title='Right Bars')

volumeThresh = input(20, title='Volume Threshold')

highUsePivot = fixnan(ta.pivothigh(leftBars, rightBars)[1]) 

lowUsePivot = fixnan(ta.pivotlow(leftBars, rightBars)[1])

r1 = plot(highUsePivot, color=ta.change(highUsePivot) ? na : color.green, linewidth=1, offset=-(rightBars + 1), title='Resistance')

s1 = plot(lowUsePivot, color=ta.change(lowUsePivot) ? na : color.green, linewidth=1, offset=-(rightBars + 1), title='Support')

..................................................

This code draws pivot high and low support and resistance.
延长 Pine Script 中的枢轴高点和低点线。

How can I extend these lines to the right?

Thank you

....................

答案1

得分: 1

请检查以下脚本。
情节不能扩展,您必须使用“line”对象和“var”数组来存储它们。

以下是要翻译的代码部分:

indicator(title='s/r', shorttitle='s/r', overlay=true, max_bars_back=1000)

leftBars = input(10, title='Left Bars ')
rightBars = input(10, title='Right Bars')

volumeThresh = input(20, title='Volume Threshold')
highUsePivot = fixnan(ta.pivothigh(leftBars, rightBars)[1])
lowUsePivot = fixnan(ta.pivotlow(leftBars, rightBars)[1])

var arPivotHighs = array.new<line>()
var arPivotLows = array.new<line>()
maxPivots = input.int(5, "How many last pivots to draw")

ph = ta.pivothigh(leftBars, rightBars)
pl = ta.pivotlow(leftBars, rightBars)

if ph
    ln = line.new(bar_index-rightBars, ph, bar_index, ph, extend = extend.right, color = color.red, width = 2)
    arPivotHighs.unshift(ln)
    while arPivotHighs.size() > maxPivots
        arPivotHighs.last().delete()
        arPivotHighs.pop()

if pl
    ln = line.new(bar_index-rightBars, pl, bar_index, pl, extend = extend.right, color = color.green, width = 2)
    arPivotLows.unshift(ln)
    while arPivotLows.size() > maxPivots
        arPivotLows.last().delete()
        arPivotLows.pop()

以下脚本绘制4小时分界点:

indicator(title='s/r', shorttitle='s/r', overlay=true, max_bars_back=1000)

leftBars = input(10, title='Left Bars ')
rightBars = input(10, title='Right Bars')

Tf1 = input.timeframe("240", "Higher timeframe")

[h, l, ph, pl, t1, t2, bi] = request.security(syminfo.tickerid, Tf1, [
                                                      high
                                                      , low
                                                      , ta.pivothigh(high, leftBars, rightBars)
                                                      , ta.pivotlow(low, leftBars, rightBars)
                                                      , time[math.min(bar_index, leftBars+rightBars+1)]
                                                      , time_close[1]
                                                      , bar_index
                                                      ])

newHTFBar = ta.change(bi) // detect when data for new HTF bar becomes first available

var arPivotHighs = array.new<line>()
var arPivotLows = array.new<line>()
maxPivots = input.int(5, "How many last pivots to draw")

// we only draw lines on the first chart TF's bar of each HTF bar
if ph and newHTFBar
    ln = line.new(t1, ph, t2, ph, extend = extend.none, color = color.red, width = 2, xloc = xloc.bar_time)
    arPivotHighs.unshift(ln)
    while arPivotHighs.size() > maxPivots
        arPivotHighs.last().delete()
        arPivotHighs.pop()

if pl and newHTFBar
    ln = line.new(t1, pl, t2, pl, extend = extend.none, color = color.green, width = 2, xloc = xloc.bar_time)
    arPivotLows.unshift(ln)
    while arPivotLows.size() > maxPivots
        arPivotLows.last().delete()
        arPivotLows.pop()
英文:

Please check the script below.
The plot cannot be extended, you have to use line objects and a var array to store them.

//@version=5 
indicator(title=&#39;s/r&#39;, shorttitle=&#39;s/r&#39;, overlay=true, max_bars_back=1000)

leftBars = input(10, title=&#39;Left Bars &#39;)
rightBars = input(10, title=&#39;Right Bars&#39;)

volumeThresh = input(20, title=&#39;Volume Threshold&#39;)
highUsePivot = fixnan(ta.pivothigh(leftBars, rightBars)[1])
lowUsePivot = fixnan(ta.pivotlow(leftBars, rightBars)[1])


var arPivotHighs = array.new&lt;line&gt;()
var arPivotLows = array.new&lt;line&gt;()
maxPivots = input.int(5, &quot;How many last pivots to draw&quot;)

ph = ta.pivothigh(leftBars, rightBars)
pl = ta.pivotlow(leftBars, rightBars)

if ph
    ln = line.new(bar_index-rightBars, ph, bar_index, ph, extend = extend.right, color = color.red, width = 2)
    arPivotHighs.unshift(ln)
    while arPivotHighs.size() &gt; maxPivots
        arPivotHighs.last().delete()
        arPivotHighs.pop()

if pl
    ln = line.new(bar_index-rightBars, pl, bar_index, pl, extend = extend.right, color = color.green, width = 2)
    arPivotLows.unshift(ln)
    while arPivotLows.size() &gt; maxPivots
        arPivotLows.last().delete()
        arPivotLows.pop()


// r1 = plot(highUsePivot, color=ta.change(highUsePivot) ? na : color.green, linewidth=1, offset=-(rightBars + 1), title=&#39;Resistance&#39;)
// s1 = plot(lowUsePivot, color=ta.change(lowUsePivot) ? na : color.green, linewidth=1, offset=-(rightBars + 1), title=&#39;Support&#39;)

The script below draws 4H pivots:

//@version=5 
indicator(title=&#39;s/r&#39;, shorttitle=&#39;s/r&#39;, overlay=true, max_bars_back=1000)

leftBars = input(10, title=&#39;Left Bars &#39;)
rightBars = input(10, title=&#39;Right Bars&#39;)

Tf1 = input.timeframe(&quot;240&quot;, &quot;Higher timeframe&quot;) 

[h, l, ph, pl, t1, t2, bi] = request.security(syminfo.tickerid, Tf1, [
                                                          high
                                                          , low
                                                          , ta.pivothigh(high, leftBars, rightBars)
                                                          , ta.pivotlow(low, leftBars, rightBars)
                                                          , time[math.min(bar_index, leftBars+rightBars+1)]
                                                          , time_close[1]
                                                          , bar_index
                                                          ])


newHTFBar = ta.change(bi) // detect when data for new HTF bar becomes first available

var arPivotHighs = array.new&lt;line&gt;()
var arPivotLows = array.new&lt;line&gt;()
maxPivots = input.int(5, &quot;How many last pivots to draw&quot;)


// we only draw lines on the first chart TF&#39;s bar of each HTF bar
if ph and newHTFBar
    ln = line.new(t1, ph, t2, ph, extend = extend.none, color = color.red, width = 2, xloc = xloc.bar_time)
    arPivotHighs.unshift(ln)
    while arPivotHighs.size() &gt; maxPivots
        arPivotHighs.last().delete()
        arPivotHighs.pop()

if pl and newHTFBar
    ln = line.new(t1, pl, t2, pl, extend = extend.none, color = color.green, width = 2, xloc = xloc.bar_time)
    arPivotLows.unshift(ln)
    while arPivotLows.size() &gt; maxPivots
        arPivotLows.last().delete()
        arPivotLows.pop()

huangapple
  • 本文由 发表于 2023年4月11日 05:11:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/75980773.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定