Skip to content
All library documents

Pine Script Higher-Timeframe Data and Repainting Behavior

Article TradingView scripts

Summary

This Pine Script reference explains how security() requests higher-timeframe data and why its values can differ between historical and live bars. It compares a basic call, a bar-state-based wrapper with repainting control, a tuple-returning technique, a two-call alternative, and two discouraged approaches. It also includes a timeframe check and reminder for users who select a timeframe below the chart’s.

The examples illustrate the timing offsets used to align requested values across bar states, and the text stresses that chart histories are models of market activity rather than perfect records of live behavior. The publication’s original recommendation for its wrapper has since been explicitly withdrawn: the note says bar-state-based non-repainting methods have inconsistencies and are no longer endorsed as a universal solution. Treat the code as a historical explanation, not current best practice; consult the referenced updated guidance before implementing higher-timeframe requests.

Key ideas

  • A basic higher-timeframe request can change while its source bar is still forming, so historical plots may not match live behavior.
  • The script demonstrates repainting controls using offsets and compares single-call, tuple, and two-call patterns.
  • Some apparently simple offset combinations can produce misleading differences between historical and realtime bars.
  • A timeframe check can warn when the requested timeframe is below the chart timeframe.
  • The publication withdraws its original bar-state-based recommendation because of inconsistencies.

Tags

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.