简体   繁体   中英

Undeclared identifier in Pine loop

I have this code:

// Average penetration

high_pen = for i = 0 to penetration_len

    penetration = high[i] - shortEma[i]
    sum = high_pen + penetration
    high_pen = penetration > 0 ? sum : 0
    high_pen

average_high_pen = high_pen / penetration_len

As you can see, I just want to get all penetration in a bullish trend. The compiler says that high_pen var is not declared in " sum = high_pen + penetration " sentence. It is a very simple loop which it only has to sum the penetration.

How can I do that correctly? How should I declare the high_pen var and use it after the loop?

Can't validate because your snippet is partial, but this should work:

// Average penetration

high_pen = 0.
for i = 0 to penetration_len
    penetration = high[i] - shortEma[i]
    sum = high_pen + penetration
    high_pen := penetration > 0 ? sum : 0

average_high_pen = high_pen / penetration_len

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