如何检查条件是否符合最后10根蜡烛/条的情况?

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

How can I check if the condition is true in terms of the last 10 candles/bars?

问题

我想检查最近的10个蜡烛,并查看是否有任何情况下条件为真。

for i = 1 to 10
    if (close > EMA5 and open > EMA5) or (close < EMA5 and open < EMA5))
        checkema5 == true
    else 
        checkema5 == false
英文:

Could you please help me with the following?

I want the check the last 10 candles here and see if the condition is true in any cases.

for i = 1 to 10
    if (close &gt; EMA5 and open &gt; EMA5) or (close &lt; EMA5 and open &lt; EMA5))
        checkema5 == true
    else 
        checkema5 == false

</details>


# 答案1
**得分**: 1

不需要循环。编写您的条件,然后使用`ta.barssince`函数,并检查它是否返回小于10。

> 计算自上次条件为真以来的柱数。

```python
cond = (close > EMA5 and open > EMA5) or (close < EMA5 and open < EMA5)
bars_since_cond = ta.barssince(cond)
was_cond_true = (bars_since_cond < 10)
英文:

No need for a loop. Write your condition and then use the ta.barssince function and check if it returns less than 10.

> Counts the number of bars since the last time the condition was true.

cond = (close &gt; EMA5 and open &gt; EMA5) or (close &lt; EMA5 and open &lt; EMA5)
bars_since_cond = ta.barssince(cond)
was_cond_true = (bars_since_cond &lt; 10)

huangapple
  • 本文由 发表于 2023年3月4日 06:42:37
  • 转载请务必保留本文链接:https://go.coder-hub.com/75632449.html
匿名

发表评论

匿名网友

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

确定