Custom variables in alerts

Autoview · Alert syntax

A custom variable lets you name a value once and use that name everywhere else in the same alert. You write :name=value on its own, then drop name into any command below it. When you want to change the value, you change it in one spot instead of hunting through every line.

Here is the shape of it:

:risk=2

That defines a variable called risk with the value 2. On its own it does nothing tradeable. It just sits there ready to be used by the commands that follow.

The rule: :name=value

Start the token with a colon, then the name, an equals sign, and the value. The name has to begin with a letter or an underscore, and after that it can hold letters, digits, and underscores. So :risk=2, :tp_pct=3.5, and :size1=1 are all fine. A name that starts with a digit is not picked up.

  • The colon is what marks it. When Autoview reads a line, any token whose key begins with : is set aside as a variable and is not treated as a normal command parameter. That is the whole job of the colon.
  • Case does not matter for the name. :risk=2 and [RISK] point at the same value. Autoview folds the name to a single case internally, so you can write it however reads best to you.
  • Trailing spaces are trimmed. The value stops at whitespace, so :risk=2 stores 2, not 2 with spaces hanging off it.

How you reference it

This is the part that catches people, so read it slowly. A custom variable is read back inside square brackets, as part of an [equation]. The name on its own, bare in a command, is not substituted. Put it in brackets and it is.

:risk=2
e=oanda s=EUR_USD b=long q=[risk]%

Autoview reads [risk], swaps in 2, and the order sizes at 2%. Because brackets are equations, you can do math with the name in the same breath: [risk*2] is 4, [risk/2] is 1, [risk+0.5] is 2.5. The variable is just a named number that the equation can build on.

One sharp edge to know about: the names you define share a pool with Autoview's built-in math constants. E, PI, LN10, LN2, LOG10E, LOG2E, SQRT1_2, and SQRT2 are already taken. If you name a variable after one of those, you change what that constant means for the rest of the alert. Pick names that are not on that list and you will never hit it.

What problem it solves

The point is having one source of truth for a value you use more than once. Say three orders in an alert all key off the same risk percentage. Without a variable you write that percentage three times, and the day you want to dial it up you have to edit all three and hope you got every one. With a variable you write it once at the top and the three orders read from it.

:risk=2
// entry
e=oanda s=EUR_USD b=long q=[risk]%
// add on a pullback
e=oanda s=EUR_USD b=long q=[risk]%
// and once more
e=oanda s=EUR_USD b=long q=[risk]%

All three orders size at 2%. Change the top line to :risk=1.5 and every order moves together. The two comment lines just label the log so you can read back what ran.

Where a definition reaches

A definition applies to its own line and every line below it in the same alert, not the lines above it. So define your variables at the top, before the commands that use them. If you define the same name again further down, the new value takes over from that point on, which lets you shift a value partway through an alert if you really need to.

:risk=2
e=oanda s=EUR_USD b=long q=[risk]%
:risk=1
e=oanda s=GBP_USD b=long q=[risk]%

The first order sizes at 2%, the second at 1%. The redefinition only affects the line under it and onward. Variables also do not carry between alerts. Each alert builds its own set fresh from its own message.

This is not the same as TradingView's {{ }} placeholders

It is easy to mix these two up, because both look like "put a value in here later." They run at completely different moments.

  • TradingView {{ }} placeholders are filled in by TradingView, before the alert ever leaves their servers. By the time Autoview receives your message, something like {{close}} or {{ticker}} has already been replaced with a real number or symbol. Autoview never sees the braces. It just sees whatever TradingView put there.
  • Autoview :name=value variables are filled in by Autoview, when it processes the alert it received. The colon syntax means nothing to TradingView; it passes straight through as plain text and Autoview resolves it on its end.

So the two stack cleanly. You can let TradingView inject a live price with its placeholder, then hand that to an Autoview variable, and each side handles its own step:

:entry={{close}}
e=oanda s=EUR_USD b=long q=1% t=limit p=[entry]

TradingView turns {{close}} into the real close price before sending. Autoview then reads :entry= with that price already in it, and [entry] uses it for the limit. Two systems, two moments, no overlap.

Things worth knowing

  • Reference inside brackets, always. A bare name in a command does not get swapped. It only resolves as part of an [equation], like [risk] or [risk*2].
  • Define above where you use it. A definition reaches downward, not up. Put it at the top of the alert.
  • Avoid the reserved constant names. Steer clear of E, PI, LN10, LN2, LOG10E, LOG2E, SQRT1_2, and SQRT2 for your own variables.
  • Names start with a letter or underscore. Digits are fine after the first character, not as the first character.
  • It is per alert. A variable lives for the one alert it is defined in and does not carry to the next.

For everything the order lines themselves can do, side, sizing, stops, order type and the rest, see the command reference, or the full alert syntax page.

Read the command reference