Default Tokens

Every expression you write in the YAML references named values called tokens. The engine refreshes the entire token map on every bar before evaluating any of your expressions. When you write `PRICE_CLOSE > 50000`, the...

Written By Axiom Admin

Last updated About 1 month ago

Default Tokens

Every expression you write in the YAML references named values called tokens. The engine refreshes the entire token map on every bar before evaluating any of your expressions. When you write PRICE_CLOSE > 50000, the engine looks up PRICE_CLOSE in the map, gets the current bar's close price, and compares it to the literal 50000.

This page documents every token the engine makes available by default β€” before you connect a single custom indicator. These are the building blocks your expressions have access to out of the box. Custom tokens (your external indicators) are covered at the end.

When examples use names like EMA_200, RSI_K, or ATR_14, assume those are custom tokens you connected from indicators on your chart. They are not built in.

Token names are case-sensitive. PRICE_CLOSE works. price_close does not. Price_Close does not. Get the casing wrong and the engine will raise an "Unknown identifier/token" error during first-bar validation β€” the strategy will not run. The error table will show exactly which token name was not found. If the strategy is failing to load, check your token names first.

For the full expression syntax β€” operators, functions, and how to combine tokens into conditions β€” see Expression Reference.


Price tokens

These update every bar from the chart's current symbol and timeframe.

Token

Type

What it returns

Example use

PRICE_CLOSE

Number

Current bar's closing price

PRICE_CLOSE > EMA_200

PRICE_HIGH

Number

Current bar's high

PRICE_HIGH > HIGHEST(PRICE_HIGH, 20)

PRICE_LOW

Number

Current bar's low

PRICE_LOW < LOWEST(PRICE_LOW, 10)

PRICE_HL2

Number

Midpoint of high and low: (high + low) / 2

PRICE_CLOSE > PRICE_HL2

PRICE_HLC3

Number

Typical price: (high + low + close) / 3

Price filter using the bar's typical price

PRICE_HLCC4

Number

Weighted close: (high + low + close + close) / 4

Smoothed price reference that weights the close

PRICE_OHLC4

Number

Average of all four: (open + high + low + close) / 4

A balanced single-bar price summary

VOLUME

Number

Current bar's volume

VOLUME > 1000000

When to use which price

Most conditions use PRICE_CLOSE because that is the price the bar settles at. Use PRICE_HIGH and PRICE_LOW when you care about the extremes β€” breakouts, range boundaries, stop placement. The averaged variants (HL2, HLC3, HLCC4, OHLC4) are useful when you want a single number that smooths out the bar's range. They are not better or worse than PRICE_CLOSE β€” they are different questions about the same bar.

History references

Any numeric token supports a history suffix. PRICE_CLOSE[1] returns the previous bar's close. PRICE_CLOSE[10] returns the close from 10 bars ago. The syntax is TOKEN_NAME[N] where N is a non-negative integer. No spaces inside the brackets. See Expression Reference for full details.


Bar and time tokens

Token

Type

What it returns

Example use

BAR_INDEX

Number

The current bar's sequential index (starts at 0)

BAR_INDEX > 200 β€” wait for enough history before evaluating

BAR_TIME

Number

Opening timestamp of the current bar (Unix ms)

Time-based comparisons and session math

TIME_CLOSE

Number

Closing timestamp of the current bar (Unix ms)

Comparing bar boundaries

TIMENOW

Number

Current real-world time when the script runs (Unix ms)

Caution: evaluates differently on historical vs. live bars β€” see warning below

BAR_YEAR

Number

Four-digit year of the bar's open

BAR_YEAR >= 2024

BAR_MONTH

Number

Month (1–12) of the bar's open

BAR_MONTH >= 3 && BAR_MONTH <= 10 β€” trade only March through October

BAR_WEEKOFYEAR

Number

Week number (1–53) of the bar's open

Seasonal filters

BAR_DAYOFMONTH

Number

Day of the month (1–31)

Avoid month-end: BAR_DAYOFMONTH < 28

BAR_DAYOFWEEK

Number

Day of week (1 = Sunday, 7 = Saturday)

BAR_DAYOFWEEK >= 2 && BAR_DAYOFWEEK <= 6 β€” weekdays only

BAR_HOUR

Number

Hour (0–23) of the bar's open

Session time gating

BAR_MINUTE

Number

Minute (0–59) of the bar's open

Intraday timing

BAR_SECOND

Number

Second (0–59) of the bar's open

Rarely useful outside tick-level timing

The TIMENOW warning

