PineForge unreleased
Deterministic PineScript v6 backtest runtime — C ABI reference
Loading...
Searching...
No Matches
pineforge::source Namespace Reference

Namespaces

namespace  detail
 
namespace  multi_day_detail
 
namespace  value_field
 The closed vocabulary of field: "<sink>.<argument>".
 

Data Structures

class  BracketRoster
 
struct  DeferredAuxBar
 
struct  DroppedCloseReceipt
 
class  FirstCallBound
 
class  HeldHistory
 
struct  HistoricalSecurityProjection
 
struct  MultiDayFeeds
 What a run holds of the symbol the N-day request reads. More...
 
struct  OpenEntryFeeFact
 
class  OriginRoster
 
class  PendingIntentView
 
class  PendingReadback
 
struct  PendingShortSeedPlan
 
struct  PineCancellationReceipt
 
class  PineExecutionAdapter
 
struct  PineExitLevels
 
struct  PineLanguageState
 
struct  PineReplayRiskConfig
 
struct  PineRiskState
 
class  PineScheduler
 
struct  PineSecurityEvalState
 
struct  PineSizingSnapshot
 
struct  PineStrategyConfig
 
class  PineStrategyHost
 
class  PineSupertrend
 
class  PlacementReadback
 
struct  PlacementSnapshot
 
class  PlacementTable
 
struct  RecordedSeries
 
struct  RecordedSeriesRow
 
class  SeriesHighest
 
class  SeriesHighestBars
 
class  SeriesLowest
 
class  SeriesLowestBars
 
class  SeriesWindowExtreme
 
struct  ShortSeedPlan
 
struct  SourceDayLedger
 
struct  StagedConfiguration
 
struct  StagedInstrumentFeed
 
struct  StrategyOverrides
 
struct  SymbolFacts
 

Typedefs

using SourceId = std::string
 
using PineNativeHost = PineStrategyHost
 
using FixtureIntentRow = PineStrategyHost::FixtureIntentRow
 
using FixtureIntentKind = PineStrategyHost::FixtureIntentKind
 

Enumerations

enum class  PineOrderFamily : std::uint8_t {
  Entry = 0 ,
  Close = 1 ,
  CloseAll = 2 ,
  ExitLimit = 3 ,
  ExitStop = 4 ,
  ExitTrail = 5 ,
  Order = 6 ,
  Margin = 7 ,
  Risk = 8
}
 
enum class  PineCancellationCause : std::int32_t {
  None = 0 ,
  Replacement = 1 ,
  Dependency = 2 ,
  Admission = 3 ,
  Explicit = 4
}
 
enum class  StrategyValueReason {
  nonfinite ,
  invalid_unicode ,
  numeric_overflow
}
 

