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: f64ATR at the time of the first entry.
max_units: u8Maximum number of units allowed (default 4).
Implementations§
Source§impl TurtlePyramidState
impl TurtlePyramidState
Sourcepub fn new(
direction: TradeDirection,
entry_price: f64,
size: f64,
atr: f64,
) -> Self
pub fn new( direction: TradeDirection, entry_price: f64, size: f64, atr: f64, ) -> Self
Create a new pyramid with the first unit.
Sourcepub fn should_add_unit(&self, current_price: f64) -> bool
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.
Sourcepub fn add_unit(&mut self, entry_price: f64, size: f64)
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.
Sourcepub fn stop_price(&self) -> f64
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
Sourcepub fn average_entry(&self) -> f64
pub fn average_entry(&self) -> f64
Weighted average entry price across all units.
Sourcepub fn total_size(&self) -> f64
pub fn total_size(&self) -> f64
Total size across all units.
Trait Implementations§
Source§impl Clone for TurtlePyramidState
impl Clone for TurtlePyramidState
Source§fn clone(&self) -> TurtlePyramidState
fn clone(&self) -> TurtlePyramidState
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more