request.security daily close on a 15 minute chart: when the backtest sees the future
Posted: Sat Oct 24, 2026 7:56 pm
request.security daily close on a 15 minute chart: when the backtest sees the future
Here is a Pine mistake that makes strategies look much better than they are. You want yesterday's daily close on a 15 minute chart, so you write request.security(syminfo.tickerid, "D", close, lookahead = barmerge.lookahead_on).
With lookahead on, each historical 15 minute bar is given the daily close of the day it belongs to. At 08:00 on a past day, the script already knows where that day finished.
Say price at 08:00 is 1.0874 and the day ends at 1.0912. A rule such as "go long when price is below the daily close" fires at 08:00, and it was right, because the future was in the data. The backtest shows a clean edge. Live, the close of the current day is not known until it arrives, so the same rule sees a moving number and the edge disappears. On the chart nothing looks wrong, because the historical bars just show a line.
The usual fix is to ask for the previous bar's value inside the call: request.security(syminfo.tickerid, "D", close[1], lookahead = barmerge.lookahead_on). The [1] has to be inside the function, as an argument, and not added after it. That returns the last finished daily close on historical and live bars alike.
Here is a Pine mistake that makes strategies look much better than they are. You want yesterday's daily close on a 15 minute chart, so you write request.security(syminfo.tickerid, "D", close, lookahead = barmerge.lookahead_on).
With lookahead on, each historical 15 minute bar is given the daily close of the day it belongs to. At 08:00 on a past day, the script already knows where that day finished.
Say price at 08:00 is 1.0874 and the day ends at 1.0912. A rule such as "go long when price is below the daily close" fires at 08:00, and it was right, because the future was in the data. The backtest shows a clean edge. Live, the close of the current day is not known until it arrives, so the same rule sees a moving number and the edge disappears. On the chart nothing looks wrong, because the historical bars just show a line.
The usual fix is to ask for the previous bar's value inside the call: request.security(syminfo.tickerid, "D", close[1], lookahead = barmerge.lookahead_on). The [1] has to be inside the function, as an argument, and not added after it. That returns the last finished daily close on historical and live bars alike.