TradingView strategy research

Funding-rate carry research: unequal timing and liquidation risk

Funding rate arbitrage holds offsetting positions to seek a net funding receipt. A spot long can hedge a perpetual short, or a perpetual long at one venue can hedge a short at another. The result depends on actual settlement events, changing position values, relative prices and all costs. Equal underlying quantities reduce common price exposure but do not eliminate liquidation, execution or venue risk. Research both cash ledgers before interpreting a displayed funding-rate spread.

See the decision guide

Choose which two positions the ledger represents

This page studies cash flows rather than forecasting the next funding rate. The examples use linear contracts quoted and settled in USDT, with quantity expressed in BTC. One BTC of contract exposure changes by one USDT for each one-USDT price move. Contract counts must first be converted using the exchange multiplier.

  • A perpetual short is a derivative position; do not invent a spot-coin borrow charge for it. Add borrow costs only where an actual loan exists, including borrowed collateral.
  • Inverse contracts and collateral in a different currency require different payoff, funding and currency-conversion formulas. The linear USDT arithmetic below cannot be copied into them unchanged.
StructureFunding receipt soughtAdditional exposure
Buy spot, short perpetualPositive funding received by the shortSpot purchase capital, perpetual margin, basis changes and custody risk; financing applies if cash is borrowed.
Long perpetual A, short perpetual BFunding received on B less funding paid on ATwo settlement schedules, two margin accounts, venue price divergence and asynchronous fills.
Short borrowed spot, long perpetualNegative funding received by the longSpot borrow availability, variable borrow interest, collateral and forced repayment.

Record funding as dated cash flows

Bybit documents funding exchanges at settlement, positive rates paid by longs, and contract-specific intervals that can change. Its calculation for linear contracts uses quantity times mark price. Its settlement processing also makes entry or exit within five seconds of funding uncertain. Use the exchange transaction record to confirm eligibility instead of assuming that a chart bar captured payment.

  • The Bybit historical API returns fundingRate and fundingRateTimestamp; its ticker API separately exposes nextFundingTime. Archive the information available at each decision and join final events afterward. A current predicted rate is not a settled historical cash flow.
  • Do not infer old settlement schedules from today's interval. Deduplicate by venue, contract and event timestamp; paginate history and reconcile missing events against transaction records. An unknown rate is not zero.
  • For a rough comparison only, a constant 0.03% per eight hours implies 0.09% per 24 hours, while 0.005% per four hours implies 0.03%. The 0.06 percentage-point difference assumes unchanged rates, full eligibility and equal constant notionals. It is neither a realized daily return nor a dependable annual yield.
Ledger fieldRule
DirectionSet s = +1 for a long and s = -1 for a short; use positive absolute base quantity q.
One eligible eventCash flow CF(j,k) = -s(j,k) × q(j,k) × mark(j,k) × rate(j,k). A rate of 0.01% is 0.0001.
Holding windowSum CF only for settlement events at which the exchange confirms the position was eligible. Zero positions have zero funding.
Total fundingSum every eligible event across both legs, each with its own timestamp, quantity and mark. Do not forward-fill a rate and charge it on every chart bar.
Final resultNet P&L = both legs' price P&L + funding cash flows - trading costs - borrowing and financing costs - other applicable charges.

Worked example: three payments against one receipt

Assume fictional venues A and B and a 12-hour position from 02:00 to 14:00 UTC on one day. Buy 1 BTC of perpetual exposure on A at 60,000 USDT and short 1 BTC on B at 60,100. A settles every four hours and B every eight hours for this example. Both legs remain open for all events below. These are invented rates and reference prices, not market observations or a performance test.

  • The 00:00 and 16:00 events lie outside the holding window. The two 08:00 entries are separate postings; simultaneous labels do not allow one venue's credit to fund the other venue's debit instantly.
  • If B's 08:00 rate changes sign to -0.030%, the short pays 18.060 and total funding becomes -30.085 USDT. If its entry misses that event entirely, the receipt disappears and funding is -12.025. Retain both cases in the sensitivity analysis.
  • At 14:00, close A at a reference price of 60,200 and B at 60,280. Long price P&L is +200, short price P&L is -180, and combined price P&L is +20 USDT. The venue price difference narrows from 100 to 80 USDT.
