Trade Client Expression Reference
How to extract values from signal files in Trade Client strategies.
Overview
When configuring a strategy, you specify expressions to extract values from your signal file. How these expressions are interpreted depends on whether your file has headers.
Files With Headers
For files with a header line (such as a Trade-Ideas file), the first line contains column headers. You can reference columns by name:
| Expression | Description |
|---|---|
Symbol |
Value from the Symbol column |
Price |
Value from the Price column |
Price($) |
Columns with special characters work too |
Math with Header References
You can perform calculations using column values in brackets:
| Expression | Description |
|---|---|
1000 + [Price($)] |
Add 1000 to the Price column value |
1000 / [Price($)] |
Divide 1000 by the Price column value |
[Price] * 2 |
Double the Price column value |
Files Without Headers
If your signal file doesn't have a header row, use column indices instead. Columns are numbered starting at 1 (not 0).
For a CSV line like: AAPL,150.25,1000
| Expression | Result | Description |
|---|---|---|
1 |
AAPL | First column |
2 |
150.25 | Second column |
3 |
1000 | Third column |
The Ambiguity Problem
Here's a common issue: What if you want the literal value 2, not the value from column 2?
When you enter 2 as your expression:
- If you have 3 or more columns,
2is interpreted as "column 2" - If you have fewer than 2 columns,
2is returned as the literal value
Solutions for getting the literal value 2:
| Expression | Why it works |
|---|---|
(2) |
Parentheses prevent column interpretation (simplest) |
2.0 |
Decimal point prevents integer parsing |
2 * 1 |
Math expression that evaluates to 2 |
1 + 1 |
Another math expression |
The (2) syntax is recommended as it's the clearest way to indicate "I mean the number 2, not column 2".
Explicit Column References with Brackets
To explicitly reference a column (leaving no ambiguity), use square brackets:
| Expression | Description |
|---|---|
[1] |
Explicitly get column 1 |
[2] |
Explicitly get column 2 |
[2] + 1 |
Column 2's value plus 1 |
If the bracketed column doesn't exist (e.g., [10] when you only have 3 columns), the result is empty.
Math Expressions
Full mathematical expressions are supported:
| Expression | Description |
|---|---|
1 + 1.2 |
Simple arithmetic (returns 2.2) |
[2] + 1 |
Add 1 to column 2's value |
[3] * 0.5 |
Half of column 3's value |
100 / [2] |
100 divided by column 2's value |
Special Values
| Expression | Behavior |
|---|---|
0 |
Returns literal 0 (not a valid column index) |
-1 |
Returns literal -1 (negative numbers are literal) |
| Empty | Returns empty string |
Summary Table
| Scenario | Expression | Behavior |
|---|---|---|
| Header file, get column by name | Price |
Value from Price column |
| Header file, math with column | [Price] + 10 |
Price + 10 |
| No header, get column 2 | 2 or [2] |
Value from column 2 |
| No header, literal number 2 | (2) or 2.0 |
The number 2 |
| No header, math with column | [2] * 100 |
Column 2 times 100 |
Examples
Example 1: File with headers
File content:
Symbol,Entry,Target,Stop
AAPL,150.25,155.00,148.00
- Entry price:
Entryreturns150.25 - Calculate risk:
[Entry] - [Stop]returns2.25
Example 2: File without headers
File content:
AAPL,150.25,155.00,148.00
- Symbol:
1returnsAAPL - Entry price:
2returns150.25 - Fixed share size of 100:
(100)returns100 - Position size based on column 4:
1000 / [4]returns6.76(1000 / 148)