Equations in your commands
Most of the time a number field gets a plain number: q=1, p=100. But you can also hand it a piece of math. Wrap the expression in square brackets, [ ], and Autoview works out the value first, then uses the result as the number. So q=[10/2] becomes a quantity of 5 before any order goes out.
Here it is in one line:
q=[100/4]
Autoview reads that, computes 25, and sizes the order at 25. The brackets are the whole trick: they mark "this is an expression, evaluate it" instead of "this is a literal number".
Why the brackets matter
Autoview splits an alert into separate commands on every newline and on the pipe character |. Anything inside [ ] is held together while that split happens, so a bracketed expression is never cut in half by a stray pipe or line break. The brackets tell Autoview where the math starts and ends.
One more thing the brackets buy you: they nest. You can use brackets inside brackets, and you can pair two bracketed expressions into a range (more on ranges below).
The operators you can use
Inside the brackets Autoview understands a small, fixed set of operators. These are the ones the parser actually implements:
+add and-subtract.[10+5]is 15,[10-5]is 5.*multiply and/divide.[4*3]is 12,[12/4]is 3. These bind tighter than add and subtract, so[2+3*4]is 14, not 20.^power.[2^3]is 8. It binds tighter than multiply and divide, and it groups from the right:[2^3^2]is2^(3^2).- A leading
-or+to set sign.[-5]is negative five,[-(2+3)]is negative five as well.
And two grouping forms:
- Parentheses
( )to force order.[(2+3)*4]is 20, because the parentheses run first. - Absolute value
| |.[|0-7|]is 7. The bars wrap an expression and return its distance from zero.
That is the complete list. There is no equals operator inside an equation: writing = between two values is not supported and will not "solve" anything. Comparison operators, logic, and named functions like min or round are not part of the expression language either, so do not reach for them here.
Constants you can name
A handful of math constants are recognized by name, and the names are not case sensitive. You can write any of these in place of a number:
PI E LN10 LN2 LOG10E LOG2E SQRT2 SQRT1_2So [2*PI] is about 6.283, and [pi] works the same as [PI]. These are the standard JavaScript math constants; nothing else is built in.
Variables you can reference
An equation can also pull in a couple of account values that Autoview fills in at run time:
balanceandequity. When Autoview sizes an order it makes your account balance and equity available to the quantity field, soq=[equity/10]sizes at a tenth of equity. (These are resolved against the account the order runs on.)
You can also define your own variables for an alert using the replacement syntax. A line like :risk=50 sets risk to 50, and then q=[risk/2] reads it. Define the value once, reference the name inside the brackets.
Be careful with names. If you put a word in an equation that Autoview does not recognize as a constant or a known variable, it is not an error you will see up front: the name has no value, so the expression cannot resolve to a real number and the order is rejected when Autoview tries to use it. Spell variable names exactly as you set them.
Percentages and ranges still work
The bracket syntax sits alongside the two number features you already know:
- Add a
%after the brackets and the result is treated as a percent.q=[100/4]%is 25 percent. - Pair two values into a range with a dash, and either side can be an expression.
q=[10/2]-[100/4]is a range from 5 to 25; Autoview picks a value inside it.q=10-20%is the plain-number version of the same idea.
A worked example
Size an entry at one quarter of equity, and set a take-profit a fixed amount above a price you passed in as a variable:
// size at 25% of equity
e=oanda s=EUR_USD b=long q=[equity/4]
// entry price came in as :entry, take profit 0.0050 above it
:entry=1.0850
p=[entry] tp=[entry+0.0050]Autoview computes the quantity from your equity, reads entry as 1.0850, sets the price to that, and works out the take-profit as 1.0900 before the order goes out. Swap the numbers and the variable names for whatever your strategy needs.
Things worth knowing
- Math runs before the order. The bracketed expression is resolved to a single number first, then that number is used. Nothing about the order is conditional on the math; it just sets the value.
- Keep to the supported operators. The five operators, parentheses, and absolute-value bars are the whole language. If an equation behaves oddly, check you are not using a symbol or function that is not on the list above.
- Variable names are literal. Only
balance,equity, the named constants, and the replacements you set with:name=have values. Any other word leaves the expression unable to resolve. - It works in number fields. Quantity, price, stop-loss, take-profit, trailing stop, and the other numeric parameters accept an equation. Text fields like comments do not do math.
For the full list of parameters an equation can go into, side, sizing, stops, order type and the rest, see the command reference, or the full alert syntax page.