1 of 3
5 min read

Custom Expressions

Build complex logic beyond preset conditions

Expressions Editor

The expressions editor lets you create complex trading conditions that go beyond simple preset rules. Use it when you need custom logic that combines multiple factors or calculations.

Expression Editor

When to Use Expressions

💡 Example:
Simple rules handle basic conditions like "profit >= $100" or "time >= 30 minutes" Expressions handle complex logic like:
  • "(profit >= $50 AND time >= 60 minutes) OR loss >= $200"
  • "Close when position delta is within 10% of being neutral"
  • "Exit if current P&L drops more than 50% from the peak"

How the Editor Works

The expressions editor uses building blocks that you combine to create your condition:

Main Components

Condition Groups: Combine multiple conditions with AND/OR logic

  • Click the "+ condition" button to add more conditions
  • Click the "+ group" button to add a new condition group
  • Clicking on condition group badge toggles between AND/OR logic
    • Choose "All of is true" when all conditions must be true
    • Choose "Any of is true" when any condition can trigger the rule
  • You can nest condition groups

Individual Conditions: Basic comparisons like "profit >= $100"

  • Left side and right side: Choose a variable, a constant or a function.
  • Operator: Choose comparison (>=, <=, ==, !=, >, <) to compare left to right expressions.

Variables: References to your strategy data

  • Position P&L, Greeks, time in trade
  • Market data like VIX levels
  • Custom calculations you create

Learn more

Functions: Built-in calculations

  • ABS: Absolute value
  • MIN, MAX: Minimum/maximum values
  • Math operations: SUM, DIFF, PROD, DIV
  • NEG to make the expression negative

You can nest functions.

Constants: Numbers or logical

💡 Example:
To simulate a trailing stop: Trailing Stop Expression

Expression Preview: See your condition in plain English as you build it

💡 Tip:
The expression preview shows your condition in plain English. If it doesn't read like you intended, modify your expression until it makes sense.

Tips for Using Expressions

Start Simple

Begin with basic conditions and add complexity gradually:

  1. Create a simple profit target first
  2. Test it to make sure it works
  3. Add additional conditions using AND/OR logic

Validation and Errors

The expressions editor validates your condition and shows helpful error messages:

⚠️ Important:
Common Validation Errors:
  • Empty groups: All condition groups must have at least one condition
  • Placeholder variables: Replace all "Choose..." dropdowns before saving
  • Type mismatches: Make sure you're comparing numbers to numbers, booleans to booleans
  • Invalid numbers: Values must be reasonable (not infinity or extremely large)

When to Use Simple Rules vs Expressions

Use Simple Rules When:

  • Basic profit/loss targets
  • Standard time-based exits
  • Simple Greek thresholds
  • Market hour restrictions

Use Expressions When:

  • Combining multiple conditions with AND/OR logic
  • Using mathematical functions (abs, min, max)
  • Creating custom calculations
  • Building complex trailing stops or dynamic targets

Need Help?

If you're struggling with expressions:

  1. Start with simple rules first to learn the basics
  2. Use the tutorial to understand each component
  3. Check the expression preview to verify your logic

Using Expressions Examples

Basic Variable Usage

💡 Example:
Simple comparison "Position PnL, USD" > 100 Expression example 1 Multiple conditions "Position PnL, USD" > 50 AND "Minutes Since Market Open" > 60 Expression example 2 Percentage calculations "Position PnL, USD" > ("Position Initial Premium" * 0.5) Expression example 3

Advanced Calculations

💡 Example:
Trailing stop using cumulative max "Position PnL, USD" < ("Position Cumulative Max PnL, USD" - 200) Expression example 4 Portfolio delta percentage abs("Position Portfolio Delta") > ("Account Equity" * 0.01) Expression example 5 Time-weighted profit target "Position PnL, USD" > (100 + ("Minutes Since Market Open" * 0.5)) Expression example 6

Multi-Leg Analysis

💡 Example:
Individual leg performance ("Leg A PnL, USD" > 50) OR ("Leg B PnL, USD" > 75) Expression example 7 Roll frequency limits ("Leg A Number of Rolls" + "Leg B Number of Rolls") < 3 Expression example 8

Market Context Integration

💡 Example:
Volatility-adjusted profit targets ("VIX Current Quote Close" > 25 AND "Position PnL, USD" > 75) OR ("VIX Current Quote Close" <= 25 AND "Position PnL, USD" > 150) Expression example 9 Fed day risk management "FED Release Day" AND ("Minutes Since Market Open" > 120) Expression example 10

Next Steps

Ready to dive deeper? Explore these related topics:

On This Page

Last updated: 9/9/2025