Math Node

The Math node does arithmetic on values: add, subtract, multiply, divide, max, min, average and absolute value. How each one takes its inputs, what a missing value or a zero denominator gives you, and the patterns it's built for.

NodeBy AlgoLiftUpdated 4 min read
On this page 6How it worksExample: volume that's unusual for the time of daySettingsUse something else whenWhen it doesn't behaveGoing further

Sometimes the number a rule needs isn't on the chart yet. Twice the average range. The midpoint of two levels. This bar's volume as a multiple of normal. The Math node builds it from values you already have, so a Comparison, an Entry or a stop can use it.

Takes
One to five numbers, depending on the operation
Gives
One number
Reach for it
The value a rule needs is arithmetic on values you already have

How it works

Pick the operation from the menu on the node. Each one takes its inputs a little differently:

OperationInputsGives
Add2 to 5a + b + c ...
Subtract2 to 5a − b − c ...
Multiply2 to 5a × b × c ...
DivideExactly a and ba ÷ b
Max, Min2 to 5The largest, or the smallest
Average2 to 5Their mean
Absolutea onlya without its sign

Order matters for Subtract and Divide, where a comes first. Wire the inputs in order with no gaps; the builder refuses a skipped one.

The result is in whatever units went in. Points minus points is points, and points divided by points is a plain ratio. That's often the point of a Divide: a ratio means the same thing on ES at 6,000 as it did at 3,000.

Missing values pass straight through. If any input has no value yet (an indicator still warming up, a level that hasn't formed), neither does the result, and a Comparison reading it is false. Division by zero works the same way. It gives no value, never infinity, so a rule built on a ratio sits out the bars where the denominator is zero instead of firing on a nonsense number.

Absolute is the one people forget. Put a Distance from price to VWAP through it, compare the result with a Constant of 2 using Less Than, and you have "within 2 points of VWAP, either side".

Example: volume that's unusual for the time of day

You trade NQ 5m breakouts and only want the ones with real participation behind them. A plain 20-bar average of volume is a poor yardstick: the open trades several times the volume of lunch, so every 09:35 bar looks huge and every 12:30 bar looks dead.

Divide instead. Search the palette for the Relative volume pattern and it drops in as three nodes you can see and edit: a Price History reading the last completed bar's volume, another reading the average volume at this time of day over the last 20 sessions, and a Divide. A reading of 1.0 is a normal bar for that time of day; 1.5 is half again as much. Wire the Divide into a Comparison, Greater Than or Equal, against a Constant of 1.5, and AND that with your breakout.

Settings

Operation
Default Add
Add, Subtract, Multiply, Divide, Max, Min, Average or Absolute, picked from the menu on the node.
Inputs
Default 2
From 2 to 5, added and removed with + and − on the node. Divide always has two and Absolute one.

Use something else when

How far price is from a line, in points, ticks, percent or ATRs
Distance does the subtraction and the scaling in one node, and positive always means above.
The midpoint or a ratio level of a range
The 50% or the 61.8% of a high and a low, without building it by hand.
A trailing or breakeven stop
Pick the mode on the bracket and it builds the Math for you (see below).
A stop or target a number of ATRs from the fill
Set the row's unit to a multiple and wire the ATR in. The builder refuses a Math node there: put the arithmetic in the multiple instead.

When it doesn't behave

My ratio is empty on some bars

One of its inputs has no value on those bars, or the denominator is zero. Neither gives a number, and any Comparison reading it is false there. Check the inputs on the chart first. A time-of-day average, for instance, has nothing to give until enough sessions have traded that slot.

The builder says an input is skipped

The wires don't run a, b, c in order. Move the wire on c to b, or remove the extra input. Absolute only reads a, and Divide only a and b.

My long's trailing stop is refused for using Min

A long's stop should only ever move up, so the ratchet that holds it is a Max (the higher of the current stop and the new candidate). Min is the short's version. The builder refuses the wrong one for the trade's direction.

Going further

The Bracket Order's stop modes are made of Math nodes, and you can watch it happen. Set a long's bracket to ATR trailing and the builder lays out an ATR times a Constant of 2 (a Multiply), price minus that (a Subtract), and the higher of the result and the current stop (a Max), wired into the bracket's stop override. A short gets an Add and a Min. Change the Constant to change the multiple. The Max is the ratchet: it's why the stop never steps back.

Every Constant feeding a Math node is a parameter Optimize can sweep. A multiplier is an easy thing to tune until it fits the past perfectly, so sweep in wide steps and keep a reason for the range.

Or ask the copilot