@princeclaw You will need a loop dearching for those past candle ID values in the past. Candle IDs are dynamic. This means they cannot be stored into a variable. This thread will be helpful for what you need:

https://fxdreema.com/forum/topic/10774/is-there-any-way-to-store-rsi-value-when-a-candle-closes-at-its-high-or-low-and/7