简体   繁体   中英

Check if the past candles are the same type in PineScript

I am trying to check if the past n candles are of the same type.

For example, are all five previous candles bullish, or are they all bearish.

With my approach, I keep getting an error:

lines 30:37: Return type of one of the 'if' blocks is not compatible with return type of other block(s) (void; series[bool]; series[bool])

What am I getting wrong in my iteration?

Thank you all in advance.

I am also willing to try out any other working approach/ ideas.

// Determine if we have a valid setup
isBullish = true
isBearish = true

for i = (iterationCount - 1) to 0
    notSeries = not(isBullish or isBearish)

    if notSeries
        break
    else if close[i] > open[i] and isBullish
        isBearish := false
    else 
        isBullish := false

Not sure why it throws that error, because even if you put isBearish:= false before the break , the error persists, even though every path in the if statement returns a bool .

I'd write it like this, because you don't need the break for the evaluation of your isBullish and isBearish . You only need the break to stop your for loop.

for i = (iterationCount - 1) to 0
    notSeries = not(isBullish or isBearish)

    if notSeries
        break

    if close[i] > open[i] and isBullish
        isBearish := false
    else 
        isBullish := false

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM