PineForge v0.13.1-379-g9b50973
Deterministic PineScript v6 backtest runtime — C ABI reference
Loading...
Searching...
No Matches
reservation_expansion.cpp
Go to the documentation of this file.
2
4
5#include <cmath>
6
8
9std::vector<std::uint64_t> select_reservation_growth_sources(
10 const std::vector<ReservationGrowthCandidate>& candidates,
11 const std::string& from_entry, bool process_on_close, bool effectively_flat,
12 double percent, int bar, PositionSide side) {
13 if (!from_entry.empty() || !process_on_close || effectively_flat
14 || percent < 100.0 - 1e-9) {
15 return {};
16 }
17 std::vector<std::uint64_t> selected;
18 for (const auto& candidate : candidates) {
19 const auto requested = candidate.is_long ? PositionSide::LONG : PositionSide::SHORT;
20 if (!candidate.market_entry || candidate.from_fill || candidate.at_entry_capacity
21 || candidate.created_bar != bar || requested != side
22 || candidate.created_position_side != side) {
23 return {};
24 }
25 selected.push_back(candidate.incarnation);
26 }
27 return selected;
28}
29
30bool admits_reservation_expansion(const std::vector<std::uint64_t>& selected,
31 bool partial, double reserved, double live) noexcept {
32 return !selected.empty() && !partial && std::isfinite(reserved)
33 && reserved >= live - 1e-9;
34}
35
36} // namespace pineforge::compat::pine
bool admits_reservation_expansion(const std::vector< std::uint64_t > &selected, bool partial, double reserved, double live) noexcept
std::vector< std::uint64_t > select_reservation_growth_sources(const std::vector< ReservationGrowthCandidate > &candidates, const std::string &from_entry, bool process_on_close, bool effectively_flat, double percent, int bar, PositionSide side)