在Pine Script 5中返回PivotHigh的bar_index是否可能?

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

Is it possible to return the bar_index of a PivotHigh in Pine Script 5?

问题

I'd like to set the index of bar_index[] based on ta.pivothigh in a dynamic way.

// PivotHigh 检查
leftBars = input(4)
rightBars = input(4)
ph = ta.pivothigh(leftBars, rightBars)
plot(ph, style=plot.style_circles, linewidth=3, color=#ffffff, offset=-rightBars)

// 绘制线条
upperLine = line.new(na(bar_index[ph]) ? bar_index : bar_index[ph], na(high[ph]) ? high : high[ph], color=#ffffff, width=2)

正如你所看到的,数字10和20并未以动态方式编写,因为我写了bar_indexhigh的索引。是否可能返回ta.pivothigh创建的每个圆的值,以便自动填充索引?

英文:

I'd like to set the index of bar_index[] based on ta.pivothigh in a dynamic way.

// PivotHigh Check
leftBars= input(4)
rightBars = input(4)
ph = ta.pivothigh(leftBars, rightBars)
plot(ph, style=plot.style_circles, linewidth=3, color=#ffffff, offset=-rightBars)

// Draw the line
upperLine = line.new(bar_index[10], high[10], bar_index[20], high[20], color=#ffffff, width = 2)

As you can see the numbers 10 and 20 aren't written in a dyinamic way, because I wrote the index of bar_index and high.
Is it possible to return the value of each circles made by ta.pivothigh in order to fill the index automatically?

答案1

得分: 1

当你的支点被绘制时,你离它有'rigthBars'的距离。
所以你的支点的索引是bar_index - rigthBars。

//@version=5
indicator("测试", overlay = true)
var IndexNewPivot = 0
var IndexOldPivot = 0
// PivotHigh 检查
leftBars = input(4)
rightBars = input(4)
ph = ta.pivothigh(leftBars, rightBars)
plot(ph, style=plot.style_circles, linewidth=3, color=color.purple, offset=-rightBars)

if ph > 0
// 画线
IndexNewPivot := bar_index - rightBars
upperLine = line.new(IndexOldPivot, high[bar_index - IndexOldPivot], IndexNewPivot, high[bar_index - IndexNewPivot], color=color.blue, width = 2)
IndexOldPivot := IndexNewPivot

结果:
在Pine Script 5中返回PivotHigh的bar_index是否可能?

英文:

When your pivot is drawn, you are 'rigthBars' away from it.
So the index of your pivot is bar_index-rigthBars.

//@version=5
indicator("test", overlay = true)
var IndexNewPivot = 0
var IndexOldPivot = 0
// PivotHigh Check
leftBars= input(4)
rightBars = input(4)
ph = ta.pivothigh(leftBars, rightBars)
plot(ph, style=plot.style_circles, linewidth=3, color=color.purple, offset=-rightBars)

if ph > 0
    // Draw the line
    IndexNewPivot := bar_index - rightBars
    upperLine = line.new(IndexOldPivot, high[bar_index - IndexOldPivot], IndexNewPivot, high[bar_index - IndexNewPivot], color=color.blue, width = 2)
    IndexOldPivot := IndexNewPivot

The result :
在Pine Script 5中返回PivotHigh的bar_index是否可能?

huangapple
  • 本文由 发表于 2023年4月17日 18:34:50
  • 转载请务必保留本文链接:https://go.coder-hub.com/76034218.html
匿名

发表评论

匿名网友

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

确定