Skip to content
Black Friday: sale starts November 15th.

Expansion Contraction Solver

Expansion Contraction solver node

The Expansion Contraction solver tells whether Input A and Input B are moving apart (expanding), coming together (contracting), or running parallel.

For example: are the Bollinger Bands widening, are two moving averages spreading apart in a trend, or squeezing together in consolidation?

Properties tab

Property Inspector tabs, with the Properties tab selected

The essential settings for the node.

Modifiers

Buttons for the most common output modifiers. They change only the selected instance of a node on a Logic Board, so they appear only when a node is selected there, not when a solver is selected in the Solvers panel. That keeps the solver’s original output unchanged everywhere else it’s used, much like changing an SMA’s plot color on one chart leaves it unchanged on your other charts.

Modifiers: the Enabled, Invert and Swap buttons
ButtonWhat it does
EnableTurns the node on or off. When it’s off, the node is left out of the system’s calculations. It still looks connected on the Logic Board, but it’s ignored.
InvertInverts the node’s output. The same calculation as the Inverter function node, without its extra options.
SwapSwaps the outputs: Long becomes Short and Short becomes Long. The same as the Long/Short Modifier function node with Mode: Swap.

Global Properties

These settings apply to every instance of the solver: change one instance and they all change. To change just one, make a copy of the solver. The copy is a separate solver, with a number added to the end of its name.

Behavior

Turns off the Long or the Short output.

Behavior: the Evaluate setting
SettingWhat it does
EvaluateWhich outputs the solver calculates.
Both: Long and Short.
Long only: only Long; the Short output is removed.
Short only: only Short; the Long output is removed.

Input A

The first value the solver evaluates, compared with Input B. Choose a data type in the Type menu; the settings below it change to match.

TypeWhat it evaluates
Indicator ValueAny installed indicator with a plot or Series<T> output, chosen in the Select Indicator window. The default and most used type. Displacement reads the value from a number of bars back.
PriceA bar price (Open, High, Low, Close, or the Body Top, Median or Bottom), optionally processed over a lookback period.
VolumeThe current bar’s volume.
Swing Point PricesPrices from the latest swing highs and lows.
Linear Regression ChannelThe upper, middle or lower line of a regression channel.
Fixed ValueA single value that never changes. Only useful for solvers with two inputs, such as Comparison.

Every type and its settings in full: Data type selection.

Input B

The second value, compared with Input A. It has the same data types and settings as Input A.

Input A and Input B, each with Type, Indicator and Displacement

Output Rules

Output rules decide when the solver gives a Long or Short output. Open the Rules window with the ellipsis (…) button next to Expansion/Contraction Rules.

Output: Expansion/Contraction Rules

The Rules window

Where you define the conditions the solver looks for. One solver can combine several rules, so complex conditions don’t need several solvers.

How the Rules window works

Click a rule’s title bar (the strip that says Fixed or Range) to expand or collapse it.

ControlWhat it does
Add Rule menu (top left)Adds a rule. A Fixed rule is the most common: it compares the Input with a value, or with Input B. A Range rule compares the Input with a lower and upper limit, or with a range of distance between Input A and Input B. To use a Range rule instead of the default Fixed rule, delete the Fixed rule, then add a Range rule.
Output Calculation menu (top right)Decides the output when two or more rules are true at the same time. See below.
Settings window (Range rules)Finer control over the values being evaluated. See below.
Delete buttonDeletes the rule. Undo brings it back.

Output Calculation options

OptionOutput
FirstThe output of the first true rule, working down from the top of the list.
LargestThe largest output of all the true rules. For fuzzy logic systems.
SmallestThe smallest output of all the true rules. For fuzzy logic systems.
AverageThe average of the outputs of all the true rules. For fuzzy logic systems.
AdditionThe outputs of all the true rules added together. For fuzzy logic systems.

Range rule settings

SettingWhat it does
Outside / InsideWhether the rule is true inside the range or outside it.
Exclude / IncludeInclude counts the range limits themselves (>= and <=). Exclude doesn’t (> and <).
Fixed Output / Ranged OutputFixed Output is a simple on/off output: 0, or the value on the far right (usually 1). Ranged Output turns on fuzzy logic: two Output fields appear, and when the Input is between the limits, the output is interpolated linearly between those two values.

Calculation Type

Besides Output Calculation, this solver’s Rules window has a Calculation Type menu:

Calculation TypeHow it works
Distance DeltaMeasures the distance between the inputs. The most accurate, but only valid when both inputs share the same price scale, for example two moving averages on the price panel. An SMA (price panel) against the MACD line (its own sub-panel) can’t be compared this way.
Slope DeltaCompares the slope of Input A with the slope of Input B. Works for any pair, including inputs on different scales.

Fixed rules

A Fixed rule identifies when the inputs are expanding, contracting or parallel. The sentence above the settings changes to describe the condition as you edit it.

  1. Input A and Input B. When both have the same name, “(A)” and “(B)” are added.
  2. Expand (moving apart), Contract (moving together) or Are Parallel.
  3. At Least or At Most: a minimum or maximum rate. Not shown for Are Parallel.
  4. The rate.
  5. The unit for the rate, see Measuring distance.
  6. The output value when the rule is true. 1 suits most systems; use a smaller value only for fuzzy logic.

