英文:
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 > EMA5 and open > EMA5) or (close < EMA5 and open < 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 > EMA5 and open > EMA5) or (close < EMA5 and open < EMA5)
bars_since_cond = ta.barssince(cond)
was_cond_true = (bars_since_cond < 10)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论