PineForge v0.13.1-379-g9b50973
Deterministic PineScript v6 backtest runtime — C ABI reference
Loading...
Searching...
No Matches
magnifier.hpp
Go to the documentation of this file.
1#pragma once
2#include <vector>
3#include "bar.hpp"
4
5namespace pineforge {
6
8 UNIFORM, // Equal spacing along path length
9 COSINE, // Dense at segment endpoints (Chebyshev-like)
10 TRIANGLE, // Dense at midpoints of each segment
11 ENDPOINTS, // Always include exact O,H,L,C + uniform fill between (default)
12 FRONT_LOADED, // Dense near O (simulates opening-impulse price action)
13 BACK_LOADED, // Dense near C (simulates closing-impulse price action)
14};
15
16/// Maps parameter t in [0,1] to a price on the 3-segment path.
17/// Segments: p0->p1, p1->p2, p2->p3 with arc lengths len0, len1, len2.
18double path_at(double t, double p0, double p1, double p2, double p3,
19 double len0, double len1, double len2, double total);
20
21/// Sample n_samples points along the OHLC price path of the bar.
22/// The first leg follows TradingView-style open proximity: O -> H -> L -> C
23/// when open is nearer high, otherwise O -> L -> H -> C (ties low-first).
24/// First sample is always O, last is always C. Minimum 2 samples.
25std::vector<double> sample_price_path(const Bar& bar, int n_samples,
27
28/// Out-parameter overload of sample_price_path. Writes the sampled prices into
29/// `out` (cleared first; retained capacity is reused), avoiding a per-call heap
30/// allocation in hot sampling loops. Behaviour is identical to the
31/// value-returning overload.
32void sample_price_path(const Bar& bar, int n_samples,
33 MagnifierDistribution dist, std::vector<double>& out);
34
35/// Sample n_samples points along the OHLC price path, weighting the sample
36/// density by the ratio of this bar's volume to a reference `mean_volume`. A
37/// bar with 2x average volume receives up to 2x as many samples as a bar at
38/// average volume, clamped within [min_samples, max_samples].
39///
40/// Intended for magnifier modes that should simulate denser tick streams when
41/// volume is higher (more trades per bar → more fill opportunities).
42std::vector<double> sample_price_path_volume_weighted(const Bar& bar,
43 int base_samples,
44 double mean_volume,
45 int min_samples = 2,
46 int max_samples = 64,
48
49/// Out-parameter overload of sample_price_path_volume_weighted. Writes into
50/// `out` (cleared first; retained capacity reused). Behaviour is identical to
51/// the value-returning overload.
53 int base_samples,
54 double mean_volume,
55 int min_samples,
56 int max_samples,
58 std::vector<double>& out);
59
60} // namespace pineforge
MagnifierDistribution
Definition magnifier.hpp:7
std::vector< double > sample_price_path(const Bar &bar, int n_samples, MagnifierDistribution dist=MagnifierDistribution::ENDPOINTS)
Sample n_samples points along the OHLC price path of the bar.
double path_at(double t, double p0, double p1, double p2, double p3, double len0, double len1, double len2, double total)
Maps parameter t in [0,1] to a price on the 3-segment path.
std::vector< double > sample_price_path_volume_weighted(const Bar &bar, int base_samples, double mean_volume, int min_samples=2, int max_samples=64, MagnifierDistribution dist=MagnifierDistribution::ENDPOINTS)
Sample n_samples points along the OHLC price path, weighting the sample density by the ratio of this ...