Pinescript 如果进入前绿色蜡烛(高 - 低)的长度超过一定长度没有安全性,请勿进入
Pinescript Do not enter if the length of green candles(high - low) before entering is more than certain length without security
我不想进入和图片一样的情况。
CandleSize = abs(high-low)
Length = CandleSize < 30
我想编写代码来满足入场前只适用绿色蜡烛的条件
如果代码能满足前一根蜡烛或最后一根蜡烛的条件就好了
您可以使用 ta.valuewhen()
来达到这个目的。
Returns the value of the source
series on the bar where the
condition
was true on the nth most recent occurrence.
//@version=5
indicator("My script", overlay=true)
is_green = close >= open
cond = (math.abs(high-low)) < 30
last_green = ta.valuewhen(is_green, cond, 0) // If the condition was true on the last green bar
last_green_1 = ta.valuewhen(is_green, cond, 1) // If the condition was true on the second green from the last bar
should_enter = last_green and last_green_1
plotshape(should_enter, size=size.small)
我不想进入和图片一样的情况。
CandleSize = abs(high-low)
Length = CandleSize < 30
我想编写代码来满足入场前只适用绿色蜡烛的条件
如果代码能满足前一根蜡烛或最后一根蜡烛的条件就好了
您可以使用 ta.valuewhen()
来达到这个目的。
Returns the value of the
source
series on the bar where thecondition
was true on the nth most recent occurrence.
//@version=5
indicator("My script", overlay=true)
is_green = close >= open
cond = (math.abs(high-low)) < 30
last_green = ta.valuewhen(is_green, cond, 0) // If the condition was true on the last green bar
last_green_1 = ta.valuewhen(is_green, cond, 1) // If the condition was true on the second green from the last bar
should_enter = last_green and last_green_1
plotshape(should_enter, size=size.small)