Compare Values
The Compare Values rule compares two numeric values using a specified operator and outputs one of them based on the comparison result. If the condition is true, it outputs the first value; if false, it outputs the second value. This makes it easy to dynamically select between two quantities such as price levels, risk amounts, or position sizes within your strategy.
How It Works
The Compare Values rule performs a straightforward comparison between two numeric inputs. It takes Value 1 and Value 2, then applies the selected comparison operator to determine whether the condition is true or false. If the comparison evaluates to true, the rule outputs Value 1. If the comparison evaluates to false, the rule outputs Value 2.
The rule supports all standard comparison operators: Greater Than, Greater Than Or Equal, Less Than, Less Than Or Equal, Equal, and Not Equal. This provides flexibility in creating a wide range of conditional scenarios.
In addition to the selected value, the rule outputs a boolean result indicating whether the comparison condition was true or false. This boolean can be passed to subsequent rules for further decision-making. The rule only executes when both input values are valid, ensuring that the comparison is meaningful and the output is reliable.
Common use cases include selecting the smaller of two values for risk calculations (using Less Than), choosing the higher value for resistance levels, or picking between different position sizes based on market conditions.
Inputs
| Parameter | Description | Required | Default |
|---|---|---|---|
| Value 1 | The first numeric value to be compared. This value will be returned as the output if the comparison condition evaluates to true. | Yes | — |
| Operator | The comparison operator used to evaluate Value 1 against Value 2. Options: Greater Than (true if Value 1 > Value 2), Greater Than Or Equal (true if Value 1 ≥ Value 2), Less Than (true if Value 1 < Value 2), Less Than Or Equal (true if Value 1 ≤ Value 2), Equal (true if Value 1 = Value 2), Not Equal (true if Value 1 ≠ Value 2). | Yes | — |
| Value 2 | The second numeric value to be compared with Value 1. This value will be returned as the output if the comparison condition evaluates to false. | Yes | — |
Outputs
| Output | Description |
|---|---|
| Value | The output value based on the comparison result. If the condition is true, Value 1 is output; if false, Value 2 is output. This value can be fed directly into downstream rules that accept a numeric input. |
| Result | A boolean value indicating whether the comparison condition was true or false. This can be consumed by other rules for additional conditional logic. |
Tips
Use Compare Values with the "Less Than" operator to implement a minimum function (the smaller of two values), or "Greater Than" for a maximum function (the larger of two values). This is especially useful for risk management — for example, comparing a calculated position size against a maximum allowed size and always using the smaller of the two to cap your exposure.
Was this helpful? Let us know