UTC eventEligible leg and markSettled rateSigned cash flow (USDT)
04:00A long: 1 × 60,000+0.005%-3.000
08:00A long: 1 × 60,100+0.005%-3.005
08:00B short: 1 × 60,200+0.030%+18.060
12:00A long: 1 × 60,200+0.010%-6.020
TotalA pays 12.025; B receives 18.060Event sum+6.035

Positive carry does not cover the assumed costs

Continue the same example with a hypothetical 0.02% fee on each of four reference-price fills, a separate 12 USDT total execution allowance, and 2,000 USDT of borrowed collateral at 12% annual simple interest using actual elapsed days over 365. Assume no other charges and no intermediate rebalance. None of these cost inputs is a current exchange quote.

  • Under these reference-price assumptions, break-even funding is 40.444767 USDT: total costs of 60.444767 less the 20 price gain. The 6.035 receipt falls short. Round only the final report; the displayed result is approximately -34.41 USDT.
  • When using actual fills, their prices already incorporate execution slippage. Remove the separate allowance and calculate percentage fees from those actual fills. The reference-price fee calculation above is a simplified cost model.
  • Use the lender's actual interest accrual convention and changing balances in an execution ledger. If collateral is entirely owned, this loan-interest line is zero; opportunity cost can be reported separately. Add transfers, conversion, rebalance trades or liquidation charges when they occur.
  • Report return against stated committed equity, including reserves at both venues. Gross contract notional and margin deposits are different denominators. The page reports cash P&L because no complete capital allocation has been specified.
ComponentCalculationUSDT
Price P&L(60,200 - 60,000) - (60,280 - 60,100)+20.000
Funding18.060 - 3.000 - 3.005 - 6.020+6.035
Trading fees(60,000 + 60,100 + 60,200 + 60,280) × 0.0002-48.116
Spread and slippage allowanceAssumed total across the four fills-12.000
Borrowed collateral interest2,000 × 0.12 × (12 / 24) / 365-0.328767
Net result20 + 6.035 - 48.116 - 12 - 0.328767-34.409767

Test hedge error and each margin account separately

For fixed linear quantities, price P&L is qA × (Aexit - Aentry) - qB × (Bexit - Bentry). With qA = qB, a common price move cancels algebraically, but changes in B - A remain. With unequal quantities, the common-move component is (qA - qB) × price change. Matching entry dollar notionals does not necessarily match underlying quantities.

  • The margin row is a simplified stress check, not an exchange liquidation-price calculator. Actual rules use mark prices, risk tiers, maintenance deductions, fees, collateral eligibility and account mode. Test the path before exit; a final profitable pair can fail earlier through liquidation.
  • Track account equity minus required maintenance and a predeclared exit-cost reserve at each venue. OKX documents that funding deductions can reduce equity enough to trigger position reduction or liquidation. Do not count a pending transfer as available collateral or net separate venues into one fictional margin account.
  • If one leg partially fills, cancel its remainder and size the other leg to confirmed exposure or unwind under a predeclared rule. Include rejected orders, transfer freezes, outages and forced deleveraging in results; successful paired fills alone give an incomplete sample.
Failure testImplication
Long 1 BTC, short only 0.98 BTCResidual exposure is +0.02 BTC. A common +6,000 USDT move contributes +120 USDT; a -6,000 move contributes -120, before basis and funding effects.
Basis widens from 100 to 400 USDT with one BTC eachCombined price P&L is -300 USDT. A small funding receipt does not offset this loss.
B short has 3,000 USDT isolated collateralAt a 63,000 mark, a short entered at 60,100 has -2,900 unrealized P&L and 100 equity before costs. Under an illustrative 0.5% maintenance requirement, 315 is required, so this state breaches maintenance.
A long gains while B losesAt A = 63,000, its entry at 60,000 shows +3,000 price P&L. That gain at another venue cannot automatically prevent B's liquidation.
Prices fall or collateral loses valueThe long leg can instead approach liquidation. Cross-margin exposure, collateral haircuts and other positions can change either account's buffer.

Use Pine to observe the price hedge

