Skip to content

Honor a timezone passed in the session slot of 2-arg time()/time_close()#66

Merged
luisleo526 merged 1 commit into
mainfrom
fix/time-session-timezone-arg
Jul 5, 2026
Merged

Honor a timezone passed in the session slot of 2-arg time()/time_close()#66
luisleo526 merged 1 commit into
mainfrom
fix/time-session-timezone-arg

Conversation

@luisleo526

Copy link
Copy Markdown
Collaborator

Bug (generic)

Pine scripts commonly write time("D", "America/New_York") — a 2-argument call whose second string binds to the session parameter but is meant as a timezone (a day-change in that zone). TradingView honors this idiom. The engine treated "America/New_York" as a session window, matched no HHMM-HHMM window, and returned na for every bar — so ta.change(time(...)) never fired and any per-day reset keyed on it never triggered (e.g. an ORB strategy trades once on day 1, then never resets for the rest of the backtest).

Fix

resolve_session_tz() / session_arg_is_timezone() in src/session_time.cpp: when no explicit tz was supplied and the session slot holds an unambiguous timezone (contains /, or starts with GMT/UTC), reinterpret it as the timezone with no session filter. A real session window ("0930-1600") never contains / nor starts with GMT/UTC, and a 3-arg call supplies tz_in, so legitimate session usage is untouched.

Tests

4 cases added to tests/test_session_time.cpp: equivalence to the 3-arg form, daily-change, real-2-arg-session guard, GMT/UTC recognition.

Gate (R7, fresh context)

  • Anti-cheat diff: exactly 2 files (fix + tests).
  • ctest: 79/79 pass (incl. the new cases).
  • Corpus gate: 239/12/0/0/0/1 over 252 — identical to baseline, zero tier changes (no corpus strategy uses the pattern; neutral as expected).
  • Scraper: a time("D",tz) ORB strategy went 1 → 98 trades (58/104 matched, px 100%); a sibling using the 3-arg form stayed 104/104 (untouched); a session strategy showed no regression.

🤖 Generated with Claude Code

Pine scripts commonly write time("D", "America/New_York") — a 2-argument
call whose second string binds to the `session` parameter but is meant as a
TIMEZONE (a day-change in that zone). TradingView honors this idiom. The
engine treated "America/New_York" as a session window, matched no HHMM-HHMM
window, and returned na for every bar, so ta.change(time(...)) never fired
and any per-day reset keyed on it never triggered.

Add resolve_session_tz(): when no explicit timezone was supplied and the
session slot holds an unambiguous timezone (IANA "Area/Location" or a
GMT/UTC specifier), reinterpret it as the timezone with no session filter.
A real session window never contains '/' nor starts with GMT/UTC, and a
3-arg call supplies tz_in, so legitimate session usage is unaffected.

Adds tz-in-session-slot cases to tests/test_session_time.cpp (equivalence to
the 3-arg form, daily change, real-session guard, GMT recognition).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@luisleo526 luisleo526 merged commit a0e211a into main Jul 5, 2026
5 checks passed
@luisleo526 luisleo526 deleted the fix/time-session-timezone-arg branch July 5, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant