Skip to content

Commit 72ae4f1

Browse files
luisleo526claude
andcommitted
fix: time(<intraday tf>) and time("D") on the symbol day-stamp grid
TradingView keys time("<intraday tf>") / time_close on the symbol's DAY-STAMP-anchored HTF grid -- the grid 88cd0c8 gave request.security's ratio buckets -- on every session symbol, and on the epoch grid only where the stamp is 00:00 UTC; time("D") on OANDA's 1800-1700 session is the 17:00 ET stamp the D bar opens on, not the 18:00 ET session open, and time_close("D") the next stamp. Pinned with `lab tv` (pin-time-hours: strategy.entry(qty = hour(time(tf), "America/New_York") * 100 + minute(...) + 10000 / 20000 / 30000 for "D" / "240" / "60"), 15m charts, 2025-04-01..07-01): OANDA:XAUUSD 1800-1700 ET: "D" = 17:00 on 147/147 entries (the engine reported 18:00); "240" in {01:00, 05:00, 09:00, 13:00, 17:00, 21:00}; "60" every hour on the hour except 17:00; NYSE:F 0930-1600 ET: "D" = 09:30; "60" in {09:30, 10:30, .., 15:30} -- session-anchored, not the epoch hour the engine reported; "240" in {09:30, 13:30}; NSE:NIFTY 0915-1530 IST: "D" = 23:45 NY (09:15 IST); "240" in {23:45, 03:45} NY (09:15 / 13:15 IST); BINANCE:BTCUSDT 24x7 UTC: "D" = 20:00 NY (00:00 UTC), epoch grid. CME_MINI:ES1! exported 0 rows: its request.security "240" grid (17:00 CT anchored) is pinned unchanged and time("240") reads it. One grid, one place: session_intraday_bucket_open_ms (timeframe.cpp) is the RATIO bucket of TimeframeAggregator::bucket_open_ms and the intraday path of compute_tf_open_ms (session_time.cpp), which now takes the symbol's tz/session from the seven-argument pine_time / pine_time_close forms; the five-argument forms pass UTC / "" and stay on the epoch grid bit-for-bit. session_period_open_ms opens the D/W/M bar on its first session-day's stamp (session_day_stamp_real_ms) and W/M close on the next period's stamp; the DAY close (open + length = the next stamp) and session_day_open_real_ms -- the trading open that session_covered_instant_ms and the close arithmetic use -- are unchanged. The aux daily-bar router keys both sides through session_period_open_ms, so its keys move together; the range-start bucket cut now keys the 1800-1700 D bucket on the stamp, which is where TradingView's D bar opens. Every session whose open is its stamp (OANDA 1700-1700, CME 1700-1600 CT, NYSE, NSE, 24x7) is bit-identical for D/W/M; their intraday time(tf) moves from the epoch grid to the session grid, as the tapes read. Re-pins, disclosed: - tests/test_session_day_anchors "Intraday tfs keep the epoch grid" arrived with b1449c3 (factorial: engine-symbol-r5, #162) as a design statement with no tape behind it; its "60" check on OANDA:EURUSD 1700-1700 never told the grids apart (17:00 ET is on the hour) and still holds; "240" is now pinned to the 17:00-ET grid. - tests/test_session_day_anchors "CME-style 1800-1700" (b1449c3, a session-length parser edge case written in the New York zone) is OANDA's metals session: its D / W open re-pinned to the stamp, the close unchanged. A real CME session (1700-1600 Chicago) is pinned with open == stamp. - tests/test_oanda_day_stamp_grid rule D (88cd0c8's design pin: the 1800-1700 D/W/M open and D label at the 18:00 session open) now reads the 17:00 stamp; the W/M open follows the D bar (the same relation 1700-1700 has) -- extrapolated, no W/M tape. tests/test_pine_time_day_stamp_grid pins the four tapes and the CME regression grid (92 checks). ctest 154/154 (153 + the new binary; test_oanda_day_stamp_grid 692, test_session_day_anchors 23853); scripts unittest 102 OK; check_c_abi_runtime.py clean. Against the previous library 53 / 18 / 4 of those checks fail respectively. Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_01Dwbd239WT9zfcTLYM5UpUU
1 parent 88cd0c8 commit 72ae4f1

8 files changed

Lines changed: 584 additions & 84 deletions

‎include/pineforge/session_time.hpp‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,13 @@ int64_t pine_time_close(int64_t bar_ms,
5555
// (TradingView rolls `time("D", "0000-2359", "America/New_York")` at New
5656
// York midnight on a UTC symbol — measured), and its window is read in the
5757
// explicit `tz`, else `sym_tz` (the syminfo default above), else UTC.
58-
// Intraday tfs are unchanged.
58+
// An intraday `tf` (with or without a session argument, which only
59+
// filters) is the symbol's day-stamp-anchored HTF grid bucket
60+
// (session_intraday_bucket_open_ms in timeframe.hpp — the grid
61+
// request.security aggregates on): time("60") on NYSE:F is 09:30 / 10:30 /
62+
// .. / 15:30 ET, time("240") on NSE:NIFTY 09:15 / 13:15 IST and on
63+
// OANDA:XAUUSD the 17:00-ET-anchored 4h grid (pin-time-hours tapes,
64+
// 2025-04-01..07-01); the five-argument forms stay on the epoch grid.
5965
// With sym_tz="UTC" and an empty / "24x7" sym_session these are
6066
// bit-identical to the five-argument forms above.
6167
//

‎include/pineforge/timeframe.hpp‎

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,12 @@ bool tf_change(int64_t prev_ms, int64_t curr_ms, const std::string& tf,
110110
// Every chart-level consumer of "the symbol's daily bar" — ta.vwap's default
111111
// anchor, timeframe.change("1D"), time("D")/time_close("D") — has to key on
112112
// this clock, the same one request.security aggregation already uses
113-
// (crosses_boundary / session_period_key above). With tz="UTC" and an
114-
// empty / "24x7" session all of these reduce to plain epoch integer math,
113+
// (crosses_boundary / session_period_key above). The bar OPENS at the
114+
// session-day's DAY STAMP — the session open on every session but OANDA's
115+
// 1800-1700, whose D bar is stamped 17:00 ET an hour before it trades
116+
// (time("D") reads 17:00 ET on OANDA:XAUUSD, pin-time-hours; the session
117+
// open stays where the tape trades from). With tz="UTC" and an empty /
118+
// "24x7" session all of these reduce to plain epoch integer math,
115119
// bit-identical to the UTC forms the corpus pins.
116120
//
117121
// Period attribution follows TV's trading-date rule: a session that wraps
@@ -128,12 +132,27 @@ bool tf_change(int64_t prev_ms, int64_t curr_ms, const std::string& tf,
128132
int64_t session_day_index(int64_t ms, const std::string& tz,
129133
const std::string& session);
130134

131-
/// Open (Unix ms) of the symbol's D/W/M bar that contains `ms`.
132-
/// CalendarPeriod::NONE returns `ms` unchanged.
135+
/// Open (Unix ms) of the symbol's D/W/M bar that contains `ms`: the day
136+
/// stamp of the period's first session-day (17:00 ET on OANDA 1800-1700,
137+
/// the session open elsewhere). CalendarPeriod::NONE returns `ms` unchanged.
133138
int64_t session_period_open_ms(int64_t ms, const std::string& tz,
134139
const std::string& session,
135140
CalendarPeriod period);
136141

142+
/// Open (Unix ms) of the `bucket_sec`-wide intraday bucket that contains
143+
/// `ms` on the symbol's day-stamp-anchored grid: exchange-tz time since
144+
/// local midnight + day stamp, floored to the bucket width. This is THE
145+
/// intraday HTF grid — request.security's ratio buckets
146+
/// (TimeframeAggregator::bucket_open_ms), tf_change and
147+
/// time("<intraday tf>") / time_close all read it (pin-time-hours:
148+
/// time("60") on NYSE:F is 09:30 / 10:30 / .. / 15:30 ET, time("240") on
149+
/// NSE:NIFTY 09:15 / 13:15 IST, on OANDA:XAUUSD 17:00 ET + 4h*k). With
150+
/// tz="UTC" and session ""/"24x7" it is the epoch grid, bit-identical to
151+
/// the tz-less forms. bucket_sec <= 0 returns `ms`.
152+
int64_t session_intraday_bucket_open_ms(int64_t ms, int64_t bucket_sec,
153+
const std::string& tz,
154+
const std::string& session);
155+
137156
/// The session instant a native CALENDAR chart stamp covers. A stamp inside
138157
/// its session (open to exclusive close) returns unchanged. A stamp in the
139158
/// inter-session gap -- before its session-day's open (the 1800-1700 day
@@ -203,8 +222,9 @@ class TimeframeAggregator {
203222
/// belongs to, on the aggregator's anchor clock (syminfo tz + session):
204223
/// CALENDAR -> session_period_open_ms of the bar's D/W/M period (the
205224
/// forex week opens Sunday 17:00 ET, its month on the session whose
206-
/// close date is the 1st); RATIO -> the session-open-anchored intraday
207-
/// grid bucket (the same key feed() splits on); PASSTHROUGH, or a
225+
/// close date is the 1st); RATIO -> session_intraday_bucket_open_ms,
226+
/// the day-stamp-anchored grid bucket (the same key feed() splits on
227+
/// and time("<intraday tf>") reads); PASSTHROUGH, or a
208228
/// count-only ratio with no wall-clock width, -> `ms` itself. Pure
209229
/// function of the configuration: it neither reads nor advances the
210230
/// aggregation state, so callers may query it before feeding the bar.
@@ -215,11 +235,13 @@ class TimeframeAggregator {
215235
/// on every bucket it starts (finding 473). RATIO -> bucket_open_ms
216236
/// (the session-anchored grid open, whether or not the grid-opening
217237
/// sub-bar traded: a forex 1m tape that starts at 17:04 ET still yields
218-
/// the 17:00 chart bar); CALENDAR -> the open of the session-day holding
219-
/// `ms` (the D/W/M bar is dated by its first TRADED session-day, so a
220-
/// holiday-Monday week stays Tuesday's bar, but never by a thin-open
221-
/// sub-bar inside that day); PASSTHROUGH -> `ms`. Gap-free feeds are
222-
/// bit-identical: there the first sub-bar IS the bucket open.
238+
/// the 17:00 chart bar); CALENDAR -> the day stamp of the session-day
239+
/// holding `ms` (the D/W/M bar is dated by its first TRADED session-day,
240+
/// so a holiday-Monday week stays Tuesday's bar, but never by a
241+
/// thin-open sub-bar inside that day; on OANDA 1800-1700 the stamp is
242+
/// 17:00 ET, an hour before the day trades); PASSTHROUGH -> `ms`.
243+
/// Gap-free feeds whose open is the stamp are bit-identical: there the
244+
/// first sub-bar IS the bucket open.
223245
int64_t bar_label_ms(int64_t ms) const;
224246

225247
private:

‎src/session_time.cpp‎

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -159,18 +159,6 @@ static bool minute_in_window(int mod, int start, int end) {
159159
return mod >= start || mod < end;
160160
}
161161

162-
static int64_t utc_bucket_open_ms(int64_t bar_ms, int period_sec) {
163-
if (period_sec <= 0)
164-
return bar_ms;
165-
int64_t period_ms = static_cast<int64_t>(period_sec) * 1000;
166-
if (bar_ms >= 0)
167-
return (bar_ms / period_ms) * period_ms;
168-
int64_t q = bar_ms / period_ms;
169-
if (bar_ms % period_ms != 0 && bar_ms < 0)
170-
--q;
171-
return q * period_ms;
172-
}
173-
174162
static int64_t calendar_week_open_local_ms_tz(int64_t bar_ms, const std::string& tz);
175163

176164
static int64_t calendar_week_open_local_ms(int64_t bar_ms, const std::string& tz) {
@@ -248,9 +236,15 @@ static int64_t calendar_month_open_local_ms_tz(int64_t bar_ms, const std::string
248236
return static_cast<int64_t>(m0) * 1000;
249237
}
250238

239+
// D/W/M open on the `tz` calendar; an intraday tf on the SYMBOL's
240+
// day-stamp-anchored HTF grid (session_intraday_bucket_open_ms — the grid
241+
// request.security aggregates on), which with sym_tz "UTC" and no
242+
// sym_session is the epoch grid the five-argument forms keep.
251243
static int64_t compute_tf_open_ms(int64_t bar_ms,
252244
const std::string& tf,
253-
const std::string& tz) {
245+
const std::string& tz,
246+
const std::string& sym_tz,
247+
const std::string& sym_session) {
254248
if (tf.empty())
255249
return bar_ms;
256250

@@ -264,7 +258,7 @@ static int64_t compute_tf_open_ms(int64_t bar_ms,
264258

265259
int sec = tf_to_seconds(tf);
266260
if (sec > 0 && sec < kSecPerDay)
267-
return utc_bucket_open_ms(bar_ms, sec);
261+
return session_intraday_bucket_open_ms(bar_ms, sec, sym_tz, sym_session);
268262
return bar_ms;
269263
}
270264

@@ -586,8 +580,9 @@ static bool session_arg_is_timezone(const std::string& s) {
586580
// deliberately left exactly as before: explicit tz argument, else UTC.
587581
// The D/W/M calendar path of compute_tf_open_ms is owned elsewhere and
588582
// must not silently start rolling at syminfo.timezone just because a
589-
// session was supplied; intraday timeframes are UTC-bucketed and never
590-
// depended on tz anyway.
583+
// session was supplied; intraday timeframes sit on the symbol's own
584+
// HTF grid (the seven-argument forms) or the epoch grid (these) and
585+
// never depended on tz.
591586
//
592587
// When a 2-arg call passes a timezone-looking string in the session slot (and
593588
// no explicit tz), TV treats it as an invalid session and ignores it: drop the
@@ -630,7 +625,7 @@ int64_t pine_time(int64_t bar_ms,
630625
if (!sess.empty() && !passes_session_filter(sess, session_tz, bar_ms))
631626
return na<int64_t>();
632627

633-
return compute_tf_open_ms(bar_ms, tf, tf_tz);
628+
return compute_tf_open_ms(bar_ms, tf, tf_tz, "UTC", "");
634629
}
635630

636631
int64_t pine_time_close(int64_t bar_ms,
@@ -649,7 +644,7 @@ int64_t pine_time_close(int64_t bar_ms,
649644
if (!sess.empty() && !passes_session_filter(sess, session_tz, bar_ms))
650645
return na<int64_t>();
651646

652-
int64_t t_open = compute_tf_open_ms(bar_ms, tf, tf_tz);
647+
int64_t t_open = compute_tf_open_ms(bar_ms, tf, tf_tz, "UTC", "");
653648
return compute_tf_close_ms(t_open, tf, tf_tz);
654649
}
655650

@@ -664,7 +659,13 @@ int64_t pine_time_close(int64_t bar_ms,
664659
// roll, 18% with the symbol's UTC roll), so that path keeps the tz-only
665660
// calendar floor of the five-argument forms. A timezone-looking string in the
666661
// session slot is an invalid session (dropped by resolve_session_tz) and
667-
// falls back to the symbol clock. Intraday tfs keep the epoch-grid bucket.
662+
// falls back to the symbol clock. An intraday tf is the symbol's
663+
// day-stamp-anchored HTF grid bucket whatever the session argument (it
664+
// only filters): TradingView's time("60") on NYSE:F 15 is 09:30 / 10:30 /
665+
// .. / 15:30 ET, time("240") on NSE:NIFTY 09:15 / 13:15 IST and on
666+
// OANDA:XAUUSD 17:00 ET + 4h*k, 00:00 UTC + 4h*k only on 24x7 UTC
667+
// (pin-time-hours, 2025-04-01..07-01) — the very grid request.security
668+
// aggregates on (session_intraday_bucket_open_ms), one grid in one place.
668669
static bool symbol_clock_applies(const std::string& resolved_session,
669670
CalendarPeriod cp) {
670671
return cp != CalendarPeriod::NONE && resolved_session.empty();
@@ -694,7 +695,7 @@ int64_t pine_time(int64_t bar_ms,
694695
const CalendarPeriod cp = calendar_period_for(tf);
695696
if (symbol_clock_applies(sess, cp))
696697
return session_period_open_ms(bar_ms, sym_tz, sym_session, cp);
697-
return compute_tf_open_ms(bar_ms, tf, tf_tz);
698+
return compute_tf_open_ms(bar_ms, tf, tf_tz, sym_tz, sym_session);
698699
}
699700

700701
int64_t pine_time_close(int64_t bar_ms,
@@ -720,7 +721,7 @@ int64_t pine_time_close(int64_t bar_ms,
720721
// tz-only forms above; intraday closes stay the exact boundary.
721722
return session_period_close_ms(bar_ms, sym_tz, sym_session, cp) - 1;
722723
}
723-
int64_t t_open = compute_tf_open_ms(bar_ms, tf, tf_tz);
724+
int64_t t_open = compute_tf_open_ms(bar_ms, tf, tf_tz, sym_tz, sym_session);
724725
return compute_tf_close_ms(t_open, tf, tf_tz);
725726
}
726727

‎src/timeframe.cpp‎

Lines changed: 60 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -237,9 +237,14 @@ static int session_length_minutes(const std::string& session);
237237
/// anchor put them at 22:00Z / 02:00Z / ... and 22:00Z / 22:45Z / 23:30Z.
238238
/// Every 3commas-* XAUUSD DCA probe (request.security "240" RSI gate) shows
239239
/// the same 17:00-ET grid on TV against the engine's 18:00-ET one, the DCA
240-
/// legs agreeing to 1e-6 once the grid does. The session OPEN stays the
241-
/// session-day's nominal open (the D bar's label and its close arithmetic,
242-
/// session_day_open_nominal_ms); only the clock moves, and no 1800-1700 bar
240+
/// legs agreeing to 1e-6 once the grid does. The stamp is also where the
241+
/// symbol's D bar OPENS -- time("D") on OANDA:XAUUSD 15 reads 17:00 ET on
242+
/// 147/147 entries of pin-time-hours (2025-04-01..07-01), never the 18:00
243+
/// ET session open -- so session_period_open_ms and the D/W/M bucket label
244+
/// sit on it (session_day_stamp_real_ms). The session OPEN keeps the
245+
/// trading window: session_day_open_real_ms / session_covered_instant_ms
246+
/// (where a native 17:00-stamped bar's content lies) and the close
247+
/// arithmetic (open + length = the next 17:00 stamp). No 1800-1700 bar
243248
/// trades in the 17:00-18:00 hour the two clocks attribute differently.
244249
static int session_day_stamp_offset_minutes(const std::string& session) {
245250
const int open = session_open_offset_minutes(session);
@@ -262,6 +267,19 @@ static int64_t intraday_clock_ms(int64_t ts, const std::string& tz,
262267
- static_cast<int64_t>(session_day_stamp_offset_minutes(session)) * 60000;
263268
}
264269

270+
int64_t session_intraday_bucket_open_ms(int64_t ms, int64_t bucket_sec,
271+
const std::string& tz,
272+
const std::string& session) {
273+
if (bucket_sec <= 0) return ms;
274+
// Floor (not truncate) so the open never lands after `ms` on a negative
275+
// clock; for every real feed the two agree.
276+
const int64_t bucket_ms = bucket_sec * 1000;
277+
const int64_t clock = intraday_clock_ms(ms, tz, session);
278+
int64_t open_clock = (clock / bucket_ms) * bucket_ms;
279+
if (clock < 0 && clock % bucket_ms != 0) open_clock -= bucket_ms;
280+
return ms - (clock - open_clock);
281+
}
282+
265283
/// Minutes from symbol-local midnight to the first session window's CLOSE
266284
/// ("0930-1600..." -> 960). Returns -1 when the session is none/24x7/wrapped
267285
/// (end<=start), in which case eager session-close completion is unavailable
@@ -377,19 +395,34 @@ static int64_t session_day_open_nominal_ms(int64_t d, const std::string& session
377395
+ static_cast<int64_t>(session_open_offset_minutes(session)) * 60000;
378396
}
379397

380-
/// Real epoch of session-day `d`'s open: the nominal wall-clock instant
381-
/// mapped back through the zone offset in force on THAT date (resolved
382-
/// twice so an east-of-UTC zone whose local open lands on the previous UTC
383-
/// date reads its own offset, not the nominal date's).
384-
static int64_t session_day_open_real_ms(int64_t d, const std::string& tz,
385-
const std::string& session) {
386-
const int64_t nominal = session_day_open_nominal_ms(d, session);
398+
/// Real epoch of a nominal wall-clock instant (UTC-encoded local time):
399+
/// mapped back through the zone offset in force at THAT instant (resolved
400+
/// twice so an east-of-UTC zone whose local instant lands on the previous
401+
/// UTC date reads its own offset, not the nominal date's).
402+
static int64_t nominal_to_real_ms(int64_t nominal, const std::string& tz) {
387403
if (is_utc_tz(tz)) return nominal;
388404
int64_t real = nominal + tz_offset_ms(nominal, tz);
389405
real = nominal + tz_offset_ms(real, tz);
390406
return real;
391407
}
392408

409+
/// Real epoch of session-day `d`'s OPEN: the first traded instant.
410+
static int64_t session_day_open_real_ms(int64_t d, const std::string& tz,
411+
const std::string& session) {
412+
return nominal_to_real_ms(session_day_open_nominal_ms(d, session), tz);
413+
}
414+
415+
/// Real epoch of session-day `d`'s DAY STAMP: where the symbol's D bar
416+
/// opens (session_day_stamp_offset_minutes) -- the session open everywhere
417+
/// but 1800-1700, whose bar is stamped 17:00 ET an hour before it trades.
418+
static int64_t session_day_stamp_real_ms(int64_t d, const std::string& tz,
419+
const std::string& session) {
420+
return nominal_to_real_ms(
421+
d * kMsPerDay
422+
+ static_cast<int64_t>(session_day_stamp_offset_minutes(session)) * 60000,
423+
tz);
424+
}
425+
393426
int64_t session_day_index(int64_t ms, const std::string& tz,
394427
const std::string& session) {
395428
return floor_div_day(intraday_clock_ms(ms, tz, session));
@@ -421,9 +454,11 @@ int64_t session_period_open_ms(int64_t ms, const std::string& tz,
421454
const std::string& session,
422455
CalendarPeriod period) {
423456
if (period == CalendarPeriod::NONE) return ms;
457+
// The period's bar opens where its first session-day's D bar does: the
458+
// day stamp (the session open on every session but 1800-1700).
424459
const int64_t d = session_day_index(ms, tz, session);
425-
return session_day_open_real_ms(session_period_first_day(d, session, period),
426-
tz, session);
460+
return session_day_stamp_real_ms(session_period_first_day(d, session, period),
461+
tz, session);
427462
}
428463

429464
/// Epoch day of the first session-day of the W/M period FOLLOWING the one
@@ -476,8 +511,9 @@ int64_t session_period_close_ms(int64_t ms, const std::string& tz,
476511
if (period == CalendarPeriod::NONE) return ms;
477512
const int64_t d = session_day_index(ms, tz, session);
478513
if (period == CalendarPeriod::DAY) return session_day_close_real_ms(d, tz, session);
479-
return session_day_open_real_ms(session_period_next_first_day(d, session, period),
480-
tz, session);
514+
// W/M close on the next period's first D bar open -- its day stamp.
515+
return session_day_stamp_real_ms(session_period_next_first_day(d, session, period),
516+
tz, session);
481517
}
482518

483519
/// True when the run declares a real exchange session (equities RTH, forex
@@ -1046,18 +1082,12 @@ int64_t TimeframeAggregator::bucket_open_ms(int64_t ms) const {
10461082
case Mode::CALENDAR:
10471083
return session_period_open_ms(ms, anchor_tz_, anchor_session_,
10481084
cal_period_);
1049-
case Mode::RATIO: {
1050-
if (target_seconds_ <= 0) return ms; // count-only ratio: no grid
1051-
// Same grid feed_ratio_mode keys on: exchange-tz ms since
1052-
// local-midnight + session-open, floored to the bucket width.
1053-
// Floor (not truncate) so the open never lands after `ms` on a
1054-
// negative clock; for every real feed the two agree.
1055-
const int64_t bucket_ms = target_seconds_ * 1000;
1056-
const int64_t clock = intraday_clock_ms(ms, anchor_tz_, anchor_session_);
1057-
int64_t open_clock = (clock / bucket_ms) * bucket_ms;
1058-
if (clock < 0 && clock % bucket_ms != 0) open_clock -= bucket_ms;
1059-
return ms - (clock - open_clock);
1060-
}
1085+
case Mode::RATIO:
1086+
// Same grid feed_ratio_mode keys on (and time("<intraday tf>")
1087+
// reads): exchange-tz ms since local-midnight + day stamp,
1088+
// floored to the bucket width. Count-only ratio: no grid.
1089+
return session_intraday_bucket_open_ms(ms, target_seconds_,
1090+
anchor_tz_, anchor_session_);
10611091
case Mode::PASSTHROUGH:
10621092
return ms;
10631093
}
@@ -1074,8 +1104,10 @@ int64_t TimeframeAggregator::bar_label_ms(int64_t ms) const {
10741104
// The D/W/M bar is dated by its first TRADED session-day (a
10751105
// holiday-Monday equity week is Tuesday's bar, exactly as the
10761106
// first-present sub-bar already implied), but within that
1077-
// session-day by the session OPEN: the forex daily / weekly bar
1078-
// whose tape starts at 17:04 ET is still the 17:00 ET bar.
1107+
// session-day by the DAY STAMP: the forex daily / weekly bar
1108+
// whose tape starts at 17:04 ET is still the 17:00 ET bar, and
1109+
// the 1800-1700 day that trades from 18:00 ET is its 17:00 ET
1110+
// stamped bar (session_day_stamp_offset_minutes).
10791111
return session_period_open_ms(ms, anchor_tz_, anchor_session_,
10801112
CalendarPeriod::DAY);
10811113
case Mode::PASSTHROUGH:

‎tests/CMakeLists.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ set(TEST_SOURCES
7373
test_chart_bar_bucket_label
7474
test_htf_bucket_real_end
7575
test_oanda_day_stamp_grid
76+
test_pine_time_day_stamp_grid
7677
test_adversarial_ohlcv
7778
test_report_trace
7879
test_path_resolve_extra

0 commit comments

Comments
 (0)