Expression Language Reference
This page is here to teach you how to actually write expressions for Axiom Strategy Lab Pro.
Written By AxiomCharts
Last updated About 2 hours ago
Expression Language Reference
This page is here to teach you how to actually write expressions for Axiom Strategy Lab Pro. If you are a first-time buyer, the practical question is usually not "what parser rules exist in theory?" The practical question is: "How do I write logic the strategy can understand?" That is the job of this page.
What An Expression Is
An expression is a piece of logic the strategy reads and evaluates. Sometimes the expression answers a yes-or-no question: - should this setup become active? - should this entry trigger now? - should this working order cancel? Sometimes the expression calculates a number: - what price should this limit order use? - what price should this stop use? - how far is price from the average fill? That gives you two big expression families:
The Two Most Important Ideas First
1. Tokens are the words your expression uses
Tokens are the named values the strategy exposes.
- PRICE_CLOSE
- BARSTATE_ISCONFIRMED
- POSITION_ACTIVE
- POSITION_AVG_PRICE
If you need the full token catalog, read Default Token Reference.
2. Operators and functions are how you do something with those tokens
An operator is a symbol like: - > - && - + - *
A function is a named tool like: - CROSSOVER(...) - HIGHEST(...) - ABS(...) - SAFE_DIV(...)
Put simply: - tokens are the ingredients - operators connect or compare them - functions do a named job with them
Where Expressions Are Used In The Strategy
This matters because the field tells you what kind of expression you need to write.
That means one of the first questions to ask is: "Am I writing a yes-or-no expression, or am I calculating a number?"
The Fastest Way To Build A Good Expression
Use this order:
- Decide what the field needs. If the field is a condition field, write a yes-or-no expression. If the field is a price field, write a number expression.
- Pick the tokens you need.
- Choose the operator or function that expresses the idea.
- Keep the first version small.
- Verify it on the chart before you make it more clever.
A Few Expressions In Plain English
If you can read expressions like short sentences, this page is doing its job.
Operators: What They Are And How To Use Them
Operators are the symbols that compare, combine, or calculate.
Comparison Operators
Use these when the job is to ask whether one number is above, below, equal to, or different from another.
One important note about ==
In this expression engine, numeric equality is not treated as raw bit-for-bit equality. It uses the symbol's minimum tick size as a tolerance. In trader terms, that means: - == means "close enough to count as equal" - != means "far enough apart to count as different" That is usually much more useful for chart logic than exact machine-style equality. Also because of the execution speed of TradingView scripts you may miss equality if not massaged just a little bit.
Logical Operators
Use these when you want to combine yes-or-no conditions.
Good mental model
- && narrows the condition - || widens the condition - ! flips a condition
Arithmetic Operators
Use these when you want to calculate a number.
Arithmetic is most often used in price expressions and numeric calculations.
Unary Operators
These are the one-input versions of an operator.
Most traders will mainly use unary - and !.
The Ternary Operator
This is the "if this, then that, otherwise something else" operator.
Shape: condition ? value_if_true : value_if_false
Example: POSITION_ACTIVE ? POSITION_AVG_PRICE * 1.01 : PRICE_CLOSE
Reads like: "If a position is active, use 1% above average price. Otherwise, use current close."
When ternary is useful
- choosing one price formula or another - switching behavior based on whether a position exists - creating one compact expression instead of repeating the same field in two places
Two rules to remember
- the condition must be yes-or-no - both result branches must be the same kind of thing - both numbers or both booleans
Token History: Looking Back
You can ask for an older value of a token by adding [number] after it.
Rules for token history
- write it with no spaces: PRICE_CLOSE[1] - use a non-negative whole number - the base token has to exist
Good: PRICE_CLOSE[1] POSITION_ACTIVE[3]
Not good: PRICE_CLOSE [1] PRICE_CLOSE[-1] PRICE_CLOSE[1.5]
Order Of Operations In Plain English
You do not need to memorize parser theory to use this well.
The practical reading order is: 1. math happens first 2. comparisons happen after the math 3. && and || combine the results 4. ternary chooses between the final branches
If you ever feel unsure, use parentheses. That is the cleanest habit anyway because it makes your intent obvious to both you and the next time you read the expression.
Example: BARSTATE_ISCONFIRMED && (PRICE_CLOSE > PRICE_HLC3 || PRICE_CLOSE > PRICE_HIGH[1]) The parentheses make the grouping obvious without needing to think about operator tables.
Functions: What They Are And What They Do
Functions are named tools. They let you do jobs that would be awkward or repetitive with operators alone. The most useful way to learn them is by job, not by parser category.
Function Group 1: Check Or Clean Values
These help you test, convert, or clean values before using them.
What BOOL(...) really does
- non-zero numbers become true - zero becomes false - na becomes false - booleans stay boolean
Function Group 2: Compare Or Measure Numbers
These are everyday workhorse functions.
Function Group 3: Work With Percentages And Safer Math
These are very useful in strategy authoring.
Function Group 4: Detect Events And Timing
These are often the most useful functions for setup and entry logic.
CHANGE(...) behaves differently depending on the input
- if you pass a number, it returns a number - if you pass a boolean, it returns a boolean That makes it flexible, but it also means you should know what kind of value you are feeding into it.
Function Group 5: Work With Trends, Ranges, And Lookbacks
These help you look across a window of bars instead of only the current bar.
Function Group 6: Advanced Math Tools
These are available, but they are not where most first strategy authors need to start.
They are part of the current engine, but most strategy authoring starts with the earlier groups first.
Expressions You Can Actually Use
These are much more helpful than abstract syntax on their own.
Example 1: Wait for a confirmed bullish condition
BARSTATE_ISCONFIRMED && PRICE_CLOSE > PRICE_HLC3Good use: - setup gates - entry gates - basic confirmed-bar filters
Example 2: Trigger only when price crosses up
CROSSOVER(PRICE_CLOSE, PRICE_HLC3)Good use: - setup activation - entry trigger logic
Example 3: Only manage exits when a position exists
POSITION_ACTIVEGood use: - exit gate conditions
Example 4: Place a take-profit 1% above average entry price
POSITION_AVG_PRICE * 1.01Good use: - take-profit limit price
Example 5: Place a stop 1% below average entry price
POSITION_AVG_PRICE * 0.99Good use: - stop-loss stop price
Example 6: Choose one price when in a trade and another when flat
POSITION_ACTIVE ? POSITION_AVG_PRICE * 1.01 : PRICE_CLOSEGood use: - dynamic price formulas
What The Strategy Expects In Real Fields
This is one of the most useful sections on the page.
Fields that want yes-or-no logic
These want a boolean result:
- setup_gate_condition
- setup_active_when
- setup_cancel_when
- setup_reset_when
- entry_gate_condition
- entry_trigger_when
- entry_cancel_when
- take_profit_gate_condition
- take_profit_trigger_when
- take_profit_cancel_when
- stop_loss_gate_condition
- stop_loss_trigger_when
- stop_loss_cancel_when
Good examples:
BARSTATE_ISCONFIRMED PRICE_CLOSE > PRICE_HLC3 POSITION_ACTIVE && BARSTATE_ISCONFIRMEDFields that want a number
These want a numeric result:
- entry_limit_price
- entry_stop_price
- take_profit_limit_price
- take_profit_stop_price
- stop_loss_limit_price
- stop_loss_stop_price
Good examples:
PRICE_LOW POSITION_AVG_PRICE * 1.01 ROUND_TO_MINTICK(PRICE_HLC3)What Makes An Expression Feel "Wrong" Even When It Looks Close
Most of the time, it is one of these:
Use Parentheses Liberally
You do not need to memorize parser theory to write strong expressions. If the reading order feels even slightly unclear, add parentheses.
Example: BARSTATE_ISCONFIRMED && (PRICE_CLOSE > PRICE_HLC3 || CROSSOVER(PRICE_CLOSE, PRICE_HLC3)) That makes your intent clearer immediately.
A Good Verification Habit
After you write an expression: 1. say it out loud in plain English 2. make sure it reads like what you intended 3. check that the field wants a bool or a number 4. verify it on the chart with the expression value label if needed
That one habit usually catches a lot before the strategy ever feels "mysterious."
What To Read Next
- Read Default Token Reference if you need the full token vocabulary.
- Read YAML Section Reference if you want to know which fields expect which kind of expression.
- Read Troubleshooting if the strategy is still disagreeing with an expression you expected to work.