PineForge unreleased
Deterministic PineScript v6 backtest runtime — C ABI reference
Loading...
Searching...
No Matches
magnifier_intrabars.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <pineforge/bar.hpp>
5
6#include <memory>
7#include <string>
8#include <string_view>
9#include <vector>
10
11namespace pineforge::source {
12
13/// The intrabar timeframe TradingView's bar magnifier walks on a chart of
14/// `chart_tf`, from the table in TradingView's help centre ("What is bar
15/// magnifier backtesting mode"), each row covering the chart timeframes from
16/// it up to the next one: below 30S 1S, 30S 5S, 1 10S, 5 30S, 10 1, 15 2,
17/// 30 5, 60 10, 240 30, 1D 60, 3D 240, 1W and up 1D. Empty for a literal that
18/// does not parse. the TradingView intrabar import measured every row the population
19/// uses against TradingView's own request.security_lower_tf bars and
20/// magnified tapes (tests/fixtures/magnifier_intrabars).
21std::string tradingview_intrabar_timeframe(std::string_view chart_tf);
22
23/// The lower-timeframe path TradingView's bar magnifier walks for every chart
24/// bar of a run whose chart bars are aggregated from `bars` (input timeframe
25/// `input_tf`, chart timeframe `script_tf`, the symbol's `session` in
26/// `timezone`), as bars for IntrabarPath::lower_tf on the input's own grid.
27///
28/// TradingView's intrabars are the symbol's regular bars at the table's
29/// timeframe. Fixed slots count from the session open except on `1800-1700`,
30/// which counts from 17:00 but trades from 18:00, and `0930-1200,1300-1600`,
31/// which counts from 09:00 but opens its first bar at 09:30. Slots are cut at
32/// the session close and owned by the chart bar that holds their LAST minute,
33/// so on a 15-minute chart a 2-minute intrabar across a boundary belongs to the later
34/// bar. A chart bar's path is its own open, its owned intrabars (each open a
35/// discrete point, then its extremes and close), then its own close. Here
36/// that is:
37/// - a one-price bar at the chart bar's open, stamped at its first input,
38/// when its first intrabar starts before it (the straddler);
39/// - each owned intrabar, stamped at its first input bar -- the straddler
40/// one millisecond after the open bar, inside the chart bar that owns it;
41/// - a one-price bar at the chart bar's close, stamped at its last input,
42/// when its last input belongs to a later chart bar's intrabar.
43///
44/// The input bars come back unchanged when the table's intrabar is the input
45/// timeframe itself (a 10-minute chart on 1-minute bars), cannot be built
46/// from it (a 1- or 5-minute chart needs 10- or 30-second bars), or when a
47/// bar's calendar interval cannot be resolved.
48std::vector<Bar> tradingview_magnifier_bars(const Bar* bars, int n,
49 const std::string& input_tf,
50 const std::string& script_tf,
51 const std::string& session,
52 const std::string& timezone);
53
54/// The same logical path without retaining the input or a whole-run path.
55/// Input stays immutable and alive through the consumer's public run exit.
56/// Construction decides whole-input fallback and caches count; whole walks
57/// have independent cursors, and segment storage survives all const reads.
58std::unique_ptr<NativeLowerPathSource> make_magnifier_path_source(
59 const Bar* bars, int n, const std::string& input_tf,
60 const std::string& script_tf, const std::string& session,
61 const std::string& timezone);
62
63} // namespace pineforge::source
std::unique_ptr< NativeLowerPathSource > make_magnifier_path_source(const Bar *bars, int n, const std::string &input_tf, const std::string &script_tf, const std::string &session, const std::string &timezone)
The same logical path without retaining the input or a whole-run path.
std::vector< Bar > tradingview_magnifier_bars(const Bar *bars, int n, const std::string &input_tf, const std::string &script_tf, const std::string &session, const std::string &timezone)
The lower-timeframe path TradingView's bar magnifier walks for every chart bar of a run whose chart b...
std::string tradingview_intrabar_timeframe(std::string_view chart_tf)
The intrabar timeframe TradingView's bar magnifier walks on a chart of chart_tf, from the table in Tr...