What is valuewhen in Pine Script?
ta.valuewhen is a Pine Script function that returns a value from a historical bar where a specified condition was true. It acts as market memory for your scripts. Instead of watching price move in real time and guessing what happened last time something similar occurred, you capture the exact number and use it.
I spent last month backtesting a golden cross strategy on AAPL. Without valuewhen, I had to scroll around the chart manually, trying to remember what the RSI was reading when each cross happened. With it, I pulled those values in seconds. That single function changed how I build indicators.

