英文:
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_index和high的索引。是否可能返回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
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论