# Stops and targets in the graph

> Compute stop-loss and take-profit prices from swing points or ATR, and feed them into the trade entry.

Source: https://quantraider.com/learn/strategy-builder/exits-in-graph

Course: Building strategies as node graphs (lesson 3 of 5) · Level: Intermediate · 4 min

Entries get the attention, but the stop and target decide how much each trade risks and earns. You will learn to compute exits from recent swing points or ATR and to feed several of them into the `Trade entry` node.

## How exits enter the graph

The `Trade entry` node has an `Entry Price` input and named exit inputs: stop losses `SL1`, `SL2` and so on, and take profits `TP1`, `TP2` and so on. Each named input takes a price, not a distance, and each connected exit is recorded when `Trigger` is true. You can add more of either kind from the node itself.

So the job of the graph is to produce a price for every exit. For a long trade the stop price must be below the entry and the target above it. For a short trade (direction set to sell) it is the reverse.

## A swing-low stop

A swing-low stop sits just below a recent low, on the idea that if price falls beneath it, the trade idea is wrong. To find the lowest low of the last N candles, use memory nodes. `SlidingWindow` takes a `Value` and outputs `Values`, the last N values, with N set as its period. `Min` reads those `Values` and outputs the smallest in `Min`, with its `Position` in the window as a second output.

1. Connect `Data.Low` to the `Value` input of a `SlidingWindow` node and set its period, for example 10.
2. Connect `Values` to a `Min` node. Its `Min` output is the lowest low in the window.
3. Optionally add a `Subtract` node to place the stop a small buffer below it, with `Min` on `A` and a number constant on `B`.
4. Connect the result to `SL1`. Use `Max` over `Data.High` instead for a short trade.

**Worked example: A swing-low stop with a buffer and a 2R target**

1. The last ten lows are 98.40, 98.90, 98.10, 99.00, 99.30, 98.70, 99.50, 99.80, 99.20 and 99.60. The smallest is 98.10.
2. With a buffer of 0.10, the stop is 98.10 − 0.10 = 98.00.
3. With an entry at 100.40, the risk is 100.40 − 98.00 = 2.40.
4. A 2R target is 100.40 + 2 × 2.40 = 100.40 + 4.80 = 105.20.

Entry 100.40, stop 98.00, target 105.20: the stop distance follows the market's structure instead of being fixed.

Check in the replay whether the window includes the current candle, because that decides whether the stop can ever equal the candle's own low. A very distant swing low also gives a wide stop and, with fixed risk, a small position.

## ATR stops and several exits

An ATR stop, as in the previous lesson, uses `Subtract` of the close and `Multiply` of the `ATR` by a multiple such as 1.5. Its advantage over a swing stop is that it is always defined and scales with volatility. Its drawback is that it ignores where the market's structure actually lies.

Adding `SL2` or `TP2` lets you connect a second price, for example a nearer target at 1R in `TP1` and a further one at 2R in `TP2`, or a swing stop alongside an ATR stop. How the exits are combined in a trade, and which one is hit first, should be verified in the replay for your own graph rather than assumed.

**Common ways to compute a long stop.**

| Method | Nodes | Adapts to |
| --- | --- | --- |
| Fixed distance | `Subtract` close and a number constant | Nothing |
| ATR multiple | `ATR`, `Multiply`, `Subtract` | Volatility |
| Swing low | `SlidingWindow`, `Min`, `Subtract` | Recent structure |

> **Keep the stop on the right side**
>
> If the graph ever produces a long stop above the entry price, for example because a distant window low sits above a gapped entry, the trade makes no sense. Look at several trades in the replay and check the exit prices are where you intended.

> **Add exits to your graph**: Add a `SlidingWindow` over `Data.Low`, feed it to `Min` and connect the result to `SL1`. [Open the graph editor](https://quantraider.com/nodesystem)

## Key takeaways

- Each exit input of `Trade entry` takes a price: `SL1`, `SL2` for stops and `TP1`, `TP2` for targets.
- A swing-low stop is `SlidingWindow` over `Low` into `Min`, optionally with a small buffer subtracted.
- An ATR stop adapts to volatility, while a swing stop follows structure, and each has different weaknesses.
- Whenever you build exits, inspect the actual prices of trades in the replay.

> Educational content, not financial advice. Trading involves risk of loss.
