> Every Taji docs page as Markdown: https://docs.taji.is/llms.txt

# Draw the prior day's high, low and close

This indicator draws three horizontal levels over an intraday chart: the high, the low and the close of the session before the one you are looking at. Each session's three levels are flat segments that start on the session's second bar.

You need a running Taji and a way to add an indicator to a chart: ask your [connected agent](https://docs.taji.is/guide/agent.md) to write and bind this source, or make the write and bind calls yourself as [Your first indicator](https://docs.taji.is/indicators/first-indicator.md) does. Set the chart to an intraday interval first: on a daily chart every bar is a session of its own.

Taji ships a Prior Day Levels indicator that reads the vendor's daily bar. This one builds the levels from the bars on your chart, to show how an anchor input and an indicator's state work together.

```ts file="examples/prior-day-levels/prior_session_levels.ts" title="prior_session_levels.ts"
import { indicator, input, plot } from "@taji/indicators";

export default indicator({
  name: "Prior session levels",
  pane: "price",
  inputs: { day: input.anchor("session") },
  plots: {
    prior_high: plot.step_breaks({ title: "Prior high", color: "#26a69a" }),
    prior_low: plot.step_breaks({ title: "Prior low", color: "#ef5350" }),
    prior_close: plot.step_breaks({ title: "Prior close", color: "#ff9800" }),
  },
  setup: () => ({ high: NaN, low: NaN, close: NaN, prior_high: NaN, prior_low: NaN, prior_close: NaN }),
  next(bar, s, { inputs }) {
    const starts = inputs.day.starts;
    if (starts) {
      s.prior_high = s.high;
      s.prior_low = s.low;
      s.prior_close = s.close;
      s.high = bar.high;
      s.low = bar.low;
    } else {
      s.high = Math.max(s.high, bar.high);
      s.low = Math.min(s.low, bar.low);
    }
    s.close = bar.close;
    const draw = (level: number) => (starts ? NaN : level);
    return { prior_high: draw(s.prior_high), prior_low: draw(s.prior_low), prior_close: draw(s.prior_close) };
  },
});
```

![A 15-minute SPY chart with three horizontal lines over the candles, teal at the prior session's high, red at its low and orange at its close, each a separate flat segment per session](https://raw.githubusercontent.com/TajiAI/Taji/main/docs/cookbook/examples/prior-day-levels/shot.png)

1. **`import { indicator, input, plot }`** takes what it needs from `@taji/indicators`. There is no `ta` here: the levels are plain numbers.
2. **`inputs: { day: input.anchor("session") }`** declares an anchor input. In `next` it is `{ starts, period_start }`: `starts` is true on the first bar of each session and on the first bar of the chart, and `period_start` is that session's first trading day as `yyyymmdd`. The kernel computes it from the instrument's calendar, so you never compare timestamps yourself. An anchor exists per bar only: reading it in `setup` throws.
3. **`pane: "price"` and `plots`** draw three `step_breaks` lines over the bars, on the price scale. A step line holds each value flat across the bar, and `step_breaks` leaves a gap where the value is `NaN`. That is how the first session, with no session before it, draws nothing, and how each session's levels end up as their own segments.
4. **`setup`** returns the state, six numbers that start as `NaN` (na): the running `high`, `low` and `close` of the current session, and the three `prior_` values the plots show. The kernel commits the state on each close and restores it on each tick of the forming bar, so you mutate it freely.
5. **`const starts` and `if (starts)`** read the anchor once, and the `if` runs on the first bar of a session. The running values then hold the session that has just ended, so they become the `prior_` values, and the running `high` and `low` start over from this bar.
6. **`else`** widens the running `high` and `low` with each later bar of the session.
7. **`s.close = bar.close`** keeps the latest close, so on the next session's first bar it is the last bar's close of this one.
8. **`draw` and `return`** give the three `prior_` values for every bar except a `starts` bar, where `draw` returns `NaN`. The values do not change inside a session, so each plot is flat, and the gap on the `starts` bar breaks the line there: the old session's levels end, and the new session's begin on the next bar, with no vertical step between them.

The kernel serves the indicator's rows, one per bar. These are ten of them (the example's `rows.jq` picks them): the last three bars of one session, then the first seven of the next, the first of them its `starts` bar:

```json file="examples/prior-day-levels/prior_session_levels.json"
[
  {
    "start_dt": "2026-12-03T20:15:00+00:00",
    "prior_high": 143.99,
    "prior_low": 142.7,
    "prior_close": 143.51
  },
  {
    "start_dt": "2026-12-03T20:30:00+00:00",
    "prior_high": 143.99,
    "prior_low": 142.7,
    "prior_close": 143.51
  },
  {
    "start_dt": "2026-12-03T20:45:00+00:00",
    "prior_high": 143.99,
    "prior_low": 142.7,
    "prior_close": 143.51
  },
  {
    "start_dt": "2026-12-04T14:30:00+00:00",
    "prior_high": null,
    "prior_low": null,
    "prior_close": null
  },
  {
    "start_dt": "2026-12-04T14:45:00+00:00",
    "prior_high": 142.15,
    "prior_low": 140.16,
    "prior_close": 140.88
  },
  {
    "start_dt": "2026-12-04T15:00:00+00:00",
    "prior_high": 142.15,
    "prior_low": 140.16,
    "prior_close": 140.88
  },
  {
    "start_dt": "2026-12-04T15:15:00+00:00",
    "prior_high": 142.15,
    "prior_low": 140.16,
    "prior_close": 140.88
  },
  {
    "start_dt": "2026-12-04T15:30:00+00:00",
    "prior_high": 142.15,
    "prior_low": 140.16,
    "prior_close": 140.88
  },
  {
    "start_dt": "2026-12-04T15:45:00+00:00",
    "prior_high": 142.15,
    "prior_low": 140.16,
    "prior_close": 140.88
  },
  {
    "start_dt": "2026-12-04T16:00:00+00:00",
    "prior_high": 142.15,
    "prior_low": 140.16,
    "prior_close": 140.88
  }
]
```

*Captured 2026-12-04 on a headless kernel reading made-up 15-minute bars for SPY.*

- The first three rows are the last bars of 2026-12-03, at 15:15, 15:30 and 15:45 New York time (20:15 to 20:45 UTC). They carry the levels of the session before it: high 143.99, low 142.70, close 143.51.
- The fourth row, 14:30 UTC on 2026-12-04, is the session's first bar, 09:30 in New York, and `starts` is true on it. All three levels are `null` there: that is the break between the two sessions' lines.
- The next row onward carries 142.15, 140.16 and 140.88: the high, low and close of 2026-12-03, the session the first three rows closed. They were captured while 2026-12-04 was still trading, so its own high, low and close are not drawn yet: they become levels at the next `starts` bar.
- The first session the chart holds has no session before it, so nothing is drawn there, and the levels it produces cover only the bars the chart holds.

## Change it

Draw the prior week's levels instead: change the anchor's period to `"week"`, which starts on a week's first trading bar even when its Monday is a holiday.

```diff
-  inputs: { day: input.anchor("session") },
+  inputs: { day: input.anchor("week") },
```

Add the midpoint between the prior high and low as a fourth line:

```diff
     prior_close: plot.step_breaks({ title: "Prior close", color: "#ff9800" }),
+    prior_mid: plot.step_breaks({ title: "Prior mid", color: "#9e9e9e" }),
   },
```

```diff
-    return { prior_high: s.prior_high, prior_low: s.prior_low, prior_close: s.prior_close };
+    return {
+      prior_high: s.prior_high,
+      prior_low: s.prior_low,
+      prior_close: s.prior_close,
+      prior_mid: (s.prior_high + s.prior_low) / 2,
+    };
```

## Next

- [Inputs](https://docs.taji.is/indicators/inputs.md): sources, anchors and declared data, and when each is readable.
- [Outputs](https://docs.taji.is/indicators/outputs.md): every plot kind, colour, fill and drawing an indicator can return.
- [Indicator reference](https://docs.taji.is/skill/references/indicators.md): every field, kind, default, limit and refusal.
