PineForge v0.13.1-379-g9b50973
Deterministic PineScript v6 backtest runtime — C ABI reference
Loading...
Searching...
No Matches
pine_policy_support.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <cmath>
4#include <cstddef>
5#include <string>
6
7namespace pineforge::source {
8
9inline double tv_money_round(double value) {
10 if (!std::isfinite(value) || value == 0.0) return value;
11 const double magnitude = std::floor(std::log10(std::abs(value)));
12 const double scale = std::pow(10.0, 9.0 - magnitude);
13 const double rounded = std::floor(std::abs(value) * scale + 0.5) / scale;
14 return value < 0.0 ? -rounded : rounded;
15}
16
17inline double tv_money_floor_lot(double qty, double step) {
18 if (!(step > 0.0) || !std::isfinite(qty) || qty <= 0.0) return qty;
19 double floored = std::floor(qty / step) * step;
20 if (step == 0.01) {
21 const double cent_candidate = std::floor(qty * 100.0) * step;
22 if (cent_candidate > floored && cent_candidate <= qty)
23 floored = cent_candidate;
24 }
25 return floored < qty ? floored : qty;
26}
27
28inline const std::string& pine_enum_str_at(const std::string* table, std::size_t n,
29 int idx) {
30 static const std::string kEmpty;
31 if (n == 0 || table == nullptr) return kEmpty;
32 std::size_t u = static_cast<std::size_t>(idx);
33 if (u >= n) u = n - 1;
34 return table[u];
35}
36
37} // namespace pineforge::source
double tv_money_round(double value)
const std::string & pine_enum_str_at(const std::string *table, std::size_t n, int idx)
double tv_money_floor_lot(double qty, double step)