How a strategy graph works

Nodes, sockets and connections: how a graph turns candles into trade decisions, one candle at a time.

All courses · Lesson 1 of 5 · Intermediate · 4 min

In QuantRaider a strategy is a graph: nodes that read candle data, calculate, compare and finally place a trade entry. You will learn what nodes, sockets and connections are and how a graph is evaluated once for every candle.

Nodes, sockets and connections

A node is one small operation, such as reading prices, averaging them or comparing two numbers. Each node has sockets: input sockets on one side that receive values, and output sockets on the other that provide them. A connection is a line from an output socket to an input socket, and it carries the value the output produced for the current candle.

Sockets have a data type, for example a number, a boolean (true or false) or a list of numbers. A connection joins sockets of the same type. This is why a comparison such as GreaterThan, which outputs a boolean, can feed a logic node such as And, while an SMA, which outputs a number, feeds the numeric inputs of a comparison.

A `Data` node feeding two `SMA` nodes, whose outputs go into a `GreaterThan` node connected to the trigger of a `Trade entry` node.

The families of nodes

  • Data has no inputs. Its outputs are Open, Close, High, Low, Time, Volume, Spread at high and Spread at low for the current candle.
  • Indicators such as SMA, EMA, RSI, MACD and ATR turn prices into new series.
  • Maths and comparisons: Add, Subtract, Multiply, Divide, GreaterThan, LessThan, EqualTo and If.
  • Logic: And, Or and Not combine booleans.
  • Memory: PreviousValue returns the value from one candle earlier, and SlidingWindow returns the last N values, which Min, Max and GetNthValue can read.
  • Output: Trade entry places trades, and the VisualizeLine, VisualizeArrow and VisualizeHistogram nodes draw on the chart.

One candle at a time

The whole graph is evaluated once per candle, from the oldest candle in the test to the newest. On each candle every node computes its outputs from the values that arrive at its inputs, and the Trade entry node looks at its Trigger. If the trigger is true on that candle, a trade is recorded with the entry, stop and target values the graph produced on that same candle.

Because the graph only ever sees the current candle plus whatever memory nodes give it, it cannot peek at future candles. Anything that refers to the past has to be built explicitly, which is what PreviousValue and SlidingWindow are for.

Worked example

Evaluating a simple graph on three candles

  1. The graph is Data.Close into SMA 20 (fast) and SMA 50 (slow), and both into a GreaterThan node with the fast average on A and the slow one on B.
  2. Candle 1: fast = 99.80 and slow = 100.00. Is 99.80 > 100.00? No, so Result is false.
  3. Candle 2: fast = 100.30 and slow = 100.10. Is 100.30 > 100.10? Yes, so Result is true.
  4. Candle 3: fast = 100.50 and slow = 100.10. Is 100.50 > 100.10? Yes, so Result is true.

The output over the three candles is false, true, true: the graph produces one boolean per candle, and the later nodes only see that candle's value.

A note on this example

Notice that on candle 3 the output is still true even though nothing new happened. A plain comparison describes a state, not an event. Whether you want a state or an event is the central design question when you turn a rule into a graph, and the next lesson shows how to turn the state into a single crossing event.

Key takeaways

  • A strategy is a graph of nodes whose sockets are joined by typed connections.
  • The graph is evaluated once per candle, and each node only sees values for the current candle plus what memory nodes provide.
  • A comparison describes a state that can stay true for many candles, which is different from an event that happens once.
  • PreviousValue and SlidingWindow are how a graph looks back at earlier candles.

Sign in to save your progress and quiz results.