柱形索引上的 Pine 脚本循环
Pine script loop on bar index
我想检查过去 n
个柱的条件。
因此,如果我想针对特定数字执行此操作,我将使用类似的方法,最后 5 根柱线:
cond = close > open
conditions = cond and cond[1] and cond[2] and cond[3] and cond[4] and cond[5]
但我需要在一个函数中使用这个方法(用于返回自定义柱索引号)
我的意思是这样的:
check(condition,length)=>
for i = 1 to length
condition[bar_index] and condition[bar_index+i]
所以我可以像这样使用它:
check(close>open,5)
我希望答案是对还是错。
我已经尝试了很多循环,但我找不到我需要的那个。
请告诉我如何在 for
循环的函数中使用它。
//@version=4
study("Help (check)")
check(_condition,_length) =>
_check = true
for i = 0 to _length
_check := _check and _condition[i]
cond = close > open
conditions = cond and cond[1] and cond[2] and cond[3] and cond[4] and cond[5]
//bgcolor(conditions ? color.black : na)
bgcolor(check(cond,5) ? color.blue : na)
无处记录,内联示例:
close[ta.barssince(time < timestamp("2021-11-07T14:30:00"))]
我想检查过去 n
个柱的条件。
因此,如果我想针对特定数字执行此操作,我将使用类似的方法,最后 5 根柱线:
cond = close > open
conditions = cond and cond[1] and cond[2] and cond[3] and cond[4] and cond[5]
但我需要在一个函数中使用这个方法(用于返回自定义柱索引号)
我的意思是这样的:
check(condition,length)=>
for i = 1 to length
condition[bar_index] and condition[bar_index+i]
所以我可以像这样使用它:
check(close>open,5)
我希望答案是对还是错。
我已经尝试了很多循环,但我找不到我需要的那个。
请告诉我如何在 for
循环的函数中使用它。
//@version=4
study("Help (check)")
check(_condition,_length) =>
_check = true
for i = 0 to _length
_check := _check and _condition[i]
cond = close > open
conditions = cond and cond[1] and cond[2] and cond[3] and cond[4] and cond[5]
//bgcolor(conditions ? color.black : na)
bgcolor(check(cond,5) ? color.blue : na)
无处记录,内联示例:
close[ta.barssince(time < timestamp("2021-11-07T14:30:00"))]