Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/pine-builtins/src/ta/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,8 @@ fn step_series<O: PineOutput>(series: &mut Value<O>, push: bool, next: f64) {
if let Value::Series(s) = series {
if push {
if let Some(history) = &s.history {
let mut history = history.borrow_mut();
history.push((*s.current).clone(), MAX_LOOKBACK);
let previous = s.current.as_number().unwrap_or(f64::NAN);
history.borrow_mut().push(previous, MAX_LOOKBACK);
}
}
*s.current = Value::Number(next);
Expand Down
7 changes: 5 additions & 2 deletions crates/pine-interpreter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct Variable<O: PineOutput = DefaultPineOutput> {
pub struct Series<O: PineOutput = DefaultPineOutput> {
pub id: String,
pub current: Box<Value<O>>,
pub history: Option<Rc<RefCell<SeriesBuffer<Value<O>>>>>,
pub history: Option<Rc<RefCell<SeriesBuffer<f64>>>>,
}

/// The lazy scalar an object carries, so a single name can be *both* a namespace
Expand Down Expand Up @@ -1526,7 +1526,10 @@ impl<O: PineOutput> Interpreter<O> {
return Ok((*series.current).clone());
}
let h = history.borrow();
return Ok(h.get(index_val - 1).cloned().unwrap_or(Value::Na));
return Ok(match h.get(index_val - 1) {
Some(x) if !x.is_nan() => Value::Number(*x),
_ => Value::Na,
});
}
}

Expand Down
Loading