pub trait OHLCV: 'static {
Show 16 methods
// Required methods
fn open(&self) -> ValueType;
fn high(&self) -> ValueType;
fn low(&self) -> ValueType;
fn close(&self) -> ValueType;
fn volume(&self) -> ValueType;
// Provided methods
fn tp(&self) -> ValueType { ... }
fn hl2(&self) -> ValueType { ... }
fn ohlc4(&self) -> ValueType { ... }
fn clv(&self) -> ValueType { ... }
fn tr(&self, prev_candle: &dyn OHLCV) -> ValueType { ... }
fn tr_close(&self, prev_close: ValueType) -> ValueType { ... }
fn validate(&self) -> bool { ... }
fn source(&self, source: Source) -> ValueType { ... }
fn volumed_price(&self) -> ValueType { ... }
fn is_rising(&self) -> bool { ... }
fn is_falling(&self) -> bool { ... }
}
Expand description
Basic trait for implementing Open-High-Low-Close-Volume timeseries data.
It has already implemented for tuple of 5 float values:
use yata::prelude::OHLCV;
// open high low close, volume
let row = (2.0, 5.0, 1.0, 4.0, 10.0 );
assert_eq!(row.open(), row.0);
assert_eq!(row.high(), row.1);
assert_eq!(row.low(), row.2);
assert_eq!(row.close(), row.3);
assert_eq!(row.volume(), row.4);
See also Candle.
Required Methods§
Provided Methods§
sourcefn tp(&self) -> ValueType
fn tp(&self) -> ValueType
Calculates Typical price.
It’s just a simple (High
+ Low
+ Close
) / 3
§Examples
use yata::prelude::*;
use yata::core::Candle;
let candle = Candle {
high: 10.0,
low: 5.0,
close: 9.0,
..Candle::default()
};
assert_eq!(candle.tp(), 8.0);
sourcefn hl2(&self) -> ValueType
fn hl2(&self) -> ValueType
Calculates arithmetic average of high
and low
values of the candle
§Examples
use yata::prelude::*;
use yata::core::Candle;
let candle = Candle {
high: 10.0,
low: 5.0,
..Candle::default()
};
assert_eq!(candle.hl2(), 7.5);
sourcefn ohlc4(&self) -> ValueType
fn ohlc4(&self) -> ValueType
Calculates arithmetic average of high
, low
, open
and close
values of the candle
§Examples
use yata::prelude::*;
use yata::core::Candle;
let candle = Candle {
high: 10.0,
low: 5.0,
open: 2.0,
close: 3.0,
..Candle::default()
};
assert_eq!(candle.ohlc4(), 5.0);
sourcefn clv(&self) -> ValueType
fn clv(&self) -> ValueType
CLV = [(close - low) - (high - close)] / (high - low)
§Examples
use yata::prelude::*;
use yata::core::Candle;
let candle = Candle {
high: 5.0,
low: 2.0,
close: 4.0,
..Candle::default()
};
assert_eq!(candle.clv(), ((candle.close()-candle.low()) - (candle.high() - candle.close()))/(candle.high() - candle.low()));
assert_eq!(candle.clv(), ((4. - 2.) - (5. - 4.))/(5. - 2.));
sourcefn tr(&self, prev_candle: &dyn OHLCV) -> ValueType
fn tr(&self, prev_candle: &dyn OHLCV) -> ValueType
Calculates True Range over last two candles
§Examples
use yata::prelude::*;
use yata::core::Candle;
let candle1 = Candle {
close: 70.0,
..Candle::default()
};
let candle2 = Candle {
high: 100.0,
low: 50.0,
..Candle::default()
};
let tr = candle2.tr(&candle1);
assert_eq!(tr, 50.);
use yata::prelude::*;
use yata::core::Candle;
let candle1 = Candle {
close: 30.0,
..Candle::default()
};
let candle2 = Candle {
high: 100.0,
low: 50.0,
..Candle::default()
};
let tr = candle2.tr(&candle1);
assert_eq!(tr, 70.);
sourcefn tr_close(&self, prev_close: ValueType) -> ValueType
fn tr_close(&self, prev_close: ValueType) -> ValueType
Calculates True Range over last two candles using close
price from the previous candle.
sourcefn validate(&self) -> bool
fn validate(&self) -> bool
Validates candle attributes
Returns true
if validates OK
§Examples
use yata::prelude::*;
use yata::core::Candle;
let candle1 = Candle {
open: 7.0,
high: 10.0,
low: 7.0,
close: 11.0, // cannot be more than high
..Candle::default()
};
let candle2 = Candle {
open: 10.0,
high: 10.0,
low: 11.0, // low cannot be more than any other value of the candle
close: 10.0,
..Candle::default()
};
assert!(!candle1.validate());
assert!(!candle2.validate());
sourcefn source(&self, source: Source) -> ValueType
fn source(&self, source: Source) -> ValueType
Returns Source
field value of the candle.
§Examples
use yata::prelude::*;
use yata::core::{Candle, Source};
let candle = Candle {
open: 12.0,
high: 15.0,
low: 7.0,
close: 10.0,
..Candle::default()
};
assert_eq!(OHLCV::source(&candle, Source::Low), 7.0);
assert_eq!(OHLCV::source(&candle, "close".to_string().parse().unwrap()), 10.0);
sourcefn volumed_price(&self) -> ValueType
fn volumed_price(&self) -> ValueType
Volumed price
Same as OHLCV::tp()
* OHLCV::volume()
sourcefn is_rising(&self) -> bool
fn is_rising(&self) -> bool
Checks if candle is “rising”: it’s close value greater than open value
sourcefn is_falling(&self) -> bool
fn is_falling(&self) -> bool
Checks if candle is “falling”: it’s close value smaller than open value