TIMENOW returns the actual current wall-clock time when the script evaluates. On historical bars during a backtest, this is the time of the recalculation β€” not the time the bar originally occurred. This means:

  • A condition using TIMENOW will produce different results each time TradingView recalculates the strategy.

  • Results that depend on TIMENOW are not stable across sessions. If you close your browser and reopen the chart, the results may change.

  • If your strategy's results changed overnight without any YAML changes, TIMENOW (or a bar-state token) is the most likely cause.

Use BAR_TIME or the calendar tokens (BAR_HOUR, BAR_DAYOFWEEK, etc.) for time-based logic that needs to be stable across recalculations. Reserve TIMENOW for real-time-only logic where you genuinely need the current wall-clock time.


Symbol information tokens

Token

Type

What it returns

Example use

MINTICK

Number

The smallest price increment for the current symbol

Price rounding and stop placement

SYM_POINTVALUE

Number

Currency value of one point of price movement

Contract value calculations

SYM_PRICESCALE

Number

Price scale (number of decimal digits in price display)

Precision awareness

These are constants for a given symbol β€” they do not change bar to bar. They are most useful inside price expressions for exits: calculating a stop loss as POSITION_AVG_PRICE - (50 * MINTICK) means "50 ticks below my average entry price," which adapts automatically to whatever symbol you are charting.


Timeframe tokens

Token

Type

What it returns

Example use

TF_MULTIPLIER

Number

The numeric multiplier of the chart's timeframe (e.g., 15 for a 15-minute chart)

TF_MULTIPLIER >= 60 β€” only on hourly or higher

TF_ISINTRADAY

True/False

True if the chart timeframe is intraday

Gate conditions that should only run intraday

TF_ISSECONDS

True/False

True if the chart is on a seconds-based timeframe

TF_ISTICKS

True/False

True if the chart is on a tick-based timeframe

TF_ISDAILY

True/False

True if the chart is on a daily timeframe

TF_ISWEEKLY

True/False

True if the chart is on a weekly timeframe

TF_ISMONTHLY

True/False

True if the chart is on a monthly timeframe

Timeframe tokens are useful as gate conditions when you build a strategy that should only evaluate on certain chart resolutions. A strategy tuned for daily charts can use TF_ISDAILY as a setup gate to prevent accidental evaluation on an intraday chart where the assumptions would be wrong.


Bar state tokens

Token

Type

What it returns

Example use

BARSTATE_ISCONFIRMED

True/False

True when the current bar is confirmed (closed)

Ensure conditions only trigger on confirmed data

BARSTATE_ISNEW

True/False

True on the first tick of a new bar

BARSTATE_ISLAST

True/False

True on the last historical bar or the current real-time bar

BARSTATE_ISREALTIME

True/False

True only on the live, real-time bar β€” false on all historical bars

The historical recalculation trap

BARSTATE_ISREALTIME is always false during a backtest and always false on historical bars during a recalculation. If you use it in a gate or trigger condition, that condition will never fire in the backtest. Your results will show zero trades, and everything will look like the condition is simply too strict β€” when in reality it is a bar-state token that cannot be true in the test environment.

BARSTATE_ISCONFIRMED is the most practically useful bar-state token. If you want a condition to only trigger on the bar's close (not on intra-bar ticks during real-time evaluation), gating on BARSTATE_ISCONFIRMED achieves that. Note: in backtesting, all bars are confirmed by definition, so this gate has no filtering effect on historical data. It matters only for real-time behavior.


Session tokens

Token

Type

What it returns

Example use

SESSION_ISMARKET

True/False

True during regular market hours

SESSION_ISMARKET as a setup gate β€” trade only during market hours

SESSION_ISPREMARKET

True/False

True during pre-market session

SESSION_ISPOSTMARKET

True/False

True during post-market session

Session tokens are most relevant for equities and futures where pre-market and post-market behavior differs from the regular session. For 24/7 crypto markets, SESSION_ISMARKET is typically always true. Check your exchange's session definition on TradingView if session gating does not behave as expected.


Strategy statistics tokens

These report the strategy tester's cumulative performance metrics. They update as trades are processed.

Token

Type

What it returns

STRATEGY_EQUITY

Number

Current equity (initial capital + net profit + open profit)

STRATEGY_INITIAL_CAPITAL

Number

The starting capital configured in Properties

STRATEGY_NETPROFIT

Number

Realized net profit in currency

STRATEGY_NETPROFIT_PERCENT

Number

Realized net profit as a percentage of initial capital

STRATEGY_GROSSPROFIT

Number

Sum of all winning trades in currency

STRATEGY_GROSSPROFIT_PERCENT

Number

Gross profit as a percentage

STRATEGY_GROSSLOSS

