Honor a timezone passed in the session slot of 2-arg time()/time_close()#66
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Bug (generic)
Pine scripts commonly write
time("D", "America/New_York")— a 2-argument call whose second string binds to thesessionparameter 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 noHHMM-HHMMwindow, and returnednafor every bar — sota.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()insrc/session_time.cpp: when no explicit tz was supplied and the session slot holds an unambiguous timezone (contains/, or starts withGMT/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 suppliestz_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)
ctest: 79/79 pass (incl. the new cases).239/12/0/0/0/1over 252 — identical to baseline, zero tier changes (no corpus strategy uses the pattern; neutral as expected).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