[][src]Trait yata::core::OHLCV

pub trait OHLCV {
    pub fn open(&self) -> ValueType;
pub fn high(&self) -> ValueType;
pub fn low(&self) -> ValueType;
pub fn close(&self) -> ValueType;
pub fn volume(&self) -> ValueType; pub fn tp(&self) -> ValueType { ... }
pub fn hl2(&self) -> ValueType { ... }
pub fn ohlc4(&self) -> ValueType { ... }
pub fn clv(&self) -> ValueType { ... }
pub fn tr(&self, prev_candle: &dyn OHLCV) -> ValueType { ... }
pub fn tr_close(&self, prev_close: ValueType) -> ValueType { ... }
pub fn validate(&self) -> bool { ... }
pub fn source(&self, source: Source) -> ValueType { ... }
pub fn volumed_price(&self) -> ValueType { ... } }

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

pub fn open(&self) -> ValueType[src]

Should return an open value of the period

pub fn high(&self) -> ValueType[src]

Should return an highest value of the period

pub fn low(&self) -> ValueType[src]

Should return an lowest value of the period

pub fn close(&self) -> ValueType[src]

Should return an close value of the candle

pub fn volume(&self) -> ValueType[src]

Should return volume value for the period

Loading content...

Provided methods

pub fn tp(&self) -> ValueType[src]

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);

pub fn hl2(&self) -> ValueType[src]

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);

pub fn ohlc4(&self) -> ValueType[src]

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);

pub fn clv(&self) -> ValueType[src]

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.));

pub fn tr(&self, prev_candle: &dyn OHLCV) -> ValueType[src]

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.);

pub fn tr_close(&self, prev_close: ValueType) -> ValueType[src]

Calculates True Range over last two candles using close price from the previous candle.

pub fn validate(&self) -> bool[src]

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());

pub fn source(&self, source: Source) -> ValueType[src]

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);

pub fn volumed_price(&self) -> ValueType[src]

Volumed price

Same as OHLCV::tp() * OHLCV::volume()

Loading content...

Implementations on Foreign Types

impl OHLCV for (ValueType, ValueType, ValueType, ValueType, ValueType)[src]

impl OHLCV for [ValueType; 5][src]

impl<T: OHLCV> OHLCV for &T[src]

Loading content...

Implementors

impl OHLCV for Candle[src]

Loading content...