获取低于当前条低的第一个栏的bar_index
为了找到分歧,我正在尝试获得第一个栏的bar_index,该栏的低点低于当前栏的低点。
我希望我可以将当前的条值注入ta.valuewhen()
的条件字段,但这是不可能的。
我可以为循环使用,但这是地狱般的慢速,在所有蜡烛上迭代,这不是必需的,因为我想检查第一个较低的枢轴,而不是所有蜡烛都是枢轴。
使用ta.valuewhen(条件,源,出现)
在循环内部,并在出现字段中迭代脚本本身。
例如:
prevPivLL = na
prevPivLLI = na
// Looking back 5 pivot lows for a lower low than current low
for i = 0 to 5
prevPivotLo = ta.valuewhen(na(pivotLo), pivotLo, i)
prevPivLL := pivotLo > prevPivotLo ? pivotLo : na
prevPivLLI := bar_index - ta.valuewhen(na(pivotLo), bar_index, i)
那么,还有什么呢?有更好的方法吗?
我可能已经看到所有其他寻求差异的脚本,看看当前的低点是否高于前面的脚本。问题是,当前低点可以是先前的枢轴,但仍然是较高的枢轴的枢轴。我想检查第一个下部枢轴,即使两者之间有更高的枢轴。之后,我停止看(因为那时它变得无关紧要)。
顺便说一句,也是如此。
这与大多数脚本所做的事情有点倒退,但可能更准确。
To find divergences I'm trying to get the bar_index of the first bar that has a lower low than the low of the current bar.
I wish I could inject current bar values into the condition field of ta.valuewhen()
but this is not possible.
I could use a for
loop, but this is slow as hell and iterating over ALL candles, which is not necessary because I want to check the first lower pivot and not all candles are pivots.
Using ta.valuewhen(condition, source, occurrence)
inside a for
loop and iterate with the occurrence field is discouraged by the script itself.
Eg:
prevPivLL = na
prevPivLLI = na
// Looking back 5 pivot lows for a lower low than current low
for i = 0 to 5
prevPivotLo = ta.valuewhen(na(pivotLo), pivotLo, i)
prevPivLL := pivotLo > prevPivotLo ? pivotLo : na
prevPivLLI := bar_index - ta.valuewhen(na(pivotLo), bar_index, i)
So, what else then? Is there a better approach to this?
I have seen probably all other scripts that look for divergence, look if the current low is higher than the previous one. The thing is that the current low can be a lower one with the previous pivot, but still a higher one with a earlier pivot. I want to check against the first lower pivot, even if there are higher ones in between. After that, i stop looking (because it becomes irrelevant then).
Same goes for close btw.
This is kinda backwards from what most scripts do, but probably way more accurate.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在发生时使用数组来存储枢轴及其相应的条形指数。然后,您只需要迭代一小部分枢轴值即可进行评估。
但是,您需要限制历史搜索,枢轴的数量和/或通过条形回溯限制。
You can use arrays to store the pivots and their corresponding bar indices as they occur. Then you only need to iterate through a small array of pivot values to do the evaluation.
You'll need to limit the historical search though, by the number of pivots and/or by a bar lookback limit.