For example, SMA(A) & SMA(B) [ Expand ] by [ At Least ] [ 0.5 ] [ Points ] is true while the two SMAs move apart by at least 0.5 points per bar: a moderate spread.

Range rules

A Range rule identifies expansion or contraction at a rate between a minimum and a maximum. For example, a Long rule that is true while two SMAs expand by up to 1 point per bar.

  1. Input A and Input B.
  2. Expand or Contract (Are Parallel is only for Fixed rules).
  3. The minimum rate.
  4. The maximum rate.
  5. The unit for 3 and 4.
  6. The output value when the rule is true.
Ranged Output (fuzzy logic, advanced)

With Ranged Output on in the rule’s Settings menu, two Output fields appear, 6 and 7: the output confidence value at the minimum rate and at the maximum rate, interpolated in between. If one of them is 1, the other should be less. Only use this for fuzzy logic systems.

Options tab

Property Inspector tabs, with the Options tab selected

Secondary settings shared by all nodes.

Weight

Changes the node’s final output value. Only needed when designing a fuzzy logic system, or a fuzzy logic part of a system.

How Weight works

Weight changes only the selected instance of a node on a Logic Board. So the controls appear only when a node is selected there, not when a solver is selected in the Solvers panel: a solver’s original output can’t be changed globally.

ControlWhat it does
Multiply OutputMultiplies the node’s internal Long and Short values (set by the Output Rules on the Properties tab) by this number. The final output still can’t go above 1 (see Slider).
SliderLimits the final output to between 0 and 1. The left handle sets a minimum output, given whether or not the condition is true. The right handle sets the maximum; the output is capped there.
Hedge OperationApplies a formula to the internal value.
None: unchanged.
Very: squares it (value²).
Somewhat: takes the square root (√value).

Example: two out of three

Three solvers check three indicator conditions, but only two need to be true. Connect them to an Additive logic node and set each solver’s maximum (the slider’s right handle) to 0.5. When any two are true, the Additive node adds 0.5 + 0.5 + 0 = 1, which means the two-out-of-three condition is met.

Description

Free text for describing what the node does or what it’s for. The Description is shared by every instance of the node, unlike Weight, which is set per instance.

Help tab

Property Inspector tabs, with the Help tab selected

Shows this page for the selected node, inside BloodHound. Click the node’s image at the top of the page to open it in a bigger window. The built-in web viewer needs NinjaTrader 8.0.26.0 or newer.

Tutorial videos

Example: identifying when the bar length increases or decreases.

Examples

Example 1A: The basics (Bollinger Bands)

When the Bollinger Bands expand, a sign of rising volatility.

Settings and chart

Input settings

  • Set Input A to Bollinger » Upper.
  • Set Input B to Bollinger » Lower.

Rules window

  • Open the Rules window with the ellipsis (…) button next to Expansion/Contraction Rules, then set the rule as shown.

Result

Long and Short outputs together, because expansion and contraction measure volatility, not direction. Note that the bands can expand or contract even while both slope the same way.

Example 1B: Expanding moving averages

Moving averages spreading apart: like 1A this shows expansion, but it can also point to trend moves and continuations.

Settings and chart

Input settings

  • Set Input A to EMA 20.
  • Set Input B to SMA 50.

Rules window

  • Open the Rules window with the ellipsis (…) button next to Expansion/Contraction Rules, then set the rule as shown.

Result

Long and Short outputs together, because expansion and contraction measure volatility, not direction. Right after the averages cross it isn’t perfect, just as a moving average crossover system isn’t.

Example 2: Expansion exhaustion

Extreme spreading of the moving averages, which can mean the move is overextended and a consolidation may follow.

Settings and chart

Input settings

  • Set Input A to EMA 20.
  • Set Input B to SMA 50.

Rules window

  • Open the Rules window with the ellipsis (…) button next to Expansion/Contraction Rules, then set the rule as shown. The rate is 2.5 Points.

Result

Long and Short outputs together, because expansion and contraction measure volatility, not direction.

Example 3: MACD expansion

Like 1B, but with the MACD (in effect two moving averages in another form): the MACD line moving away from its average can mean a trend move or continuation.

Settings and chart

Input settings

  • Set Input A to MACD » MACD.
  • Set Input B to MACD » Avg.

Rules window

  • Open the Rules window with the ellipsis (…) button next to Expansion/Contraction Rules, then set the rule as shown.

Result

Long and Short outputs together, because expansion and contraction measure volatility, not direction. A MACD crossover isn’t a perfect predictor of a reversal.

Example 4: Consolidation (contraction)

The opposite of 1B: moving averages coming together, which can coincide with price consolidation. Input A is a fast HMA of the median price, to smooth out the jumpy closes.

Settings and chart

Input settings

  • Set Input A to HMA, then nest Chameleon into it so the HMA uses the Median price (see the image).
  • Set Input B to SMA 50.

Rules window

  • Open the Rules window with the ellipsis (…) button next to Expansion/Contraction Rules, then set the rule as shown.

Result

Contraction is one way to identify consolidation. Long and Short outputs together, because expansion and contraction measure volatility, not direction.

Still stuck? Contact support