Number

Sum of all losing trades in currency (negative number)

STRATEGY_GROSSLOSS_PERCENT

Number

Gross loss as a percentage

STRATEGY_OPENPROFIT

Number

Unrealized P/L on all open trades in currency

STRATEGY_OPENPROFIT_PERCENT

Number

Unrealized P/L as a percentage

STRATEGY_MAX_DRAWDOWN

Number

Maximum peak-to-trough equity decline in currency

STRATEGY_MAX_DRAWDOWN_PERCENT

Number

Maximum drawdown as a percentage

STRATEGY_MAX_RUNUP

Number

Maximum equity runup in currency

STRATEGY_MAX_RUNUP_PERCENT

Number

Maximum runup as a percentage

STRATEGY_OPENTRADES

Number

Count of currently open trades

STRATEGY_CLOSEDTRADES

Number

Count of closed trades

STRATEGY_WINTRADES

Number

Count of winning closed trades

STRATEGY_LOSSTRADES

Number

Count of losing closed trades

STRATEGY_EVENTRADES

Number

Count of breakeven closed trades

STRATEGY_AVG_TRADE

Number

Average trade P/L in currency

STRATEGY_AVG_TRADE_PERCENT

Number

Average trade P/L as a percentage

STRATEGY_AVG_WINNING_TRADE

Number

Average winning trade P/L in currency

STRATEGY_AVG_WINNING_TRADE_PERCENT

Number

Average winning trade as a percentage

STRATEGY_AVG_LOSING_TRADE

Number

Average losing trade P/L in currency

STRATEGY_AVG_LOSING_TRADE_PERCENT

Number

Average losing trade as a percentage

STRATEGY_POSITION_SIZE

Number

Current net position size (positive for long, negative for short, zero for flat)

STRATEGY_POSITION_AVG_PRICE

Number

Average fill price of the current position

STRATEGY_LAST_DIRECTION

Number

Previous bar's position size β€” positive was long, negative was short, zero was flat

STRATEGY_MARGIN_LIQUIDATION_PRICE

Number

Estimated margin liquidation price (where applicable)

STRATEGY_MAX_CONTRACTS_HELD_ALL

Number

Peak concurrent contracts/units held (both directions)

STRATEGY_MAX_CONTRACTS_HELD_LONG

Number

Peak concurrent contracts/units held on the long side

STRATEGY_MAX_CONTRACTS_HELD_SHORT

Number

Peak concurrent contracts/units held on the short side

STRATEGY_OPENTRADES_CAPITAL_HELD

Number

Capital currently tied up in open trades

How strategy tokens enable adaptive logic

Strategy statistics tokens let your rules respond to what the strategy is doing, not just what the market is doing. Examples:

  • Equity-based position scaling: Use STRATEGY_EQUITY in an allocation expression to scale position size dynamically β€” smaller after drawdowns, larger after growth.

  • Drawdown gating: Use STRATEGY_MAX_DRAWDOWN_PERCENT > 15 as a setup gate condition to pause new entries after a significant drawdown, even before the risk circuit breaker threshold is reached.

  • Win/loss filtering: After a losing streak, you might gate entries on STRATEGY_LOSSTRADES - STRATEGY_WINTRADES < 5 to slow down when the strategy is underperforming.

  • Position awareness: STRATEGY_OPENTRADES > 0 tells you whether the strategy has open exposure. Useful in gate conditions for entries that should only fire when flat.

These are powerful, but they come with a warning: building conditions that reference strategy statistics creates feedback loops. A condition that pauses trading after drawdown will produce a different equity curve than the same strategy without the pause β€” and that different equity curve changes when the pause triggers, which changes the drawdown, which changes when the pause triggers. Test carefully and watch for recursive effects.


Position state tokens

These describe the current aggregated position across all setups and entries.

Token

Type

What it returns

POSITION_READY

True/False

True when position state has been initialized

POSITION_ACTIVE

True/False

True when there are open trades

POSITION_DIRECTION

Number

Net direction: 1 for long, -1 for short, 0 for flat

POSITION_ACTIVE_TRADES

Number

Count of currently open trades

POSITION_QUEUED_TRADES

Number

Count of orders submitted but not yet filled

POSITION_FILLED_QTY

Number

Net filled quantity across all open trades

POSITION_AVG_PRICE

Number

Weighted average fill price of the open position

POSITION_PROFIT_AMT

Number

Current unrealized P/L in currency

POSITION_PROFIT_PERCENT

Number

Current unrealized P/L as a percentage

POSITION_MAX_RUNUP

Number

Mirrors TradingView's strategy-level strategy.max_runup series in currency as currently exposed by this build

