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. R5 lane MAG-INTRABAR 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: anchored at the session day's open, cut at its close, and each
30/// owned by the chart bar that holds its LAST minute, so on a 15-minute chart
31/// a 2-minute intrabar that straddles a chart boundary belongs to the later
32/// bar. A chart bar's path is its own open, its owned intrabars (each open a
33/// discrete point, then its extremes and close), then its own close. Here
34/// that is:
35/// - a one-price bar at the chart bar's open, stamped at its first input,
36/// when its first intrabar starts before it (the straddler);
37/// - each owned intrabar, stamped at its first input bar -- the straddler
38/// one millisecond after the open bar, inside the chart bar that owns it;
39/// - a one-price bar at the chart bar's close, stamped at its last input,
40/// when its last input belongs to a later chart bar's intrabar.
41///
42/// The input bars come back unchanged when the table's intrabar is the input
43/// timeframe itself (a 10-minute chart on 1-minute bars), cannot be built
44/// from it (a 1- or 5-minute chart needs 10- or 30-second bars), or when a
45/// bar's calendar interval cannot be resolved.
46std::vector<Bar> tradingview_magnifier_bars(const Bar* bars, int n,
47 const std::string& input_tf,
48 const std::string& script_tf,
49 const std::string& session,
50 const std::string& timezone);
51
52/// The same logical path without retaining the input or a whole-run path.
53/// Input stays immutable and alive through the consumer's public run exit.
54/// Construction decides whole-input fallback and caches count; whole walks
55/// have independent cursors, and segment storage survives all const reads.
56std::unique_ptr<NativeLowerPathSource> make_magnifier_path_source(
57 const Bar* bars, int n, const std::string& input_tf,
58 const std::string& script_tf, const std::string& session,
59 const std::string& timezone);
60
61} // 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...