Trade State Data
The Trade State Data rule calculates comprehensive aggregated state data for a specified set of trades. It continuously monitors the selected trades and provides real-time aggregations of their performance, position status, volume, margin requirements, and pip values—all expressed in a currency of your choice. This rule is ideal for building trade-group-level analytics and managing clusters of related trades within your strategy.
How It Works
The Trade State Data rule serves as a comprehensive reporting and analytics tool that aggregates information from multiple trades into a unified dataset. You specify a list of trade IDs, and the rule continuously monitors those trades and calculates various aggregated metrics including profit/loss (in both currency and pips), position counts, volume metrics, margin requirements, and pip values.
The rule processes all trades in the specified list, but only includes trades from the same account and symbol in the calculations. This ensures that the aggregated data represents a consistent set of trades that can be meaningfully combined. All metrics update automatically whenever relevant events occur, such as price ticks, time-based updates, or order status changes.
A key feature of this rule is that it provides both current values and historical maximums for key metrics. For example, it tracks the current profit/loss as well as the maximum profit and maximum loss achieved throughout the trades' lifecycle. This allows your strategies to monitor not just the current state but also the historical extremes of trade performance—useful for managing risk and detecting when a group of trades has moved significantly from its best or worst levels.
The rule supports currency conversion, allowing you to view all monetary values in your preferred currency. This is particularly useful for strategies trading across different instruments or when you need consistent reporting in a single currency. The rule automatically handles the conversion of profit/loss figures, margin requirements, and pip values.
The rule also distinguishes between open and closed positions, providing separate counts and metrics for each. Additionally, it breaks down order counts by type (buy/sell and limit/stop orders), providing granular visibility into the composition of open orders.
Inputs
| Parameter | Description | Required | Default |
|---|---|---|---|
| Trade Id(s) | The specific trade IDs for which to calculate aggregated state data. You can specify multiple trade IDs as a list. Only trades from the same account and symbol will be included in the calculations. | Yes | — |
| Currency Code | The currency code in which to express all monetary output values, including profit/loss figures, margin requirements, and pip values. | Yes | — |
Outputs
| Output | Description |
|---|---|
| Trade Id(s) | The list of trade IDs used for the calculations, sorted by trade creation time. |
| Open Position(s) Trade Id(s) | The list of trade IDs that represent currently open positions within the specified trades, sorted by creation time. |
| Profit | The aggregate profit or loss for all specified trades, in the specified output currency. Includes both open and closed positions. |
| Profit Pips | The aggregate profit or loss for all specified trades expressed in pips. |
| Max Profit Pips | The maximum aggregate profit in pips achieved throughout the trades' lifecycle. |
| Max Loss Pips | The maximum aggregate loss in pips (negative value) achieved throughout the trades' lifecycle. |
| Open Positions Profit | The aggregate profit or loss for only the currently open positions, in the specified currency. |
| Open Positions Profit Pips | The aggregate profit or loss for only the currently open positions, in pips. |
| Max Open Positions Profit Pips | The maximum aggregate profit in pips achieved by just the open positions. |
| Max Open Positions Loss Pips | The maximum aggregate loss in pips achieved by just the open positions. |
| Open Buy Positions | The current number of open buy positions within the specified trades. |
| Closed Buy Positions | The number of closed buy positions within the specified trades. |
| Open Sell Positions | The current number of open sell positions within the specified trades. |
| Closed Sell Positions | The number of closed sell positions within the specified trades. |
| Max Open Buy Positions | The maximum number of simultaneous open buy positions reached at any point. |
| Max Open Sell Positions | The maximum number of simultaneous open sell positions reached at any point. |
| Open Positions | The current total number of open positions. |
| Closed Positions | The current total number of closed positions. |
| Open Orders | The current total number of open orders. |
| Open Buy Limit Orders | The current number of open buy limit orders. |
| Open Sell Limit Orders | The current number of open sell limit orders. |
| Open Buy Stop Orders | The current number of open buy stop orders. |
| Open Sell Stop Orders | The current number of open sell stop orders. |
| Has Open Positions | A true/false value indicating whether any of the specified trades currently have open positions. |
| Margin | The total margin required to maintain all open positions, in the specified currency. |
| Max Margin | The maximum margin required at any point, in the specified currency. |
| Total Qty | The aggregate quantity for both open and closed trades. |
| Open Qty | The aggregate quantity for only the open trades. |
| Closed Qty | The aggregate quantity for only the closed trades. |
| Max Open Qty | The maximum aggregate quantity for open trades reached at any point. |
| Pip Value | The current value of a pip based on the quantity of open trades, in the specified currency. |
| Max Pip Value | The maximum pip value achieved at any point, in the specified currency. |
| Avg Buy Entry Price | The average entry price of all buy positions within the specified trades. |
| Avg Sell Entry Price | The average entry price of all sell positions within the specified trades. |
Tips
Use this rule to monitor a specific cluster of related trades—for example, all trades opened during a particular trading session or all positions in a scaling-in strategy. The “Open Position(s) Trade Id(s)” output is especially useful for feeding into other rules that need to operate only on currently active positions. The pip-based profit outputs (Profit Pips, Max Profit Pips, Max Loss Pips) are valuable for strategies where you want to manage trades based on pip distance rather than monetary value, as they are unaffected by position size differences. Use the Average Buy/Sell Entry Price outputs to calculate the effective cost basis of your aggregated positions.
Was this helpful? Let us know