POSITION_MAX_DRAWDOWN

Number

Mirrors TradingView's strategy-level strategy.max_drawdown series in currency as currently exposed by this build

POSITION_MAX_RUNUP_PERCENT

Number

Mirrors TradingView's strategy-level strategy.max_runup_percent series

POSITION_MAX_DRAWDOWN_PERCENT

Number

Mirrors TradingView's strategy-level strategy.max_drawdown_percent series

POSITION_COMMISSION_PAID

Number

Currently exposed as a token, but remains 0 in this build

POSITION_CAPITAL_HELD

Number

Capital tied up in the current position

What position tokens are good for

Position tokens let your exits and entries respond to how the current trade is performing:

  • Trailing behavior: A take profit gated on POSITION_PROFIT_PERCENT > 5 will not trigger until the position has moved at least 5% in your favor. Combine with a price expression to set the actual exit level.

  • Breakeven stops: An exit triggered when POSITION_PROFIT_AMT > 0 and priced at POSITION_AVG_PRICE creates a move-to-breakeven stop after the trade goes green.

  • Flat detection: POSITION_ACTIVE == FALSE in a gate condition prevents entries from evaluating when you already have exposure. Useful for single-trade strategies.

One important qualifier: POSITION_MAX_RUNUP* and POSITION_MAX_DRAWDOWN* are not per-trade excursion counters in this build. The strategy currently populates them from TradingView's strategy-level strategy.max_* series. If you need live open-position behavior, use POSITION_PROFIT_AMT or POSITION_PROFIT_PERCENT instead.


Dynamic state tokens

When you define named setups, entries, and exits in your YAML, the engine automatically creates boolean state tokens for each one. These tokens let expressions in one part of your strategy check the state of another part.

Setup state tokens

For every named setup (e.g., a setup called TREND_FILTER), the engine registers:

Token pattern

Type

True when

<SETUP_NAME>_INACTIVE

True/False

The setup is in INACTIVE state

<SETUP_NAME>_ACTIVE

True/False

The setup is in any state other than INACTIVE (currently CONFIRMING or CONFIRMED in this build)

<SETUP_NAME>_CONFIRMING

True/False

The setup is currently in CONFIRMING state

<SETUP_NAME>_CONFIRMED

True/False

The setup has reached CONFIRMED state

So a setup called TREND_FILTER produces TREND_FILTER_INACTIVE, TREND_FILTER_ACTIVE, TREND_FILTER_CONFIRMING, and TREND_FILTER_CONFIRMED.

Example use: An entry gate condition of TREND_FILTER_CONFIRMED && VOLATILITY_SETUP_CONFIRMED requires two independent setups to both be confirmed before the entry can fire. This is how you build composite regime filters without cramming everything into a single setup's activation expression.

Entry and exit state tokens

For every named entry or exit (e.g., an entry called BREAKOUT_LONG), the engine registers:

Token pattern

Type

True when

<NAME>_INACTIVE

True/False

The intent is idle β€” not armed, not active

<NAME>_WAITING

True/False

The intent is armed or working, but not yet active

<NAME>_ACTIVE

True/False

The intent has an open trade or an already-filled exit leg recorded as active

Example use: A second entry gated on BREAKOUT_LONG_ACTIVE will only evaluate when the first entry has already filled and has an open trade. This is how you build add-on entries that pyramid into an existing position only after the initial entry is confirmed.

Naming requirements

The state token name is derived from the name you give the setup, entry, or exit in your YAML. The engine converts it to an uppercase, underscore-separated form for use in expressions. Keep your names simple and token-friendly β€” alphanumeric characters and underscores. Avoid spaces and special characters in names.


Custom tokens

Custom tokens are the bridge between external indicators on your chart and the expression language. The strategy provides 30 slots, each with three fields: name, type, and source. See Settings for the configuration details.

Once a custom token is registered, it is indistinguishable from a built-in token inside an expression. MY_EMA > PRICE_CLOSE works exactly the same way as STRATEGY_EQUITY > 100000 β€” the engine looks up the name, gets the value, applies the operator.

What custom tokens make possible

Any indicator output on your TradingView chart can become a token. Moving averages, RSI, Bollinger Bands, volume profiles, custom scripts β€” if it produces a plot on the chart, you can wire it into the expression language.

This is the mechanism that makes the strategy builder extensible without needing to build indicators into the engine. The engine does not calculate EMAs or RSIs. It does not need to. You add the indicator you trust to your chart, connect its output as a custom token, and reference it in your expressions. The indicator does the calculation. The strategy builder does the logic.

What happens if a token name is wrong

