Skip to content

Commit c648e2a

Browse files
authored
Improve SMA indicator parity with Cython (#2655)
1 parent c9a339a commit c648e2a

File tree

2 files changed

+242
-51
lines changed

2 files changed

+242
-51
lines changed

crates/indicators/src/average/rma.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,14 @@ impl Indicator for WilderMovingAverage {
5656
self.initialized
5757
}
5858

59-
fn handle_quote(&mut self, q: &QuoteTick) {
60-
self.update_raw(q.extract_price(self.price_type).into());
59+
fn handle_quote(&mut self, quote: &QuoteTick) {
60+
self.update_raw(quote.extract_price(self.price_type).into());
6161
}
62+
6263
fn handle_trade(&mut self, t: &TradeTick) {
6364
self.update_raw((&t.price).into());
6465
}
66+
6567
fn handle_bar(&mut self, b: &Bar) {
6668
self.update_raw((&b.close).into());
6769
}
@@ -85,7 +87,10 @@ impl WilderMovingAverage {
8587
// The Wilder Moving Average is The Wilder's Moving Average is simply
8688
// an Exponential Moving Average (EMA) with a modified alpha.
8789
// alpha = 1 / period
88-
assert!(period > 0, "WilderMovingAverage: period must be > 0");
90+
assert!(
91+
period > 0,
92+
"WilderMovingAverage: period must be > 0 (received {period})"
93+
);
8994
Self {
9095
period,
9196
price_type: price_type.unwrap_or(PriceType::Last),

0 commit comments

Comments
 (0)