英文:
Count bars lower since new highest high
问题
我尝试实现的是一个Pine脚本,它会计算在潜在的突破后,有多少根柱子的最高价低于新的最高价。
//@version=5
indicator('Test')
len = input(20)
threshold = 0.01
upper = ta.highest(high, len)
u = ta.barssince(close > (upper+threshold))
plot(u)
<details>
<summary>英文:</summary>
What I am trying to accomplish is a Pine Script that count how many bars back are inferior to the new highest high since an eventual break-out.
//@version=5
indicator('Test')
len = input(20)
threshold = 0.01
upper = ta.highest(high, len)
u = ta.barssince(close > (upper+threshold))
plot(u)
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/Hcm6A.png
</details>
# 答案1
**得分**: 0
以下是翻译好的代码部分:
```plaintext
你可以像这样做。你可能想要添加一个变量,如果在一定数量的天数内没有达到新的高点,那么只需取最近的高点,以防股票远离了它以前的高点。
indicator("我的脚本", overlay=true)
var float highest = 0.0
var int highIndex = 0
var barsincehigh = 0
if close > highest
highest := high
highIndex := bar_index
barsincehigh := 0
else
barsincehigh += 1
if highest > highest[1] and barsincehigh[1] > 1
label.new(bar_index, high, str.tostring(barsincehigh[1]), color=color.lime)
希望这能对你有所帮助。如果需要进一步的解释或帮助,请告诉我。
英文:
You can do something like this. You may want to add a variable that if a new high isn't reached after a certain number of days to just take the most recent high in case a stock is well off it's previous highs.
indicator("My script", overlay = true)
var float highest = 0.0
var int highIndex = 0
var barsincehigh = 0
if close > highest
highest := high
highIndex := bar_index
barsincehigh := 0
else
barsincehigh += 1
if highest > highest[1] and barsincehigh[1] > 1
label.new(bar_index, high, str.tostring(barsincehigh[1]), color = color.lime)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论