> ## Documentation Index
> Fetch the complete documentation index at: https://docs.0xarchive.io/llms.txt
> Use this file to discover all available pages before exploring further.

# 4h EMA

> An EMA of 4-hour bars on any chart, with no lookahead.

<Frame caption="BTC on 15-minute bars in the 0xArchive Terminal, 2026-10-15.">
  <img src="https://mintcdn.com/0xarchive-e895b8e7/_p6Z1TtSEb5DBnPX/images/terminal/examples/higher-timeframe.webp?fit=max&auto=format&n=_p6Z1TtSEb5DBnPX&q=85&s=9888555438e343d076a241f4edfb405a" alt="4h EMA on a BTC chart" width="1038" height="664" data-path="images/terminal/examples/higher-timeframe.webp" />
</Frame>

<Card title="Open on a chart" icon="chart-candlestick" href="https://terminal.0xarchive.io/?symbol=BTC&interval=15m&scripts=example%3Ahigher-timeframe" horizontal>
  Load it on BTC 15m in the terminal, then change its settings or open it in the script editor.
</Card>

A 20-period EMA of the 4-hour closes, drawn on a 15-minute chart. It steps when each 4-hour bar closes.

## How it works

`bars({ interval: '4h' })` is a second stream with its own handler, which updates the EMA. The chart's handler reads `ema.confirmed`: the value as of the last closed 4-hour bar. That is the [no-lookahead rule](/terminal/guides/data#as-of-no-lookahead): history only ever sees what was known at the time, so the line is drawn where it would have been live.

## The script

```ts higher-timeframe.ts theme={"theme":"github-dark"}
// A 4h EMA on any chart. Reading another stream gives its last closed value: no lookahead.
indicator('4h EMA', { overlay: true });

const length = input.int('Length', 20, { min: 1 });

const chart = bars();
const h4 = bars({ interval: '4h' });
const ema = ta.ema(length);
const line = plot.line('4h EMA', { width: 2 });

h4.onBar(() => {
  ema.update(h4.close);
});

chart.onBar(() => {
  line.set(ema.confirmed);
});
```

## Next step

See the next example, [Anchored VWAP bands](/terminal/examples/anchored-vwap).


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.