Expand description
Condition system for building strategy entry/exit rules.
This module provides a composable way to define trading conditions using indicator references and comparison operations.
§Example
ⓘ
use finance_query::backtesting::refs::*;
use finance_query::backtesting::condition::*;
// Simple condition
let oversold = rsi(14).below(30.0);
// Compound conditions
let entry = rsi(14).crosses_below(30.0)
.and(price().above_ref(sma(200)));
let exit = rsi(14).crosses_above(70.0)
.or(stop_loss(0.05));Structs§
- Above
- Condition: indicator is above a threshold.
- Above
Ref - Condition: indicator is above another indicator.
- All
- A condition that evaluates to true when ALL inner conditions are true.
- And
- Condition: both conditions must be true (AND logic).
- Any
- A condition that evaluates to true when ANY inner condition is true.
- Below
- Condition: indicator is below a threshold.
- Below
Ref - Condition: indicator is below another indicator.
- Between
- Condition: indicator is between two thresholds.
- Condition
Builder - Builder for creating complex multi-condition combinations.
- Constant
Condition - A condition that always returns the same value.
- Crosses
Above - Condition: indicator crosses above a threshold.
- Crosses
Above Ref - Condition: indicator crosses above another indicator.
- Crosses
Below - Condition: indicator crosses below a threshold.
- Crosses
Below Ref - Condition: indicator crosses below another indicator.
- Equals
- Condition: indicator equals a value (within tolerance).
- HasPosition
- Condition: check if we have any position.
- Held
ForBars - Condition: position has been held for at least N bars.
- InLoss
- Condition: position P/L is negative (in loss).
- InProfit
- Condition: position P/L is positive (in profit).
- IsLong
- Condition: check if we have a long position.
- IsShort
- Condition: check if we have a short position.
- NoPosition
- Condition: check if we have no position.
- Not
- Condition: negation of a condition (NOT logic).
- Or
- Condition: at least one condition must be true (OR logic).
- Stop
Loss - Condition: position P/L is at or below the stop-loss threshold.
- Take
Profit - Condition: position P/L is at or above the take-profit threshold.
- Trailing
Stop - Condition: trailing stop triggered when price retraces from peak/trough.
- Trailing
Take Profit - Condition: trailing take-profit triggered when profit retraces from peak.
Traits§
- Condition
- A condition that can be evaluated on each candle.
Functions§
- always_
false - Convenience function to create a condition that always returns false.
- always_
true - Convenience function to create a condition that always returns true.
- has_
position - Create a condition that checks if we have any position.
- held_
for_ bars - Create a condition that checks if position has been held for at least N bars.
- in_loss
- Create a condition that checks if position is at a loss.
- in_
profit - Create a condition that checks if position is profitable.
- is_long
- Create a condition that checks if we have a long position.
- is_
short - Create a condition that checks if we have a short position.
- no_
position - Create a condition that checks if we have no position.
- stop_
loss - Create a stop-loss condition.
- take_
profit - Create a take-profit condition.
- trailing_
stop - Create a trailing stop condition.
- trailing_
take_ profit - Create a trailing take-profit condition.