PineForge unreleased
Deterministic PineScript v6 backtest runtime — C ABI reference
Loading...
Searching...
No Matches
pine_ta_series_stats.hpp
Go to the documentation of this file.
1#pragma once
2// Statistics built-ins whose length is a per-call (series) value: ta.stdev,
3// ta.variance, ta.dev, ta.range, ta.median, ta.mode, ta.percentrank,
4// ta.percentile_linear_interpolation, ta.correlation and math.sum.
5//
6// TradingView compiles a series length for each of them (observed in
7// November 2026 on synthetic scripts whose length changes on every bar).
8// What TradingView computes after a length change is not recorded by a tape
9// for any of the ten: the rule below is this layer's definition of it.
10//
11// Every class takes the length on each call, as SeriesSma does, and answers
12// what the fixed-length class of <pineforge/ta.hpp> answers for that length
13// (for math.sum, math::Sum's window):
14//
15// * While the length of a call site stays the same, every call goes to one
16// fixed-length object (ta.range: see below), so the values are that
17// class's own, bit for bit, its na rule included. A site whose length
18// never changes is the fixed-length call.
19// * A call with another length builds the fixed-length object of the new
20// length and replays the site's retained inputs through it, oldest first,
21// then the current input. The answer is the function over the last
22// `length` inputs as a new fixed-length object computes it.
23// * ta.stdev, ta.variance, ta.dev, ta.median, ta.mode and math.sum never let
24// an na source into their window, so the site retains its non-na sources
25// and the window is the last `length` of them. An na call answers what the
26// fixed-length class answers: math.sum and ta.stdev hold the value of the
27// full window, the other four answer na.
28// * ta.percentrank, ta.percentile_linear_interpolation and ta.correlation
29// keep one slot per call, na included: the window is the last `length`
30// calls (for ta.percentrank the current source and the `length` before
31// it). After a length change the percentile window is replayed in call
32// order, as SeriesPercentileNearestRank replays its own.
33// * ta.range is SeriesHighest minus SeriesLowest on the same calls (the rule
34// documented at SeriesWindowExtreme), not a fixed-length object: it equals
35// ta::Range for a constant length only on a site that runs on every bar.
36// * A call whose window needs more inputs than the site holds answers na and
37// builds nothing, so a very long length allocates nothing.
38//
39// The length is checked before anything is updated, by SeriesSma's rule and
40// with SeriesSma's errors: an na or infinite length, a length below one
41// after truncation toward zero, or a length beyond a configured lookback cap
42// stops the run. Lookback is unlimited unless the host sets a cap; with a
43// cap a site retains its last cap + 2 inputs.
44//
45// recompute() runs the current call again with other inputs, or another
46// length, from the state the call found. Each compute() is one logical
47// update of its site.
48//
49// math.sum and the biased ta.stdev keep compensated running sums. Those sums
50// restart from the replayed window on a length change; SeriesSma, the one
51// series-length sum recorded on TradingView, adjusts one running pair
52// instead. The two can differ in the last bits of a sum.
55#include <pineforge/na.hpp>
58#include <pineforge/series.hpp>
59#include <pineforge/ta.hpp>
61
62#include <climits>
63#include <cmath>
64#include <cstddef>
65#include <cstdint>
66#include <limits>
67#include <optional>
68#include <string>
69#include <type_traits>
70#include <utility>
71
72namespace pineforge {
73namespace source {
74
76
77// simple_ta_length stops the run for an na, zero or negative value with
78// TradingView's text; the callers pass only such a value.
79[[noreturn]] inline void stop_for_length(double value, const char* function) {
80 simple_ta_length(value, function, "length");
81 pine_engine_invariant("a per-call length that must stop the run passed its check");
82}
83
84[[noreturn]] inline void stop_for_lookback(std::uint64_t offset, std::int64_t maximum,
85 bool beyond_uint64) {
86 const std::string text = run_error_bar_prefix() +
87 "The script attempts to reference historical data that is too far from "
88 "the current bar (" + (beyond_uint64 ? "more than " : "") + std::to_string(offset) +
89 " bars back). The historical buffer's limit is " + std::to_string(maximum) + " bars.";
90 pine_limit_stop("max_bars_back", maximum, text.c_str());
91}
92
93// SeriesSma's check of a per-call length, reported for `function`: the
94// length truncated toward zero, or a stopped run.
95inline std::uint64_t checked_length(double length, const char* function,
96 std::int64_t maximum) {
97 if (!std::isfinite(length)) stop_for_length(na<double>(), function);
98 if (!(length >= 1.0)) stop_for_length(length, function);
99 if (length >= 0x1p64) {
100 constexpr auto last = std::numeric_limits<std::uint64_t>::max();
101 if (maximum != 0) stop_for_lookback(last, maximum, length > 0x1p64);
102 return last;
103 }
104 const auto requested = static_cast<std::uint64_t>(length);
105 if (maximum != 0 && requested - 1 > static_cast<std::uint64_t>(maximum))
106 stop_for_lookback(requested - 1, maximum, false);
107 return requested;
108}
109
110// The length a fixed-length class is built with. A window longer than the
111// inputs a site holds is never built, so the limit is not reached.
112inline int fixed_length(std::uint64_t length) {
113 return length > static_cast<std::uint64_t>(INT_MAX) ? INT_MAX : static_cast<int>(length);
114}
115
116// How many inputs a site retains: all of them (0) without a lookback cap,
117// else the current one and the cap + 1 before it. A cap beyond addressable
118// storage cannot cause eviction.
119inline std::size_t retained_inputs(std::int64_t maximum) {
120 constexpr std::size_t slots = std::numeric_limits<std::size_t>::max() / sizeof(double);
121 if (maximum <= 0 || static_cast<std::uint64_t>(maximum) >= slots - 2) return 0;
122 return static_cast<std::size_t>(maximum) + 2;
123}
124
125// The inputs one call site has recorded, oldest first. Without a limit every
126// input is kept; with one the oldest leaves when the limit is reached.
127// Numeric storage is copy-on-write and follows the cache capacity given at
128// construction.
129class Inputs {
130public:
131 Inputs(WindowCacheCapacity cache, std::size_t keep) : values_(cache), keep_(keep) {}
132 // Copy even from an rvalue: the counts still name the source's storage.
133 Inputs(const Inputs&) = default;
134 Inputs& operator=(const Inputs&) = default;
135
136 std::size_t size() const { return stored_; }
137 void append(double value) {
138 if (keep_ != 0 && stored_ == keep_) {
139 oldest_ = oldest_ + 1 == values_.size() ? 0 : oldest_ + 1;
140 --stored_;
141 }
142 if (stored_ == values_.size()) grow();
143 values_.write(slot(stored_), value);
144 ++stored_;
145 }
146 // The newest input leaves; the caller keeps size() above zero.
147 void pop_back() { --stored_; }
148 // The newest input is replaced; the caller keeps size() above zero.
149 void replace_back(double value) { values_.write(slot(stored_ - 1), value); }
150 // The input `back` places before the newest (0 is the newest); the
151 // caller keeps `back` below size().
152 double from_back(std::size_t back) const { return values_.read(slot(stored_ - 1 - back)); }
153 void observe_owned_storage(OwnedStorage& out) const noexcept {
154 values_.observe_owned_storage(out);
155 }
156
157private:
159
160 std::size_t slot(std::size_t index) const {
161 const std::size_t remaining = values_.size() - oldest_;
162 return index >= remaining ? index - remaining : oldest_ + index;
163 }
164 // Storage grows only before a limit is reached, when it has not wrapped.
165 void grow() {
166 constexpr std::size_t most = std::numeric_limits<std::size_t>::max() / sizeof(double);
167 const std::size_t held = values_.size();
168 std::size_t capacity = held == 0 ? Values::kChunk : (held > most / 2 ? most : 2 * held);
169 // One more than the representable extent is refused by the storage.
170 if (capacity <= held) capacity = held + 1;
171 if (keep_ != 0 && capacity > keep_) capacity = keep_;
172 Values next(capacity, na<double>(), values_.cache_capacity());
173 for (std::size_t index = 0; index < stored_; ++index)
174 next.write(index, values_.read(slot(index)));
175 values_ = std::move(next);
176 oldest_ = 0;
177 }
178
179 Values values_;
180 std::size_t keep_;
181 std::size_t oldest_ = 0; // where the oldest retained input is stored
182 std::size_t stored_ = 0;
183};
184
185// The fixed-length object of `length`: built with `option` where the class
186// takes one (ta::StdDev and ta::Variance: biased).
187template <class Window>
188void build_window(std::optional<Window>& window, int length, bool option) {
189 if constexpr (std::is_constructible_v<Window, int, bool>) {
190 window.emplace(length, option);
191 } else {
192 static_cast<void>(option);
193 window.emplace(length);
194 }
195}
196
197// math::Sum's compute() and recompute() on the window math::Sum uses, with
198// the window's storage observable.
200 KahanWindowSum window_;
201
202public:
203 explicit SumWindow(int length) : window_(length) {}
204 double compute(double src) {
205 if (is_na(src)) {
206 window_.note_no_push();
207 return window_.seeded() ? window_.sum() : na<double>();
208 }
209 const double sum = window_.push(src);
210 return window_.seeded() ? sum : na<double>();
211 }
212 double recompute(double src) {
213 if (is_na(src)) {
214 window_.unpush();
215 window_.note_no_push();
216 return window_.seeded() ? window_.sum() : na<double>();
217 }
218 const double sum = window_.repush(src);
219 return window_.seeded() ? sum : na<double>();
220 }
221 void observe_owned_storage(OwnedStorage& out) const noexcept {
222 window_.observe_owned_storage(out);
223 }
224};
225
226// A site of a function whose fixed-length class `Window` skips na sources:
227// the site retains its non-na sources and `Window` holds the last `length`
228// of them. `option` is the function's second constructor argument (biased),
229// false for a function that has none. While a Window exists, its last call
230// is this site's last call. A Window built by a call holds the sources of
231// that call's window only, not the one that was the oldest before the call,
232// so its own rewind cannot answer for the call run again (an na source would
233// find a window that is not full): that call builds the Window again.
234template <class Window>
236public:
238 : history_(cache, retained_inputs(max_lookback_)) {}
239 ValidSources(const ValidSources&) = default;
241
242 double update(const char* function, double source, double length, bool option,
243 bool replace) {
244 const std::uint64_t requested = checked_length(length, function, max_lookback_);
245 const bool again = replace && called_;
246 if (again && pushed_) history_.pop_back();
247 const bool push = !is_na(source);
248 if (push) history_.append(source);
249 called_ = true;
250 pushed_ = push;
251 if (requested > history_.size()) {
252 window_.reset();
253 return na<double>();
254 }
255 const bool carried = window_.has_value() && !(again && built_) &&
256 window_length_ == requested && window_option_ == option;
257 if (carried) {
258 built_ = false;
259 return again ? window_->recompute(source) : window_->compute(source);
260 }
261 series_stats_detail::build_window(window_, fixed_length(requested), option);
262 built_ = true;
263 window_length_ = requested;
264 window_option_ = option;
265 // The window's earlier sources, oldest first, then this call.
266 const std::size_t newest = push ? 1 : 0;
267 for (std::size_t earlier = static_cast<std::size_t>(requested) - newest; earlier != 0;
268 --earlier)
269 window_->compute(history_.from_back(newest + earlier - 1));
270 return window_->compute(source);
271 }
272 void observe_owned_storage(OwnedStorage& out) const noexcept {
273 ::pineforge::observe_owned_members(out, history_, window_);
274 }
275
276private:
277 std::int64_t max_lookback_ = ::pineforge::detail::ta_lookback_limit();
278 Inputs history_;
279 std::optional<Window> window_;
280 std::uint64_t window_length_ = 0;
281 bool window_option_ = false;
282 bool called_ = false;
283 bool pushed_ = false; // the last call recorded its source
284 bool built_ = false; // the last call built window_
285};
286
287// A site of a one-source function whose fixed-length class `Window` keeps
288// one slot per call, na included. `extra` is how many sources the window
289// holds beyond `length`; `step(window, source, again)` makes one call of the
290// fixed-length object. While a Window exists, its last call is this site's
291// last call.
292template <class Window>
294public:
296 : history_(cache, retained_inputs(max_lookback_)) {}
297 EveryCall(const EveryCall&) = default;
298 EveryCall& operator=(const EveryCall&) = default;
299
300 template <class Step>
301 double update(const char* function, double source, double length, std::size_t extra,
302 bool replace, Step step) {
303 const std::uint64_t requested = checked_length(length, function, max_lookback_);
304 const bool again = replace && called_;
305 if (again) history_.replace_back(source);
306 else history_.append(source);
307 called_ = true;
308 const std::size_t held = history_.size();
309 if (held < extra || requested > held - extra) {
310 window_.reset();
311 return na<double>();
312 }
313 if (window_ && window_length_ == requested) return step(*window_, source, again);
314 window_.emplace(fixed_length(requested));
315 window_length_ = requested;
316 for (std::size_t back = static_cast<std::size_t>(requested) + extra - 1; back != 0; --back)
317 step(*window_, history_.from_back(back), false);
318 return step(*window_, source, false);
319 }
320 void observe_owned_storage(OwnedStorage& out) const noexcept {
321 ::pineforge::observe_owned_members(out, history_, window_);
322 }
323
324private:
325 std::int64_t max_lookback_ = ::pineforge::detail::ta_lookback_limit();
326 Inputs history_;
327 std::optional<Window> window_;
328 std::uint64_t window_length_ = 0;
329 bool called_ = false;
330};
331
332} // namespace series_stats_detail
333
334// math.sum(source, length) with a series length.
336public:
338 explicit SeriesMathSum(WindowCacheCapacity cache) : core_(cache) {}
339 SeriesMathSum(const SeriesMathSum&) = default;
341 double compute(double source, double length) {
342 return core_.update("sum", source, length, false, false);
343 }
344 double recompute(double source, double length) {
345 return core_.update("sum", source, length, false, true);
346 }
347 void observe_owned_storage(OwnedStorage& out) const noexcept {
348 core_.observe_owned_storage(out);
349 }
350
351private:
353};
354
355// ta.stdev(source, length, biased) with a series length. `biased` is taken
356// on each call, before the length; the two-argument forms are biased = true.
358public:
360 explicit SeriesStdev(WindowCacheCapacity cache) : core_(cache) {}
361 SeriesStdev(const SeriesStdev&) = default;
363 double compute(double source, double length) { return compute(source, true, length); }
364 double compute(double source, bool biased, double length) {
365 return core_.update("stdev", source, length, biased, false);
366 }
367 double recompute(double source, double length) { return recompute(source, true, length); }
368 double recompute(double source, bool biased, double length) {
369 return core_.update("stdev", source, length, biased, true);
370 }
371 void observe_owned_storage(OwnedStorage& out) const noexcept {
372 core_.observe_owned_storage(out);
373 }
374
375private:
377};
378
379// ta.variance(source, length, biased) with a series length. `biased` is
380// taken on each call, before the length; the two-argument forms are
381// biased = true.
383public:
385 explicit SeriesVariance(WindowCacheCapacity cache) : core_(cache) {}
388 double compute(double source, double length) { return compute(source, true, length); }
389 double compute(double source, bool biased, double length) {
390 return core_.update("variance", source, length, biased, false);
391 }
392 double recompute(double source, double length) { return recompute(source, true, length); }
393 double recompute(double source, bool biased, double length) {
394 return core_.update("variance", source, length, biased, true);
395 }
396 void observe_owned_storage(OwnedStorage& out) const noexcept {
397 core_.observe_owned_storage(out);
398 }
399
400private:
402};
403
404// ta.dev(source, length) with a series length.
406public:
408 explicit SeriesDev(WindowCacheCapacity cache) : core_(cache) {}
409 SeriesDev(const SeriesDev&) = default;
410 SeriesDev& operator=(const SeriesDev&) = default;
411 double compute(double source, double length) {
412 return core_.update("dev", source, length, false, false);
413 }
414 double recompute(double source, double length) {
415 return core_.update("dev", source, length, false, true);
416 }
417 void observe_owned_storage(OwnedStorage& out) const noexcept {
418 core_.observe_owned_storage(out);
419 }
420
421private:
423};
424
425// ta.median(source, length) with a series length.
427public:
429 explicit SeriesMedian(WindowCacheCapacity cache) : core_(cache) {}
430 SeriesMedian(const SeriesMedian&) = default;
432 double compute(double source, double length) {
433 return core_.update("median", source, length, false, false);
434 }
435 double recompute(double source, double length) {
436 return core_.update("median", source, length, false, true);
437 }
438 void observe_owned_storage(OwnedStorage& out) const noexcept {
439 core_.observe_owned_storage(out);
440 }
441
442private:
444};
445
446// ta.mode(source, length) with a series length.
448public:
450 explicit SeriesMode(WindowCacheCapacity cache) : core_(cache) {}
451 SeriesMode(const SeriesMode&) = default;
452 SeriesMode& operator=(const SeriesMode&) = default;
453 double compute(double source, double length) {
454 return core_.update("mode", source, length, false, false);
455 }
456 double recompute(double source, double length) {
457 return core_.update("mode", source, length, false, true);
458 }
459 void observe_owned_storage(OwnedStorage& out) const noexcept {
460 core_.observe_owned_storage(out);
461 }
462
463private:
465};
466
467// ta.range(source, length) with a series length: the series-length highest
468// minus the series-length lowest of the same calls, na where either is.
470public:
472 explicit SeriesRange(WindowCacheCapacity cache) : highest_(cache), lowest_(cache) {}
473 SeriesRange(const SeriesRange&) = default;
475 double compute(double source, double length) {
476 series_stats_detail::checked_length(length, "range", max_lookback_);
477 const double high = highest_.compute(source, length);
478 const double low = lowest_.compute(source, length);
479 if (is_na(high) || is_na(low)) return na<double>();
480 return high - low;
481 }
482 double recompute(double source, double length) {
483 series_stats_detail::checked_length(length, "range", max_lookback_);
484 const double high = highest_.recompute(source, length);
485 const double low = lowest_.recompute(source, length);
486 if (is_na(high) || is_na(low)) return na<double>();
487 return high - low;
488 }
489 void observe_owned_storage(OwnedStorage& out) const noexcept {
490 highest_.observe_owned_storage(out);
491 lowest_.observe_owned_storage(out);
492 }
493
494private:
495 std::int64_t max_lookback_ = ::pineforge::detail::ta_lookback_limit();
496 SeriesHighest highest_;
497 SeriesLowest lowest_;
498};
499
500// ta.percentrank(source, length) with a series length: the current source
501// ranked among the `length` sources of the calls before it.
503public:
505 explicit SeriesPercentrank(WindowCacheCapacity cache) : core_(cache) {}
508 double compute(double source, double length) { return update(source, length, false); }
509 double recompute(double source, double length) { return update(source, length, true); }
510 void observe_owned_storage(OwnedStorage& out) const noexcept {
511 core_.observe_owned_storage(out);
512 }
513
514private:
515 double update(double source, double length, bool replace) {
516 return core_.update("percentrank", source, length, 1, replace,
517 [](ta::PercentRank& window, double src, bool again) {
518 return again ? window.recompute(src) : window.compute(src);
519 });
520 }
521
522 series_stats_detail::EveryCall<ta::PercentRank> core_;
523};
524
525// ta.percentile_linear_interpolation(source, length, percentage) with a
526// series length. The percentage is taken on each call, before the length.
528public:
530 explicit SeriesPercentileLinear(WindowCacheCapacity cache) : core_(cache) {}
533 double compute(double source, double percentage, double length) {
534 return update(source, percentage, length, false);
535 }
536 double recompute(double source, double percentage, double length) {
537 return update(source, percentage, length, true);
538 }
539 void observe_owned_storage(OwnedStorage& out) const noexcept {
540 core_.observe_owned_storage(out);
541 }
542
543private:
544 double update(double source, double percentage, double length, bool replace) {
545 // The window's state does not depend on the percentage, so a replayed
546 // call may carry the current one.
547 return core_.update(
548 "percentile_linear_interpolation", source, length, 0, replace,
549 [percentage](ta::PercentileLinearInterpolation& window, double src, bool again) {
550 return again ? window.recompute(src, percentage)
551 : window.compute(src, percentage);
552 });
553 }
554
555 series_stats_detail::EveryCall<ta::PercentileLinearInterpolation> core_;
556};
557
558// ta.correlation(source1, source2, length) with a series length: every call
559// records its pair, na included, and the window is the last `length` pairs.
561public:
564 : first_(cache, series_stats_detail::retained_inputs(max_lookback_)),
565 second_(cache, series_stats_detail::retained_inputs(max_lookback_)) {}
568 double compute(double source1, double source2, double length) {
569 return update(source1, source2, length, false);
570 }
571 double recompute(double source1, double source2, double length) {
572 return update(source1, source2, length, true);
573 }
574 void observe_owned_storage(OwnedStorage& out) const noexcept {
575 ::pineforge::observe_owned_members(out, first_, second_, window_);
576 }
577
578private:
579 double update(double source1, double source2, double length, bool replace) {
580 const std::uint64_t requested =
581 series_stats_detail::checked_length(length, "correlation", max_lookback_);
582 const bool again = replace && called_;
583 if (again) {
584 first_.replace_back(source1);
585 second_.replace_back(source2);
586 } else {
587 first_.append(source1);
588 second_.append(source2);
589 }
590 called_ = true;
591 if (requested > first_.size()) {
592 window_.reset();
593 return na<double>();
594 }
595 // While a window exists, its last call is this site's last call.
596 if (window_ && window_length_ == requested)
597 return again ? window_->recompute(source1, source2)
598 : window_->compute(source1, source2);
599 window_.emplace(series_stats_detail::fixed_length(requested));
600 window_length_ = requested;
601 for (std::size_t back = static_cast<std::size_t>(requested) - 1; back != 0; --back)
602 window_->compute(first_.from_back(back), second_.from_back(back));
603 return window_->compute(source1, source2);
604 }
605
606 std::int64_t max_lookback_ = ::pineforge::detail::ta_lookback_limit();
607 series_stats_detail::Inputs first_;
608 series_stats_detail::Inputs second_;
609 std::optional<ta::Correlation> window_;
610 std::uint64_t window_length_ = 0;
611 bool called_ = false;
612};
613
614} // namespace source
615} // namespace pineforge
616
617// Feature macros: one per class above.
618#define PINEFORGE_HAS_PINE_SERIES_STDEV 1
619#define PINEFORGE_HAS_PINE_SERIES_VARIANCE 1
620#define PINEFORGE_HAS_PINE_SERIES_DEV 1
621#define PINEFORGE_HAS_PINE_SERIES_RANGE 1
622#define PINEFORGE_HAS_PINE_SERIES_MEDIAN 1
623#define PINEFORGE_HAS_PINE_SERIES_MODE 1
624#define PINEFORGE_HAS_PINE_SERIES_PERCENTRANK 1
625#define PINEFORGE_HAS_PINE_SERIES_PERCENTILELINEAR 1
626#define PINEFORGE_HAS_PINE_SERIES_CORRELATION 1
627#define PINEFORGE_HAS_PINE_SERIES_MATHSUM 1
628// The two names of more than one word, also spelled with the word break the
629// other feature macros of this layer use.
630#define PINEFORGE_HAS_PINE_SERIES_PERCENTILE_LINEAR 1
631#define PINEFORGE_HAS_PINE_SERIES_MATH_SUM 1
std::size_t size() const
Definition series.hpp:188
WindowCacheCapacity cache_capacity() const
Definition series.hpp:189
static constexpr std::size_t kChunk
Definition series.hpp:78
T read(std::size_t index) const
Definition series.hpp:138
double recompute(double source1, double source2, double length)
SeriesCorrelation & operator=(const SeriesCorrelation &)=default
double compute(double source1, double source2, double length)
SeriesCorrelation(const SeriesCorrelation &)=default
void observe_owned_storage(OwnedStorage &out) const noexcept
SeriesDev & operator=(const SeriesDev &)=default
double recompute(double source, double length)
double compute(double source, double length)
SeriesDev(const SeriesDev &)=default
void observe_owned_storage(OwnedStorage &out) const noexcept
SeriesDev(WindowCacheCapacity cache)
SeriesMathSum & operator=(const SeriesMathSum &)=default
double compute(double source, double length)
SeriesMathSum(WindowCacheCapacity cache)
SeriesMathSum(const SeriesMathSum &)=default
double recompute(double source, double length)
void observe_owned_storage(OwnedStorage &out) const noexcept
double recompute(double source, double length)
SeriesMedian(WindowCacheCapacity cache)
SeriesMedian(const SeriesMedian &)=default
SeriesMedian & operator=(const SeriesMedian &)=default
void observe_owned_storage(OwnedStorage &out) const noexcept
double compute(double source, double length)
void observe_owned_storage(OwnedStorage &out) const noexcept
SeriesMode(WindowCacheCapacity cache)
SeriesMode(const SeriesMode &)=default
double recompute(double source, double length)
double compute(double source, double length)
SeriesMode & operator=(const SeriesMode &)=default
void observe_owned_storage(OwnedStorage &out) const noexcept
double compute(double source, double percentage, double length)
SeriesPercentileLinear & operator=(const SeriesPercentileLinear &)=default
SeriesPercentileLinear(const SeriesPercentileLinear &)=default
double recompute(double source, double percentage, double length)
SeriesPercentrank(const SeriesPercentrank &)=default
double compute(double source, double length)
double recompute(double source, double length)
void observe_owned_storage(OwnedStorage &out) const noexcept
SeriesPercentrank & operator=(const SeriesPercentrank &)=default
void observe_owned_storage(OwnedStorage &out) const noexcept
double compute(double source, double length)
double recompute(double source, double length)
SeriesRange(const SeriesRange &)=default
SeriesRange & operator=(const SeriesRange &)=default
SeriesRange(WindowCacheCapacity cache)
SeriesStdev & operator=(const SeriesStdev &)=default
SeriesStdev(const SeriesStdev &)=default
SeriesStdev(WindowCacheCapacity cache)
double recompute(double source, bool biased, double length)
double recompute(double source, double length)
void observe_owned_storage(OwnedStorage &out) const noexcept
double compute(double source, double length)
double compute(double source, bool biased, double length)
double recompute(double source, bool biased, double length)
void observe_owned_storage(OwnedStorage &out) const noexcept
SeriesVariance(const SeriesVariance &)=default
SeriesVariance & operator=(const SeriesVariance &)=default
SeriesVariance(WindowCacheCapacity cache)
double compute(double source, double length)
double compute(double source, bool biased, double length)
double recompute(double source, double length)
EveryCall & operator=(const EveryCall &)=default
void observe_owned_storage(OwnedStorage &out) const noexcept
double update(const char *function, double source, double length, std::size_t extra, bool replace, Step step)
void observe_owned_storage(OwnedStorage &out) const noexcept
Inputs(WindowCacheCapacity cache, std::size_t keep)
Inputs & operator=(const Inputs &)=default
void observe_owned_storage(OwnedStorage &out) const noexcept
ValidSources & operator=(const ValidSources &)=default
double update(const char *function, double source, double length, bool option, bool replace)
void observe_owned_storage(OwnedStorage &out) const noexcept
double compute(double src)
double recompute(double src)
double recompute(double src, double percentage)
double compute(double src, double percentage)
std::int64_t ta_lookback_limit() noexcept
std::size_t retained_inputs(std::int64_t maximum)
std::uint64_t checked_length(double length, const char *function, std::int64_t maximum)
void build_window(std::optional< Window > &window, int length, bool option)
void stop_for_lookback(std::uint64_t offset, std::int64_t maximum, bool beyond_uint64)
void stop_for_length(double value, const char *function)
int simple_ta_length(double value, const char *function, const char *argument)
double na< double >()
Definition na.hpp:64
void pine_limit_stop(const char *limit, std::int64_t max, const char *english)
bool is_na(const Line &h)
Definition drawing.hpp:58
WindowCacheCapacity & window_cache_capacity()
Definition series.hpp:40
std::string run_error_bar_prefix()
Stops using TradingView's text prepend "Error on bar N: " when a bar context is installed,...
T na()
Definition na.hpp:54
void pine_engine_invariant(const char *english)
void observe_owned_members(OwnedStorage &out, const T &... values) noexcept