Functions

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 TradingView's help centre ("What is bar magnifier backtesting mode"), each row covering the chart timeframes from it up to the next one: below 30S 1S, 30S 5S, 1 10S, 5 30S, 10 1, 15 2, 30 5, 60 10, 240 30, 1D 60, 3D 240, 1W and up 1D.
 
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 bars are aggregated from bars (input timeframe input_tf, chart timeframe script_tf, the symbol's session in timezone), as bars for IntrabarPath::lower_tf on the input's own grid.
 
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.
 
bool modeled_pine_input (NativePriceProvenance provenance) noexcept
 
double tv_money_round (double value)
 
double tv_money_floor_lot (double qty, double step)
 
const std::string & pine_enum_str_at (const std::string *table, std::size_t n, int idx)
 
bool same_calendar_timeframe (const native_calendar::Timeframe &requested, const native_calendar::Timeframe &chart) noexcept
 
int simple_ta_length (double value, const char *function, const char *argument)
 
int simple_ta_length (int value, const char *function, const char *argument)
 
int simple_ta_length (std::int64_t value, const char *function, const char *argument)
 
double ta_number (double value)
 
double ta_number (int value)
 
double ta_number (std::int64_t value)
 
std::shared_ptr< TimeframeAggregator::PeriodSource > make_multi_day_period_source (const MultiDayFeeds &feeds)
 The N-day partition of feeds, or null where TradingView's rule yields none: fewer than two days, a session that does not parse, no held session day, no period opening at or before the first held day, an open that does not come after the one before it, or a date whose local noon does not exist.
 
const char * instrument_feed_field_name (NativeRunSpecField field) noexcept
 
RunFailureValue run_spec_field_failure (NativeRunSpecField field) noexcept
 
std::optional< double > checked_mul (double left, double right) noexcept
 
std::optional< double > checked_div (double left, double right) noexcept
 
std::optional< double > checked_add (double left, double right) noexcept
 
void admit_strategy_entry (const std::string &id, bool, double limit_price, double stop_price, double, const std::string &comment, const std::string &oca_name, int, int)
 
void admit_strategy_close (const std::string &id, const std::string &comment, double, double, bool)
 
void admit_strategy_close_token (const std::string &id, const std::string &comment, double qty, double qty_percent, bool immediately, std::uint64_t)
 
void admit_strategy_close_all () noexcept
 
void admit_strategy_exit (const std::string &id, const std::string &from_entry, double limit_price, double, double, double trail_offset, double trail_price, double, const std::string &comment, double, const std::string &oca_name, double profit_ticks, double loss_ticks)
 
void admit_strategy_exit_cancel_bracket (const std::string &exit_id, const std::string &from_entry, const std::string &comment)
 
void admit_strategy_cancel (const std::string &id)
 
void admit_strategy_cancel_all () noexcept
 
void admit_strategy_order (const std::string &id, bool, double, double limit_price, double stop_price, const std::string &oca_name, int)
 
const char * strategy_value_reason_name (StrategyValueReason reason) noexcept
 
void throw_strategy_value_invalid (const char *field, StrategyValueReason reason)
 The coded failure of a source-owned invalid actionable value.
 
bool declaration_value_is_invalid (double value) noexcept
 
void admit_strategy_declaration (const PineStrategyConfig &config)
 
void admit_pine_risk_max_drawdown (double value, bool)
 
void admit_pine_risk_max_intraday_loss (double value, bool)
 
void admit_pine_risk_max_position_size (double value)
 
void assert_admitted_pine_replay_risk_config (const PineReplayRiskConfig &snapshot)
 

Variables

constexpr char kSourceAdapterDomain [] = "pineforge-source-adapter/v4"
 
constexpr char kMarginCallLabel [] = "__margin_call__"
 
constexpr char kIntradayLossComment [] = "Close Position (Max intraday Loss)"
 
constexpr char kFillCapCommentPrefix []
 
constexpr std::uint32_t kCoofLoopGuard = 1U << 20
 
constexpr char kSourceSecurityDomain [] = "pineforge-source-security/v6"
 
constexpr char kSourceSymbolDataDomain [] = "pineforge-source-symbol-data/v1"
 
constexpr std::size_t kMultiDayWindow = 16
 The most period opens a multi-day period source holds at once: the recent ones it answers short questions from, and the next one ahead.
 
constexpr std::size_t kUnorderedRescanDays = 366
 Bounds the fallback's retained trading-date slots to one calendar year, including a leap year; N-day counting restarts each year.
 
constexpr bool kDeclarationNanIsInvalid = false
 

Typedef Documentation

◆ SourceId

using pineforge::source::SourceId = std::string

Definition at line 42 of file pine_adapter.hpp.

◆ PineNativeHost

◆ FixtureIntentRow

◆ FixtureIntentKind

Enumeration Type Documentation

◆ PineOrderFamily

enum class pineforge::source::PineOrderFamily : std::uint8_t
strong
Enumerator
Entry 
Close 
CloseAll 
ExitLimit 
ExitStop 
ExitTrail 
Order 
Margin 
Risk 

Definition at line 133 of file pine_adapter.hpp.

◆ PineCancellationCause

enum class pineforge::source::PineCancellationCause : std::int32_t
strong
Enumerator
None 
Replacement 
Dependency 
Admission 
Explicit 

Definition at line 155 of file pine_adapter.hpp.

◆ StrategyValueReason

Enumerator
nonfinite 
invalid_unicode 
numeric_overflow 

Definition at line 17 of file pine_value_admission.hpp.

Function Documentation

◆ tradingview_intrabar_timeframe()

std::string pineforge::source::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 TradingView's help centre ("What is bar magnifier backtesting mode"), each row covering the chart timeframes from it up to the next one: below 30S 1S, 30S 5S, 1 10S, 5 30S, 10 1, 15 2, 30 5, 60 10, 240 30, 1D 60, 3D 240, 1W and up 1D.

Empty for a literal that does not parse. R5 lane MAG-INTRABAR measured every row the population uses against TradingView's own request.security_lower_tf bars and magnified tapes (tests/fixtures/magnifier_intrabars).

Definition at line 45 of file magnifier_intrabars.cpp.

Referenced by tradingview_magnifier_bars().

◆ tradingview_magnifier_bars()

std::vector< Bar > pineforge::source::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 bars are aggregated from bars (input timeframe input_tf, chart timeframe script_tf, the symbol's session in timezone), as bars for IntrabarPath::lower_tf on the input's own grid.

TradingView's intrabars are the symbol's regular bars at the table's timeframe: anchored at the session day's open, cut at its close, and each owned by the chart bar that holds its LAST minute, so on a 15-minute chart a 2-minute intrabar that straddles a chart boundary belongs to the later bar. A chart bar's path is its own open, its owned intrabars (each open a discrete point, then its extremes and close), then its own close. Here that is:

  • a one-price bar at the chart bar's open, stamped at its first input, when its first intrabar starts before it (the straddler);
  • each owned intrabar, stamped at its first input bar – the straddler one millisecond after the open bar, inside the chart bar that owns it;
  • a one-price bar at the chart bar's close, stamped at its last input, when its last input belongs to a later chart bar's intrabar.

The input bars come back unchanged when the table's intrabar is the input timeframe itself (a 10-minute chart on 1-minute bars), cannot be built from it (a 1- or 5-minute chart needs 10- or 30-second bars), or when a bar's calendar interval cannot be resolved.

Definition at line 73 of file magnifier_intrabars.cpp.

References pineforge::Bar::close, pineforge::Bar::high, pineforge::input, pineforge::Bar::low, pineforge::Bar::open, pineforge::Bar::timestamp, tradingview_intrabar_timeframe(), and pineforge::Bar::volume.

Referenced by pineforge::source::PineExecutionAdapter::project().

◆ make_magnifier_path_source()

std::unique_ptr< NativeLowerPathSource > pineforge::source::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.

Input stays immutable and alive through the consumer's public run exit. Construction decides whole-input fallback and caches count; whole walks have independent cursors, and segment storage survives all const reads.

Definition at line 437 of file magnifier_intrabars.cpp.

Referenced by pineforge::source::PineExecutionAdapter::project().

◆ modeled_pine_input()

bool pineforge::source::modeled_pine_input ( NativePriceProvenance provenance)
inlinenoexcept

Definition at line 7 of file pine_input_domain.hpp.

◆ tv_money_round()

double pineforge::source::tv_money_round ( double value)
inline

Definition at line 9 of file pine_policy_support.hpp.

◆ tv_money_floor_lot()

double pineforge::source::tv_money_floor_lot ( double qty,
double step )
inline

Definition at line 17 of file pine_policy_support.hpp.

◆ pine_enum_str_at()

const std::string & pineforge::source::pine_enum_str_at ( const std::string * table,
std::size_t n,
int idx )
inline

Definition at line 28 of file pine_policy_support.hpp.

◆ same_calendar_timeframe()

bool pineforge::source::same_calendar_timeframe ( const native_calendar::Timeframe & requested,
const native_calendar::Timeframe & chart )
inlinenoexcept

Definition at line 7 of file pine_security_timeframe.hpp.

◆ simple_ta_length() [1/3]

int pineforge::source::simple_ta_length ( double value,
const char * function,
const char * argument )

Definition at line 81 of file pine_ta_length.cpp.

Referenced by pineforge::source::PineSupertrend::compute().

◆ simple_ta_length() [2/3]

int pineforge::source::simple_ta_length ( int value,
const char * function,
const char * argument )

Definition at line 88 of file pine_ta_length.cpp.

References pineforge::is_na().

◆ simple_ta_length() [3/3]

int pineforge::source::simple_ta_length ( std::int64_t value,
const char * function,
const char * argument )

Definition at line 94 of file pine_ta_length.cpp.

References pineforge::is_na().

◆ ta_number() [1/3]

double pineforge::source::ta_number ( double value)
inline

Definition at line 57 of file pine_ta_length.hpp.

◆ ta_number() [2/3]

double pineforge::source::ta_number ( int value)
inline

Definition at line 58 of file pine_ta_length.hpp.

References pineforge::is_na(), and pineforge::na< double >().

◆ ta_number() [3/3]

double pineforge::source::ta_number ( std::int64_t value)
inline

Definition at line 61 of file pine_ta_length.hpp.

References pineforge::is_na(), and pineforge::na< double >().

◆ make_multi_day_period_source()

std::shared_ptr< TimeframeAggregator::PeriodSource > pineforge::source::make_multi_day_period_source ( const MultiDayFeeds & feeds)
inline

The N-day partition of feeds, or null where TradingView's rule yields none: fewer than two days, a session that does not parse, no held session day, no period opening at or before the first held day, an open that does not come after the one before it, or a date whose local noon does not exist.

Ordered planning walks the feeds twice (the first and last held day, then every period once to prove the partition whole). An unordered feed instead uses full-feed rescans with at most kUnorderedRescanDays retained date slots; neither path keeps a table of all held days.

Definition at line 719 of file multi_day_periods.hpp.

References pineforge::source::MultiDayFeeds::aux, pineforge::source::MultiDayFeeds::chart, pineforge::source::MultiDayFeeds::daily_chart, pineforge::source::MultiDayFeeds::days, pineforge::source::MultiDayFeeds::exchange_calendar, pineforge::source::MultiDayFeeds::n_aux, pineforge::source::MultiDayFeeds::n_chart, pineforge::source::MultiDayFeeds::session, pineforge::source::MultiDayFeeds::tz, and pineforge::native_calendar::native_calendar_v2::NativeCivilDate::year.

◆ instrument_feed_field_name()

◆ run_spec_field_failure()

◆ checked_mul()

std::optional< double > pineforge::source::checked_mul ( double left,
double right )
inlinenoexcept

Definition at line 12 of file pine_checked_arith.hpp.

◆ checked_div()

std::optional< double > pineforge::source::checked_div ( double left,
double right )
inlinenoexcept

Definition at line 19 of file pine_checked_arith.hpp.

◆ checked_add()

std::optional< double > pineforge::source::checked_add ( double left,
double right )
inlinenoexcept

Definition at line 26 of file pine_checked_arith.hpp.

◆ admit_strategy_entry()

void pineforge::source::admit_strategy_entry ( const std::string & id,
bool ,
double limit_price,
double stop_price,
double ,
const std::string & comment,
const std::string & oca_name,
int ,
int  )

◆ admit_strategy_close()

void pineforge::source::admit_strategy_close ( const std::string & id,
const std::string & comment,
double ,
double ,
bool  )

◆ admit_strategy_close_token()

void pineforge::source::admit_strategy_close_token ( const std::string & id,
const std::string & comment,
double qty,
double qty_percent,
bool immediately,
std::uint64_t  )

Definition at line 87 of file pine_value_admission.cpp.

References admit_strategy_close().

◆ admit_strategy_close_all()

void pineforge::source::admit_strategy_close_all ( )
noexcept

Definition at line 93 of file pine_value_admission.cpp.

◆ admit_strategy_exit()

void pineforge::source::admit_strategy_exit ( const std::string & id,
const std::string & from_entry,
double limit_price,
double ,
double ,
double trail_offset,
double trail_price,
double ,
const std::string & comment,
double ,
const std::string & oca_name,
double profit_ticks,
double loss_ticks )

◆ admit_strategy_exit_cancel_bracket()

void pineforge::source::admit_strategy_exit_cancel_bracket ( const std::string & exit_id,
const std::string & from_entry,
const std::string & comment )

◆ admit_strategy_cancel()

void pineforge::source::admit_strategy_cancel ( const std::string & id)

◆ admit_strategy_cancel_all()

void pineforge::source::admit_strategy_cancel_all ( )
noexcept

Definition at line 126 of file pine_value_admission.cpp.

◆ admit_strategy_order()

void pineforge::source::admit_strategy_order ( const std::string & id,
bool ,
double ,
double limit_price,
double stop_price,
const std::string & oca_name,
int  )

◆ strategy_value_reason_name()

const char * pineforge::source::strategy_value_reason_name ( StrategyValueReason reason)
inlinenoexcept

Definition at line 19 of file pine_value_admission.hpp.

References invalid_unicode, nonfinite, and numeric_overflow.

Referenced by throw_strategy_value_invalid().

◆ throw_strategy_value_invalid()

void pineforge::source::throw_strategy_value_invalid ( const char * field,
StrategyValueReason reason )
inline

The coded failure of a source-owned invalid actionable value.

Thrown, so the existing exception path classifies it (RunFailureInfo wins over the type).

Definition at line 30 of file pine_value_admission.hpp.

References pineforge::strategy_value_invalid, and strategy_value_reason_name().

Referenced by admit_pine_risk_max_drawdown(), admit_pine_risk_max_intraday_loss(), admit_pine_risk_max_position_size(), and admit_strategy_declaration().

◆ declaration_value_is_invalid()

bool pineforge::source::declaration_value_is_invalid ( double value)
inlinenoexcept

Definition at line 16 of file pine_value_admit_decl.hpp.

References kDeclarationNanIsInvalid.

Referenced by admit_strategy_declaration().

◆ admit_strategy_declaration()

◆ admit_pine_risk_max_drawdown()

void pineforge::source::admit_pine_risk_max_drawdown ( double value,
bool  )
inline

◆ admit_pine_risk_max_intraday_loss()

void pineforge::source::admit_pine_risk_max_intraday_loss ( double value,
bool  )
inline

◆ admit_pine_risk_max_position_size()

void pineforge::source::admit_pine_risk_max_position_size ( double value)
inline

◆ assert_admitted_pine_replay_risk_config()

void pineforge::source::assert_admitted_pine_replay_risk_config ( const PineReplayRiskConfig & snapshot)
inline

Variable Documentation

◆ kSourceAdapterDomain

char pineforge::source::kSourceAdapterDomain[] = "pineforge-source-adapter/v4"
inlineconstexpr

◆ kMarginCallLabel

char pineforge::source::kMarginCallLabel[] = "__margin_call__"
inlineconstexpr

◆ kIntradayLossComment

char pineforge::source::kIntradayLossComment[] = "Close Position (Max intraday Loss)"
inlineconstexpr

◆ kFillCapCommentPrefix

char pineforge::source::kFillCapCommentPrefix[]
inlineconstexpr
Initial value:
=
"Close Position (Max number of filled orders"

Definition at line 69 of file pine_adapter.hpp.

Referenced by pineforge::source::PineStrategyHost::on_native_applied().

◆ kCoofLoopGuard

std::uint32_t pineforge::source::kCoofLoopGuard = 1U << 20
inlineconstexpr

◆ kSourceSecurityDomain

char pineforge::source::kSourceSecurityDomain[] = "pineforge-source-security/v6"
inlineconstexpr

◆ kSourceSymbolDataDomain

char pineforge::source::kSourceSymbolDataDomain[] = "pineforge-source-symbol-data/v1"
inlineconstexpr

◆ kMultiDayWindow

std::size_t pineforge::source::kMultiDayWindow = 16
inlineconstexpr

The most period opens a multi-day period source holds at once: the recent ones it answers short questions from, and the next one ahead.

Definition at line 74 of file multi_day_periods.hpp.

◆ kUnorderedRescanDays

std::size_t pineforge::source::kUnorderedRescanDays = 366
inlineconstexpr

Bounds the fallback's retained trading-date slots to one calendar year, including a leap year; N-day counting restarts each year.

Clock changes (also through the legacy coverage clock) normally regress dates by about a day. No distance bound is assumed: full-feed rescans remain exact even beyond this window, replacing the slots rather than accumulating years.

Definition at line 81 of file multi_day_periods.hpp.

Referenced by pineforge::source::multi_day_detail::RescannedHeldDays::find().

◆ kDeclarationNanIsInvalid

bool pineforge::source::kDeclarationNanIsInvalid = false
inlineconstexpr

Definition at line 14 of file pine_value_admit_decl.hpp.

Referenced by declaration_value_is_invalid().