OpenPine C++ API
C++ wrapper for the OpenPine Pine Script VM
Loading...
Searching...
No Matches
plot_candle.hpp
Go to the documentation of this file.
1#pragma once
2
7
8#if (defined(_MSVC_LANG) ? _MSVC_LANG : __cplusplus) < 201703L
9#error \
10 "OpenPine C++ wrapper headers require C++17 (std::optional, std::string_view)."
11#endif
12
13#include <cstdint>
14#include <optional>
15#include <string_view>
16
17#include "../display.hpp"
18#include "../ffi.hpp"
19#include "../string_ref.hpp"
20
21namespace openpine {
22namespace seriesgraph {
23
28 private:
29 const ffi::PlotCandle* p_;
30
31 public:
32 PlotCandle(const ffi::PlotCandle* p) : p_(p) {}
33
38 std::optional<std::string_view> title() const {
39 ffi::PineStringRef ref;
40 if (ffi::plotCandleTitle(p_, &ref)) {
41 return detail::refToView(ref);
42 } else {
43 return std::nullopt;
44 }
45 }
46
50 std::optional<ffi::Bar> value(uintptr_t idx) const {
51 ffi::Bar v;
52 if (ffi::plotCandleValue(p_, idx, &v)) {
53 return v;
54 } else {
55 return std::nullopt;
56 }
57 }
58
62 std::optional<uint32_t> color(uintptr_t idx) const {
63 uint32_t col;
64 if (ffi::plotCandleColor(p_, idx, &col)) {
65 return col;
66 } else {
67 return std::nullopt;
68 }
69 }
70
74 std::optional<uint32_t> wickColor(uintptr_t idx) const {
75 uint32_t col;
76 if (ffi::plotCandleWickColor(p_, idx, &col)) {
77 return col;
78 } else {
79 return std::nullopt;
80 }
81 }
82
86 std::optional<uint32_t> borderColor(uintptr_t idx) const {
87 uint32_t col;
88 if (ffi::plotCandleBorderColor(p_, idx, &col)) {
89 return col;
90 } else {
91 return std::nullopt;
92 }
93 }
94
98 bool editable() const { return ffi::plotCandleEditable(p_); }
99
103 std::optional<uintptr_t> showLast() const {
104 uintptr_t v;
105 if (ffi::plotCandleShowLast(p_, &v)) {
106 return v;
107 } else {
108 return std::nullopt;
109 }
110 }
111
115 Display display() const { return Display(ffi::plotCandleDisplay(p_)); }
116
120 std::optional<std::string_view> format() const {
121 ffi::PineStringRef ref;
122 if (ffi::plotCandleFormat(p_, &ref)) {
123 return detail::refToView(ref);
124 } else {
125 return std::nullopt;
126 }
127 }
128
132 std::optional<int32_t> precision() const {
133 int32_t v;
134 if (ffi::plotCandlePrecision(p_, &v)) {
135 return v;
136 } else {
137 return std::nullopt;
138 }
139 }
140
144 bool forceOverlay() const { return ffi::plotCandleForceOverlay(p_); }
145};
146
147} // namespace seriesgraph
148} // namespace openpine
A type-safe display bitmask.
Definition display.hpp:25
Display display() const
Gets the display bitmask.
std::optional< std::string_view > title() const
Gets the title.
PlotCandle(const ffi::PlotCandle *p)
std::optional< uint32_t > wickColor(uintptr_t idx) const
Gets the wick color at the specified index.
std::optional< int32_t > precision() const
Gets the optional decimal precision.
bool forceOverlay() const
Gets whether the plot-candle is forced to render as overlay.
std::optional< uintptr_t > showLast() const
Gets the show_last value, if set.
std::optional< uint32_t > borderColor(uintptr_t idx) const
Gets the border color at the specified index.
bool editable() const
Returns whether the plot-candle is editable.
std::optional< ffi::Bar > value(uintptr_t idx) const
Gets the OHLC bar at the specified index.
std::optional< uint32_t > color(uintptr_t idx) const
Gets the body color at the specified index.
std::optional< std::string_view > format() const
Gets the optional formatting hint.
Type-safe wrappers for display bitmasks used by visuals.
std::string_view refToView(const ffi::PineStringRef &ref)
Shared helpers for converting C ABI string refs to std::string_view.