openpine_vm/visuals/
plotbar.rs

1use openpine_compiler::instructions::Color;
2use serde::{Deserialize, Serialize};
3
4use crate::{
5    series::Series,
6    visuals::{PlotDisplay, PlotFormat},
7};
8
9/// OHLC bar data.
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct Bar {
12    /// Open price.
13    pub open: f64,
14    /// High price.
15    pub high: f64,
16    /// Low price.
17    pub low: f64,
18    /// Close price.
19    pub close: f64,
20}
21
22/// Plot bar (custom bar) series.
23#[derive(Debug, Clone, Serialize, Deserialize)]
24pub struct PlotBar {
25    /// Plot title (`None` when the caller did not supply one).
26    pub title: Option<String>,
27    /// Per-bar OHLC values.
28    pub series: Series<Option<Bar>>,
29    /// Per-bar color.
30    pub colors: Series<Option<Color>>,
31    /// Whether the plot is user-editable.
32    pub editable: bool,
33    /// Optional limit for the number of visible bars.
34    pub show_last: Option<usize>,
35    /// Display targets.
36    pub display: PlotDisplay,
37    /// Optional formatting hint.
38    pub format: Option<PlotFormat>,
39    /// Optional decimal precision.
40    pub precision: Option<i32>,
41    /// Whether to force overlay rendering.
42    pub force_overlay: bool,
43}
44
45impl PlotBar {
46    pub(crate) fn append_new(&mut self) {
47        self.series.append_new();
48        self.colors.append_new();
49    }
50}