PineForge unreleased
Deterministic PineScript v6 backtest runtime — C ABI reference
Loading...
Searching...
No Matches
pine_ta_flat_range.hpp
Go to the documentation of this file.
1#pragma once
2// Pine's ta.wvad and ta.iii on a bar whose high equals its low.
3//
4// Both built-ins divide by the bar's range:
5//
6// ta.wvad = (close - open) / (high - low) * volume
7// ta.iii = (2 * close - high - low) / (high - low) * volume
8//
9// The kernel classes ta::WVAD and ta::III (<pineforge/ta.hpp>) answer 0 on a
10// bar with no range, a native convention their own tests pin. The Pine
11// expressions carry no such branch: on a flat bar (open = high = low = close)
12// they are 0 / 0, which Pine reads as na, while a bar with a range whose
13// numerator is zero (close equal to open, or close at the middle of the
14// range) is a genuine 0. These adapters answer na when high equals low and
15// delegate every other bar to the kernel class, so the values off a flat bar
16// are the kernel's own, bit for bit, and a missing input is na as before.
17//
18// Not pinned by TradingView values yet: the na on a flat bar is read from the
19// expressions above. A bar whose range is zero while its numerator is not
20// (a close away from an open that equals high and low: not a valid candle)
21// also answers na here; the bare expression would be an infinity there.
22//
23// Neither class keeps state: recompute() is compute().
24#include <pineforge/ta.hpp>
25#include <pineforge/na.hpp>
26
27namespace pineforge {
28namespace source {
29
30class PineWvad {
31 ta::WVAD impl_;
32
33public:
34 double compute(double open, double high, double low, double close, double volume) {
35 if (high == low) return na<double>();
36 return impl_.compute(open, high, low, close, volume);
37 }
38 double recompute(double open, double high, double low, double close, double volume) {
39 return compute(open, high, low, close, volume);
40 }
41 // No retained fields.
42 void observe_owned_storage(OwnedStorage&) const noexcept {}
43};
44
45class PineIii {
46 ta::III impl_;
47
48public:
49 double compute(double high, double low, double close, double volume) {
50 if (high == low) return na<double>();
51 return impl_.compute(high, low, close, volume);
52 }
53 double recompute(double high, double low, double close, double volume) {
54 return compute(high, low, close, volume);
55 }
56 // No retained fields.
57 void observe_owned_storage(OwnedStorage&) const noexcept {}
58};
59
60} // namespace source
61} // namespace pineforge
62
63// Feature macro: the classes above exist.
64#define PINEFORGE_HAS_PINE_FLAT_RANGE 1
double recompute(double high, double low, double close, double volume)
void observe_owned_storage(OwnedStorage &) const noexcept
double compute(double high, double low, double close, double volume)
double recompute(double open, double high, double low, double close, double volume)
void observe_owned_storage(OwnedStorage &) const noexcept
double compute(double open, double high, double low, double close, double volume)
double na< double >()
Definition na.hpp:64