November 29, 2026 · paper

Your backtest flipped the perp. Hedge mode opened a second position.

Your backtest flipped the perp. Hedge mode opened a second position.

The agent handed us an ETHUSDT mean-reversion on 5-minute bars: z-score of close versus a 24-bar VWAP, flip at 1.8, always 25 ETH, taker in and out. Ninety days in the simulator looked like a thing we could paper. 312 flips, average hold 2.4 hours, Sharpe 1.15 after 5.5 bps and funding. The position column was a single signed integer. It never held more than 25 ETH, and it never held both directions at once, because the backtest did not have a word for that.

We pushed the same signal onto a Bybit USDT perpetual on a Tuesday in October, $80,000 paper, 10× isolated, or so we believed. First order at 09:14 UTC sold 25 ETH at 3,184.60. Paper and backtest both showed short 25. I went to lunch.

At 14:07 the z-score crossed +1.8. The research code did what every one-way simulator does: buy 50, close the short and open the long in a single ticket. Bybit filled a buy of 50. The panel then had two rows. Long 50 at 3,176.20, short 25 at 3,184.60. Net +25, which is what the backtest showed, so the dashboard we had built on net position stayed green. An intern Slack-screenshotted the red box and the green box and asked whether the agent had quietly turned us market-neutral. I said something about average-entry display and did not open the position-mode endpoint.

That is the ugly part of this bug. For a while, mark-to-market agrees. The extra long and the leftover short are a round trip the backtest already realized, just still sitting on the book. Funding nets too, if the rate is applied symmetrically: longs pay on 50, shorts receive on 25, net pay on 25, same as a 25 ETH long. Fees matched because both systems traded 50 ETH on the flip. We had built a reconciliation on net delta, net funding, and taker volume, and it was congratulating us.

4flips before net still matched
225 ETHgross vs 25 ETH intended
$71,550initial margin on an $80k paper account

Wednesday it flipped again at 02:41, sell 50. Hedge mode has no idea you meant "close long, open short." It added 50 to the short. Long 50, short 75, net −25. Flip three, buy 50: long 100, short 75. Flip four, sell 50: long 100, short 125, gross 225 ETH. Initial margin at 10% and $3,180 is $71,550. The account was $80,000. Available balance was a sliver. I remember the maintenance bar in the UI sitting at 78% and thinking the vol-of-vol on ETH had picked up. And the backtest, still living in one-way land, showed a tidy −25 and a margin line of $7,950.

Thursday 11:22, fifth flip. Signal wanted long. Backtest bought 50 at 3,192.40 and went +25. Paper sent the same buy and Bybit rejected it: insufficient available balance. The next 50 ETH at 10% needed about $16,000 of free margin we did not have, because we were already posting on 225. From that bar on, the two systems had opposite net exposure. They had agreed for 26 hours by accident.

ETH ran $118 into the 08:00 Friday print, 3,192 to 3,310. The backtest's new long made about $2,950. The paper book was still long 100 and short 125, net −25, and lost the same $2,950. Same magnitude, flipped sign, from one rejected order that the research run was not capable of emitting. We needed the gross position, not the net, and we had never logged it.

I did this by hand on Binance in 2021, before I knew hedge mode was a setting. For two days I thought I had invented a market-neutral ETH harvest. I had invented a confused mean-reversion with two liquidation prices.

Bybit, Binance, OKX, the whole perp world will let an account sit in hedge mode as a leftover from some earlier options-style experiment or a UI default. One-way treats a buy of 50 against a 25 short as a flip. Hedge mode treats it as an opening ticket on the long index unless you send reduceOnly and a position index for the short, then a second order to open the long. The agent had emitted create_order(symbol, 'market', 'buy', 50) because that is what the backtest's order object looked like. No positionIdx. No flatten-then-open. The simulator stored qty = +25. The venue stored two tickets whose sum happened to be +25 until it didn't.

IntentOne-way (what the backtest did)Hedge, no position index (what paper did)Hedge, done on purpose
Flip short 25 → long 25Buy 50; net +25; one liquidation priceOpen long 50, leave short 25; two liquidation pricesReduce-only buy 25 on the short, then buy 25 on the long
Flip againSell 50; still |net| = 25Add 50 to the short; gross 125, 175, 225…Close the long reduce-only, then open short 25
MarginOn 25 ETH (~$8k at 10×)On gross; $71.5k by flip fourOn 25 ETH if you actually closed
Fifth flip on an $80k accountFills; now longRejects; still net shortFills; now long
Flatten FridayTrade 25 ETH, doneA 25 ETH order adds a third mistakeReduce-only both sides to zero

The Friday flatten was the last joke. Backtest sold 25 and went flat for the weekend. Someone sent sell 25 at paper, without reduce-only, and the short became 150. We then closed it properly: reduce-only sell the long 100, reduce-only buy the short 150. Two orders, 250 ETH of notional, to undo a strategy that believed it was holding 25. Funding at 08:00 still printed on both tickets. It was a few dollars. It was also the first number that had been trying to tell us all week that two position books existed.

Before the first paper order, read the venue's position mode and write it next to the fill. Log long size, short size, net, and reduceOnly on every ticket. If your recon is net-only, hedge mode will pass it until the first reject, and the first reject is how you end up long in research and short in the account that was supposed to answer it.

We made position mode a property of the exchange adapter, the same way tick size already was. One-way paper accounts keep a signed qty. Hedge accounts require a two-step flip and will refuse a net-only order object. The research agent now sees a failed pre-trade check if it emits a flip without a close. I still don't love hedge mode for a strategy that is never actually hedged. But if the account is in it, the backtest has to be in it too, or the paper run is answering a different question than the one you asked.

paper tradingcrypto futureshedge modemarginexecution
← All posts