The indicator below plots the price component of a fixed long-A/short-B position from manually entered reference prices. Put leg A on a standard time-based intraday chart and choose leg B with the same underlying and quote currency. Defaults are placeholders. It requires matching bar endpoints and confirmed chart bars; missing or mismatched observations stay blank. It does not fetch funding records, read accounts or reconstruct fills.

  • Using the example inputs, A = 60,200 and B = 60,280 produces +20 USDT. If A = 60,200 and B = 60,600, price P&L is -300 and the default -250 review threshold is exceeded. This is the price component only.
  • Choose compatible feeds and manually verify their currency, multipliers and timing. Bar-close trade prices are not necessarily the mark prices used for funding or liquidation. Timestamp agreement cannot prove executable simultaneous quotes.
  • The script holds its input quantities fixed and keeps observing after the start until you change the inputs or remove it. It has no position state or automatic exit. Missing data produces no alert and therefore requires an independent data-health check.
Pine Script v6 indicator for linear contracts in one quote currency. The alert is a review condition on completed bars, not an order or liquidation safeguard.pine
//@version=6
indicator("Funding carry price-hedge monitor", overlay = false)
string legB = input.symbol("BYBIT:BTCUSDT.P", "Short leg B; chart is long leg A")
float qtyA = input.float(1.0, "Long A base quantity", minval = 0.000001)
float qtyB = input.float(1.0, "Short B base quantity", minval = 0.000001)
float entryA = input.float(60000.0, "A reference entry", minval = 0.000001)
float entryB = input.float(60100.0, "B reference entry", minval = 0.000001)
float lossLimit = input.float(250.0, "Price-loss review threshold (quote currency)", minval = 0.000001)
int startTime = input.time(timestamp("01 Jan 2026 00:00 +0000"), "Evaluation start")
if not chart.is_standard or not timeframe.isintraday
    runtime.error("Use a standard time-based intraday chart.")
[priceB, openB, closeB] = request.security(legB, timeframe.period, [close, time, time_close], gaps = barmerge.gaps_on, lookahead = barmerge.lookahead_off, ignore_invalid_symbol = true)
bool aligned = not na(priceB) and not na(time_close) and openB == time and closeB == time_close
bool ready = aligned and barstate.isconfirmed and time >= startTime and close > 0 and priceB > 0
float pricePnl = ready ? qtyA * (close - entryA) - qtyB * (priceB - entryB) : na
plot(pricePnl, "Combined price P&L; excludes funding and costs", color = color.blue, linewidth = 2, style = plot.style_linebr)
plot(ready ? -lossLimit : na, "Price-loss review threshold", color = color.red, style = plot.style_linebr)
hline(0, "Zero price P&L", color = color.gray)
alertcondition(ready and pricePnl <= -lossLimit, "Review price loss", "Price hedge loss reached the review threshold. Check both venues and the external ledger.")

Keep settlement and execution tests outside Strategy Tester

TradingView can request another symbol for a calculation, but its broker emulator simulates strategy trades from chart data. A second requested series does not create a separately funded exchange position. A synthetic spread chart also does not establish either underlying fill. Maintain an external event ledger for both legs, funding, borrowing, collateral and liquidation checks.

  • Before evaluation, freeze an entry rule based only on information available then: expected receipts over a specified holding window must exceed expected payments, all round-trip costs and a stated uncertainty allowance. This is a screening condition, not proof that those future rates will settle.
  • For an illustrative test, reassess both venues at each completed hourly observation and every funding event, allow a maximum 12-hour holding period, and request an exit if estimated remaining carry turns negative or a margin buffer fails. Define executable fill and failure handling separately; risk events can occur between observations.
  • Reconcile every settled event to the exchange statement, then test a funding sign flip, changed interval, missed receipt, partial hedge and adverse basis move. Use later untouched dates to evaluate rules selected on earlier data.
  • Pine Script AI Coding Agent can help draft the observable price rule and its missing-data checks. Strategy Optimizer can compare inputs for a separate supported TradingView strategy. This indicator has no strategy orders to optimize, and that workflow does not supply the two-venue cash and margin ledger.
Where Pineify fits

Pine Script AI Coding Agent

Draft a price-hedge monitor with explicit quantities, reference prices and timing checks. Review the source and request syntax validation before comparing it with an external funding ledger.

Also useful: Strategy Optimizer. Compare inputs after defining a separate chart-symbol strategy with explicit costs. Two-venue funding, collateral and liquidation accounting remain external research tasks.

Draft a hedge monitor

Frequently asked questions

Educational research, not investment advice. All rates, prices, fees and margin figures in the examples are hypothetical. Funding, basis, liquidation and venue losses can exceed expected carry. Syntax validation does not establish economic validity, execution feasibility or future returns.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.