If you reference a token name in an expression that does not exist β€” because of a typo, because you forgot to register it, or because the name does not match β€” the engine raises an "Unknown identifier/token" error during first-bar validation. The strategy will not run, and the error table will identify the unrecognized name.

This applies to both built-in tokens and custom tokens. A mistyped custom token name like ema_50 instead of EMA_50 is caught and reported.

After connecting custom tokens, verify that they are reporting sensible values using the token diagnostics label (Show token value label in the Inputs tab). A token that exists but reads 0 on every bar means the source connection is broken β€” the name is correct but the data is not flowing.


Quick reference β€” all default tokens

Numeric tokens (Number type)

Token

Category

PRICE_CLOSE, PRICE_HIGH, PRICE_LOW, PRICE_HL2, PRICE_HLC3, PRICE_HLCC4, PRICE_OHLC4, VOLUME

Price

BAR_INDEX, BAR_TIME, TIME_CLOSE, TIMENOW

Bar/Time

BAR_YEAR, BAR_MONTH, BAR_WEEKOFYEAR, BAR_DAYOFMONTH, BAR_DAYOFWEEK, BAR_HOUR, BAR_MINUTE, BAR_SECOND

Calendar

MINTICK, SYM_POINTVALUE, SYM_PRICESCALE

Symbol

TF_MULTIPLIER

Timeframe

STRATEGY_EQUITY, STRATEGY_INITIAL_CAPITAL, STRATEGY_NETPROFIT, STRATEGY_NETPROFIT_PERCENT, STRATEGY_GROSSPROFIT, STRATEGY_GROSSPROFIT_PERCENT, STRATEGY_GROSSLOSS, STRATEGY_GROSSLOSS_PERCENT, STRATEGY_OPENPROFIT, STRATEGY_OPENPROFIT_PERCENT, STRATEGY_MAX_DRAWDOWN, STRATEGY_MAX_DRAWDOWN_PERCENT, STRATEGY_MAX_RUNUP, STRATEGY_MAX_RUNUP_PERCENT, STRATEGY_OPENTRADES, STRATEGY_CLOSEDTRADES, STRATEGY_WINTRADES, STRATEGY_LOSSTRADES, STRATEGY_EVENTRADES, STRATEGY_AVG_TRADE, STRATEGY_AVG_TRADE_PERCENT, STRATEGY_AVG_WINNING_TRADE, STRATEGY_AVG_WINNING_TRADE_PERCENT, STRATEGY_AVG_LOSING_TRADE, STRATEGY_AVG_LOSING_TRADE_PERCENT, STRATEGY_POSITION_SIZE, STRATEGY_POSITION_AVG_PRICE, STRATEGY_LAST_DIRECTION, STRATEGY_MARGIN_LIQUIDATION_PRICE, STRATEGY_MAX_CONTRACTS_HELD_ALL, STRATEGY_MAX_CONTRACTS_HELD_LONG, STRATEGY_MAX_CONTRACTS_HELD_SHORT, STRATEGY_OPENTRADES_CAPITAL_HELD

Strategy

POSITION_DIRECTION, POSITION_ACTIVE_TRADES, POSITION_QUEUED_TRADES, POSITION_FILLED_QTY, POSITION_AVG_PRICE, POSITION_PROFIT_AMT, POSITION_PROFIT_PERCENT, POSITION_MAX_RUNUP, POSITION_MAX_DRAWDOWN, POSITION_MAX_RUNUP_PERCENT, POSITION_MAX_DRAWDOWN_PERCENT, POSITION_COMMISSION_PAID, POSITION_CAPITAL_HELD

Position

Boolean tokens (True/False type)

Token

Category

BARSTATE_ISCONFIRMED, BARSTATE_ISNEW, BARSTATE_ISLAST, BARSTATE_ISREALTIME

Bar State

SESSION_ISMARKET, SESSION_ISPREMARKET, SESSION_ISPOSTMARKET

Session

TF_ISINTRADAY, TF_ISSECONDS, TF_ISTICKS, TF_ISDAILY, TF_ISWEEKLY, TF_ISMONTHLY

Timeframe

POSITION_READY, POSITION_ACTIVE

Position

<SETUP_NAME>_INACTIVE, <SETUP_NAME>_ACTIVE, <SETUP_NAME>_CONFIRMING, <SETUP_NAME>_CONFIRMED

Dynamic (per setup)

<ENTRY_OR_EXIT_NAME>_INACTIVE, <ENTRY_OR_EXIT_NAME>_WAITING, <ENTRY_OR_EXIT_NAME>_ACTIVE

Dynamic (per intent)