@@ -947,26 +947,48 @@ class VWAP {
947947 // Sum of (price^2 * volume) for running variance computation used by
948948 // compute_bands(). Variance = cum_pv_sq_ / cum_vol_ - mean^2.
949949 double cum_pv_sq_ = 0.0 ;
950- // Anchor day index (Unix-day = timestamp_ms / 86_400_000). On the
951- // first compute() call we record this from the bar timestamp; on
952- // every subsequent compute() the cumulator is reset whenever the
953- // day index advances. Pine v6 `ta.vwap(source)` defaults to a Daily
954- // anchor (`anchor = timeframe.change("1D")`); engine matches that.
950+ // Anchor day index: the SESSION day of the bar (session_day_index —
951+ // timestamp_ms / 86_400_000 on a UTC/24x7 symbol, the 17:00-ET-keyed
952+ // trading day on forex, the 09:30 RTH day on equities). On the first
953+ // compute() call we record this from the bar timestamp; on every
954+ // subsequent compute() the cumulator is reset whenever the day index
955+ // advances. Pine v6 `ta.vwap(source)` defaults to a Daily anchor
956+ // (`anchor = timeframe.change("1D")` on the SYMBOL's daily bar); the
957+ // engine matches that when the codegen threads syminfo tz + session.
955958 int64_t anchor_day_ = std::numeric_limits<int64_t >::min();
956959
957960 // Mirror the initial committed state (see RMA::RMA) so a recompute()
958961 // before the first compute() restores a well-defined pristine state.
959962 double saved_cum_pv_ = 0.0 , saved_cum_vol_ = 0.0 , saved_cum_pv_sq_ = 0.0 ;
960963 int64_t saved_anchor_day_ = std::numeric_limits<int64_t >::min();
961964
965+ void roll_anchor (int64_t day);
966+
962967public:
963968 VWAP () = default;
969+ // tz-less forms key the anchor on the UTC day (the 24x7 corpus regime);
970+ // the tz/session forms key it on the symbol's session day and reduce to
971+ // the same integer math for tz="UTC" + empty/"24x7" session.
972+ // Feature macro PF_VWAP_HAS_SESSION_ANCHOR (below the class) lets
973+ // generated code compile the (tz, session) tail out on older engines.
964974 double compute (double src, double volume, int64_t timestamp_ms);
965975 double recompute (double src, double volume, int64_t timestamp_ms);
976+ double compute (double src, double volume, int64_t timestamp_ms,
977+ const std::string& tz, const std::string& session);
978+ double recompute (double src, double volume, int64_t timestamp_ms,
979+ const std::string& tz, const std::string& session);
966980 VWAPBandsResult compute_bands (double src, double volume, int64_t timestamp_ms, double stdev_mult);
967981 VWAPBandsResult recompute_bands (double src, double volume, int64_t timestamp_ms, double stdev_mult);
982+ VWAPBandsResult compute_bands (double src, double volume, int64_t timestamp_ms, double stdev_mult,
983+ const std::string& tz, const std::string& session);
984+ VWAPBandsResult recompute_bands (double src, double volume, int64_t timestamp_ms, double stdev_mult,
985+ const std::string& tz, const std::string& session);
968986};
969987
988+ // Feature macro: the emitted prelude's PF_VWAP_SESSION_ANCHOR_ARGS(tz, s)
989+ // expands to `, tz, s` only when this is defined (see VWAP overloads above).
990+ #define PF_VWAP_HAS_SESSION_ANCHOR 1
991+
970992// --- VWAP Bands wrapper class (3-tuple form: ta.vwap(src, anchor, stdev_mult)) ---
971993// Wraps VWAP and routes compute/recompute to compute_bands/recompute_bands with
972994// a fixed stdev_mult supplied at construction time. This lets the codegen use
@@ -982,6 +1004,14 @@ class VWAPBands {
9821004 VWAPBandsResult recompute (double src, double volume, int64_t timestamp_ms) {
9831005 return vwap_.recompute_bands (src, volume, timestamp_ms, stdev_mult_);
9841006 }
1007+ VWAPBandsResult compute (double src, double volume, int64_t timestamp_ms,
1008+ const std::string& tz, const std::string& session) {
1009+ return vwap_.compute_bands (src, volume, timestamp_ms, stdev_mult_, tz, session);
1010+ }
1011+ VWAPBandsResult recompute (double src, double volume, int64_t timestamp_ms,
1012+ const std::string& tz, const std::string& session) {
1013+ return vwap_.recompute_bands (src, volume, timestamp_ms, stdev_mult_, tz, session);
1014+ }
9851015};
9861016
9871017// --- Statistical ---
0 commit comments