计数自最新最高点以来较低的柱形图。

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

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(&quot;My script&quot;, overlay = true)

var float highest = 0.0
var int highIndex = 0
var barsincehigh = 0 

if close &gt; highest 
    highest := high
    highIndex := bar_index
    barsincehigh := 0
else
    barsincehigh += 1 

if highest &gt; highest[1] and barsincehigh[1] &gt; 1
    label.new(bar_index, high, str.tostring(barsincehigh[1]), color = color.lime)

计数自最新最高点以来较低的柱形图。

huangapple
  • 本文由 发表于 2023年5月15日 03:44:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76249387.html
匿名

发表评论

匿名网友

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

确定