pub struct Interpreter<O: PineOutput> {
pub output: O,
pub user_series_history: HashMap<String, Vec<Value<O>>>,
pub broker: Option<Box<dyn Broker>>,
pub request_provider: Option<Rc<dyn DataProvider>>,
pub chart_period: Option<i64>,
/* private fields */
}Expand description
The interpreter executes a program with a given bar
Fields§
§output: OOutput storage for plots, labels, logs, etc.
user_series_history: HashMap<String, Vec<Value<O>>>Per-variable history for user-computed series (var declarations).
history[len-1] = previous bar, history[len-2] = two bars ago, etc.
Populated on each Stmt::Assignment; supports Pine’s name[n] lookback.
broker: Option<Box<dyn Broker>>The simulated broker a strategy script trades against. None for an
indicator. The strategy.* order builtins reach it through ctx.
request_provider: Option<Rc<dyn DataProvider>>The feed request.security draws other symbols/timeframes from, and the
chart’s bar spacing in ms (for request.security_lower_tf). None when
no host provider is set. The request.* builtins reach these through
ctx, the same way strategy.* reaches the broker.
chart_period: Option<i64>Implementations§
Source§impl<O: PineOutput> Interpreter<O>
impl<O: PineOutput> Interpreter<O>
pub fn new() -> Self
Sourcepub fn bar_seq(&self) -> u64
pub fn bar_seq(&self) -> u64
How many bars have been executed. A stateful builtin advances its state when this differs from the value it last saw.
Sourcepub fn set_library_loader(&mut self, library_loader: Box<dyn LibraryLoader>)
pub fn set_library_loader(&mut self, library_loader: Box<dyn LibraryLoader>)
Set the library loader
Sourcepub fn snapshot(&self) -> HashMap<String, Value<O>>
pub fn snapshot(&self) -> HashMap<String, Value<O>>
A copy of every defined variable’s value, so a secondary interpreter
(request.security) can start from the same namespaces and builtins
without re-registering them.
Sourcepub fn exports(&self) -> &HashMap<String, Value<O>>
pub fn exports(&self) -> &HashMap<String, Value<O>>
Get the exported items from this interpreter (for library mode)
Sourcepub fn execute(&mut self, program: &Program) -> Result<O, RuntimeError>
pub fn execute(&mut self, program: &Program) -> Result<O, RuntimeError>
Execute a program with a single bar
Sourcepub fn get_variable(&self, name: &str) -> Option<&Value<O>>
pub fn get_variable(&self, name: &str) -> Option<&Value<O>>
Get a variable value
Sourcepub fn set_variable(&mut self, name: &str, value: Value<O>)
pub fn set_variable(&mut self, name: &str, value: Value<O>)
Set a variable value (useful for loading objects and test setup)
Sourcepub fn advance_series(&mut self, name: &str, value: Value<O>)
pub fn advance_series(&mut self, name: &str, value: Value<O>)
Set a built-in series to its value for a new bar, keeping the outgoing
value reachable as name[1].
This is how the OHLCV series and their derivations get the same lookback
as any user variable: history accumulates as bars execute, so close[1]
is na until a second bar has run.
Sourcepub fn set_object_field(&mut self, object: &str, field: &str, value: Value<O>)
pub fn set_object_field(&mut self, object: &str, field: &str, value: Value<O>)
Set a field on a namespace object (e.g. strategy.position_size),
leaving the object’s other fields untouched. A no-op if object is not
a registered namespace object.
Sourcepub fn set_const_variable(&mut self, name: &str, value: Value<O>)
pub fn set_const_variable(&mut self, name: &str, value: Value<O>)
Set a const variable (cannot be reassigned)