Skip to main content

TurtlePyramidState

Struct TurtlePyramidState 

Source
pub struct TurtlePyramidState {
    pub units: Vec<TurtleUnit>,
    pub direction: TradeDirection,
    pub entry_atr: f64,
    pub max_units: u8,
}
Expand description

State for a Turtle Trading pyramid position (up to max_units units).

The classic Turtle system adds a new unit each time price moves 0.5 ATR from the last entry, up to a maximum of 4 units. The stop for the entire position is placed at 2N (2 × entry ATR) below the lowest unit entry for longs, or above the highest unit entry for shorts.

Fields§

§units: Vec<TurtleUnit>§direction: TradeDirection§entry_atr: f64

ATR at the time of the first entry.

§max_units: u8

Maximum number of units allowed (default 4).

Implementations§

Source§

impl TurtlePyramidState

Source

pub fn new( direction: TradeDirection, entry_price: f64, size: f64, atr: f64, ) -> Self

Create a new pyramid with the first unit.

Source

pub fn should_add_unit(&self, current_price: f64) -> bool

Whether price has moved 0.5 ATR from the last entry in the direction of the trade, indicating we should add another unit.

Source

pub fn add_unit(&mut self, entry_price: f64, size: f64)

Add a new unit to the pyramid.

Does nothing if the pyramid is already full.

Source

pub fn stop_price(&self) -> f64

Compute the stop price for the entire position.

  • Long: lowest_entry − 2 × entry_atr
  • Short: highest_entry + 2 × entry_atr
Source

pub fn average_entry(&self) -> f64

Weighted average entry price across all units.

Source

pub fn total_size(&self) -> f64

Total size across all units.

Source

pub fn is_full(&self) -> bool

Whether the pyramid is at its maximum number of units.

Trait Implementations§

Source§

impl Clone for TurtlePyramidState

Source§

fn clone(&self) -> TurtlePyramidState

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for TurtlePyramidState

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for TurtlePyramidState

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for TurtlePyramidState

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,