> ## 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.

# Funding carry

> Take the side funding pays when it runs at an extreme, and see whether it pays after fees, slippage from the order book and the funding itself.

![Funding carry on a BTC chart](https://mintcdn.com/0xarchive-e895b8e7/u1GQz1wPm3Z-VTMN/images/terminal/examples/funding-carry.webp?fit=max\&auto=format\&n=u1GQz1wPm3Z-VTMN\&q=85\&s=b34ebbba08e2120c2f04396dd8b504b9)

BTC on 1-hour bars in the 0xArchive Terminal, 2026-10-25.

> **[Open on a chart](https://terminal.0xarchive.io/?symbol=BTC\&interval=1h\&scripts=example%3Afunding-carry)**
>
> Load it on BTC 1h in the terminal, then change its settings or open it in the script editor.

When funding runs at an extreme, one side pays the other every hour. This strategy takes the side that is paid while the rate, smoothed over a day, is more than 40% a year either way, and stands aside once it is back under 10%. The histogram is the smoothed rate, a year's worth, red where longs pay and green where shorts do.

## How it works

`funding()` reads the rate each hour settled, and `ta.ema` smooths it over 24 hours. Above the entry threshold `strategy.target(-1)` goes fully short (longs pay shorts when the rate is positive); below its negative, fully long; back inside the exit band, flat. Between the two bands the position holds.

The funding is the whole edge, so the costs decide the answer. The strategy pays the venue's fee on every fill and what the order book charged for the order's size (2 bps a fill where the archive has no reading), and collects or pays funding every hour it holds. The Strategy report puts each beside the gross result, so you can see whether the carry outran the cost of getting in and out, and how far price moved against it meanwhile.

## The script

```ts funding-carry.ts theme={"theme":"github-dark"}
// Funding carry: when funding runs at an extreme, take the side it pays and collect it; stand aside
// when it is ordinary again. The funding is the whole edge, so what it costs to get in and out
// decides whether it pays, and the Strategy report shows each: fees, slippage from the order book,
// and the funding received.
strategy('Funding carry', { shortName: 'Carry', precision: 0, from: '2025-03-01' });

const enter = input.float('Enter above (% a year)', 40, { min: 1, max: 500 });
const leave = input.float('Leave below (% a year)', 10, { min: 0, max: 500 });
const smoothing = input.int('Smoothing (hours)', 24, { min: 1, max: 500 });
const sides = input.choice('Trade', 'both', ['both', 'long', 'short'], { labels: { both: 'Long and short', long: 'Long only', short: 'Short only' } });

const chart = bars();
const fund = funding();
const yearly = ta.ema(smoothing);

const rate = plot.histogram('Funding', { color: color.neutral, unit: '% a year' });
plot.level('Zero', 0, { color: color.neutral, style: 'dotted' });

chart.onClose(() => {
  const apr = yearly.update(fund.rate({ hours: 8760 }) * 100);
  if (isNa(apr)) return;
  // Positive funding: longs pay shorts, so the carry is short.
  // Each side is its own trade: short only collects the positive extremes and sits out the rest.
  if (apr > enter && sides !== 'long') strategy.target(-1);
  else if (apr < -enter && sides !== 'short') strategy.target(1);
  else if (Math.abs(apr) < leave) strategy.target(0);
  rate.set(apr, apr > 0 ? color.down : color.up);
});
```

## Next step

See the next example, [RSI PCA forecast](https://docs.0xarchive.io/terminal/examples/rsi-pca-forecast.md).


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