OPEN-SOURCE SCRIPT

NY 4H Range - Hayder

2 605
NY First 4H Candle Range
Overview

This indicator marks the high and low of the first 4-hour candle of the New York trading day and projects that range across the remainder of the session as a reference zone.

What makes it different

Most session-range scripts read the 4H candle directly with `request.security()`, which breaks or misaligns when the chart timeframe is 4H or higher, and which depends on the data feed's own session alignment. This script instead reconstructs the range from lower-timeframe data, so the same values are produced regardless of the chart's timeframe.

Method

1. Trading day anchor at 17:00 New York. The script defines the trading day as starting at 17:00 America/New_York, not at midnight. This follows the standard forex/futures rollover rather than the calendar day. The first 4-hour candle therefore spans 17:00 to 21:00 New York time.

2. DST handling without fixed offsets. The `f_tradeDayStart()` function derives the day boundary by decomposing the current bar's timestamp into New York year/month/day/hour components, deciding whether the bar belongs to the current or previous trading day based on whether the New York hour is at or past 17:00, and rebuilding the anchor with `timestamp()` in the New York timezone. Because the timestamp is rebuilt from calendar components rather than by subtracting a constant offset, daylight saving transitions are handled automatically.

3. Lower-timeframe reconstruction. Rather than requesting the 4H candle, the script pulls arrays of time, time_close, high, and low from a configurable internal timeframe (default 15m) using `request.security_lower_tf()`. It then iterates those intrabar values and accumulates the running high and low of every bar whose open time is at or after the trading day anchor and whose close time falls at or before the anchor plus four hours. This means the range is computed from actual price data inside the window rather than from a pre-aggregated candle, and it remains correct on 4H and higher charts where a standard security call would fail.

4. Single confirmed draw, no repaint. The box and boundary lines are created only once the chart's own bar close has passed the end of the 4H window, and a state flag prevents any redraw for that trading day. Nothing is plotted while the window is still forming, and the levels never shift after they appear.

5. Projection. The range is drawn from the trading day anchor forward to anchor plus 24 hours, covering the full trading day. Each new trading day resets the accumulators and draws a fresh range.

Inputs

- Internal Calculation Timeframe (default 15m): the resolution used to reconstruct the 4H window. Lower values give a more precise range at the cost of more data; must be lower than the chart timeframe.

How to use it

The 17:00–21:00 New York window covers the futures reopen and the early Asian handoff, a period that frequently establishes the initial liquidity boundaries traders reference through the rest of the day. Watch for acceptance outside the boundary, rejection back inside, or consolidation within it. The script does not interpret this behavior for you.

Limitations

- Does not generate buy or sell signals, entries, exits, or alerts.
- The internal calculation timeframe must be lower than the chart timeframe; `request.security_lower_tf()` returns no data otherwise.
- Nothing is drawn until the chart's bar close passes 21:00 New York for that trading day.
- Intrabar data availability is limited by your TradingView plan's historical intrabar depth, which caps how far back ranges are drawn.
- Symbols with gaps or missing data inside the 17:00–21:00 window will produce a range built from whatever bars exist.
- A visual reference only, to be used as one component of a complete trading plan.


면책사항

해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.