The Order Didn't Fit. Drop It, Fill It at the Close, or Shrink It — I Ran All Three.
The short version. Post #20 ended with an order the account couldn't afford — 3 contracts at the fill open cost $9,738.72 against $9,687.31 of equity, $51.41 short, dropped silently. Kamal asked in #20's comments: when that happens, should the backtest drop the order, fill it at the close price, or shrink it to what fits? I ran all three, each with the fee on and off. Same script, same 4,089 bars, same $10,000:
- A — drop (the #20 run): +$937.45, PF 1.117, 47 trades.
- B — fill at close: +$1,299.37, PF 1.157, 47 trades. Delta vs A: +$361.92.
- C — size on the fill price: +$2,938.98, PF 1.385, 44 trades. Delta vs A: +$2,001.53.
Then the fee-off control flipped the ranking: without the fee, B loses to A by $864.31, and C's lead shrinks to +$718.92. The fee doesn't just deduct $359.12 — through the equity path it decides whether the dropped order exists at all. And the rescued trade itself is a minority of every delta: the policies mostly move the headline by reshaping which other trades ever happen.
One correction first: post #21 mislabeled the date. The signal was 2015-08-27 (bar 1372, close 3,205.64); 2015-08-28 (bar 1373, open 3,246.24) is the fill bar. The numbers in #21 were right; the date in the prose was wrong. Fixed here, and the bar numbers below use the fill bar only where stated.
The contract: one question, chosen before I looked
Kamal's question, from #20's comments, word for word in spirit: when an order doesn't fit the account, fill it at the close price or shrink it to what fits? He also set the terms: the split test must run a no-fee baseline under the same sizing rule, or the fee confounds the answer. This post is that test.
Three policies, each a one-line change to the #20 script, each run end to end — because a fill policy is a convention for the whole backtest, not a patch for one order. Each policy runs twice: with the 0.1% round-trip fee (0.05% per side) and with commission zero. Six runs, one script family, one dataset.
A — drop. The #20 script, byte-identical. A market entry sized at the signal close; the engine judges the order again at the fill bar's open and rejects it outright when the same quantity costs more than the account holds. Nothing is logged. The order just never exists.
B — fill at close. One addition to strategy():
strategy("RSI Mean Reversion (fill at close, fee 0.1% round-trip)", overlay=true, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0.05,
default_qty_type=strategy.percent_of_equity, default_qty_value=100, process_orders_on_close=true)
Every market order now fills at the bar's close — the price the signal was computed on. The unaffordable order is sized on the signal close and filled at that same close, so it always fits. This is the convention the naive vectorized backtest assumes without saying so.
C — size on the fill price. One change to the entry line:
strategy.entry("Long", strategy.long, stop=close)
The market entry becomes a buy stop at the signal close. A price-based order resolves its quantity at the actual fill price, so when the fill bar gaps up, the order shrinks to what fits instead of being dropped. This is the convention the timevolt-style event loop bakes in silently with int(notional // price) at the open — sized on the fill price, never named as a choice.
The compiled Python, verbatim from the local compiler (node bin/pine2pyne.mjs, zero diagnostics on all six) — the only lines that differ:
# B, the strategy line only:
@script.strategy(title="RSI Mean Reversion (fill at close, fee 0.1% round-trip)", overlay=True, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0.05, default_qty_type=strategy.percent_of_equity, default_qty_value=100, process_orders_on_close=True)
# C, the entry line only:
strategy.entry("Long", strategy.long, stop=close)
# fee-off runs, the strategy line only:
@script.strategy(title="RSI Mean Reversion (drop, no fee)", overlay=True, initial_capital=10000, commission_type=strategy.commission.percent, commission_value=0, default_qty_type=strategy.percent_of_equity, default_qty_value=100)
A fill policy is not a detail of the backtest. It is the backtest — the part that decides which trades exist. If you never chose one, your software chose for you, silently.
Probe 1: the headline — three policies, six runs
| A drop, fee | B close, fee | C stop, fee | A drop, no fee | B close, no fee | C stop, no fee | |
|---|---|---|---|---|---|---|
| Closed trades | 47 | 47 | 44 | 48 | 47 | 44 |
| Net profit | +$937.45 | +$1,299.37 | +$2,938.98 | +$2,530.24 | +$1,665.93 | +$3,249.16 |
| Profit Factor | 1.117 | 1.157 | 1.385 | 1.302 | 1.208 | 1.435 |
| Win rate | 18 / 47 (38.3%) | 15 / 47 (31.9%) | 16 / 44 (36.4%) | 19 / 48 (39.6%) | 18 / 47 (38.3%) | 16 / 44 (36.4%) |
| Gross profit / gross loss | +$8,951.70 / −$8,014.25 | +$9,552.61 / −$8,253.24 | +$10,572.36 / −$7,633.38 | +$10,908.26 / −$8,378.02 | +$9,688.12 / −$8,022.19 | +$10,718.87 / −$7,469.71 |
| Avg win / avg loss | $497.32 / −$276.35 | $636.84 / −$257.91 | $660.77 / −$272.62 | $574.12 / −$288.90 | $538.23 / −$276.63 | $669.93 / −$266.78 |
| Avg hold | 16.15 bars | 17.83 bars | 18.09 bars | 17.04 bars | 17.83 bars | 18.09 bars |
| Median trade | −$172.61 | −$152.24 | −$150.47 | −$161.62 | −$142.62 | −$152.62 |
| Fees paid | $359.12 | $372.55 | $385.72 | $0.00 | $0.00 | $0.00 |
| Max equity drawdown | $2,231.62 (21.01%) | $2,048.16 | $1,623.61 | $1,881.50 | $1,948.16 | $1,581.10 |
| Top-5 winners' share | 67.6% | 63.8% | 65.1% | 63.7% | 63.3% | 64.7% |
| Net minus biggest winner | −$936.86 | −$574.69 | +$599.03 | +$168.70 | −$217.63 | +$898.45 |
| Exit split (trail / stop) | 28 / 19 | 29 / 18 | 27 / 17 | 29 / 19 | 29 / 18 | 27 / 17 |
Three things to notice before the mechanisms.
First, C is the only policy whose headline survives its biggest winner — +$599.03 with the fee, +$898.45 without. A and B both go negative without theirs (A: −$936.86). But C also takes the fewest trades (44 vs 47) — it doesn't win by trading more. It wins by trading different trades, which is Probe 5's story.
Second, the fee-off column is not a small perturbation. Removing a 0.1% fee moves A's net by +$1,592.79 — 4.4× the $359.12 actually paid. A fee that small should cost what it costs. It doesn't, and Probe 3 is why.
Third, B's win rate falls to 31.9% with the fee on while its net rises — the same wrong-way pattern as #21's 3× trail (27.7% wins, most money). The fill policy, like the trail distance, moves the money through which trades happen, not through being right more often.
Probe 2: the rescued trade, four ways
The order at the center of all this: signal bar 1372 (2015-08-27, RSI crosses up through 30, close 3,205.64). The engine sizes 3 contracts on that close — 3 × 3,205.64 = $9,616.92, inside the account. At the fill bar's open (2015-08-28, 3,246.24), the same 3 contracts cost $9,738.72. Equity at the signal: $9,687.31. Short $51.41. The gate is judged at the fill price, not the sizing price — that one sentence is the whole drop.
| A, fee on | A, no fee | B, fee on | C, fee on | |
|---|---|---|---|---|
| Equity at signal 1372 | $9,687.31 | $9,844.03 | $9,707.90 | $9,962.44 |
| Entry | — (dropped) | 3 @ 3,246.24 (bar 1373) | 3 @ 3,205.64 (bar 1372) | 3 @ 3,246.24 (bar 1373) |
| Exit | — | bar 1432, trail | bar 1431, trail | bar 1432, trail |
| Profit | — | +$925.95 | +$1,043.91 | +$915.75 |
Four things to notice.
First, the no-fee A run fills the order. Same policy, same sizing rule — but without the fee, the equity path runs $156.72 higher by bar 1372 ($9,844.03 vs $9,687.31), the 3 contracts fit, and the trade exists. The drop is not a property of the policy alone. It is a property of the policy and the equity path, and the fee moves the equity path.
Second, B's version is worth the most (+$1,043.91) because it buys a bar earlier at the cheaper close — and exits a bar earlier (1431 vs 1432), because its trail started tracking one bar sooner. Same signal, same exit rules, $128.16 more than C's version, from one bar of timing.
Third, C's version is 3 contracts, not 2. The shrink never fired here: C's equity at the signal was $9,962.44 (its own, different path), so 3 at the fill price fit. The fee on that trade checks out to the cent — C's fee-on profit is $10.20 below its no-fee twin, and 0.05% × (3 × 3,246.24 + 3 × 3,554.89) = $10.20 exactly.
Fourth — and this is the number that matters for the whole post — the rescued trade is +$915.75 to +$1,043.91, while the headline deltas are +$361.92 (B) and +$2,001.53 (C). For B, the rescued trade is bigger than the whole delta; for C, it is less than half. Something else is doing the rest of the work in both cases.
Probe 3: the fee costs 4.4× what it charges — under policy A
Within each policy, fee-on net minus fee-off net, against the fees actually paid:
| Policy | Fee-on minus fee-off | Fees paid | Ratio |
|---|---|---|---|
| A drop | −$1,592.79 | $359.12 | 4.4× |
| B close | −$366.56 | $372.55 | 1.0× |
| C stop | −$310.18 | $385.72 | 0.8× |
Under B and C, the fee costs about what it charges (1.0×, 0.8×). Under A, it costs 4.4× — because the fee, through the equity path, deletes a trade. Decomposed by signal bar: of A's −$1,592.79, +$925.95 is the rescued trade existing in the no-fee run and not in the fee run, and +$666.84 is the same 47 signals performing differently (different equity paths → different quantities and different exits on identical signals). The fee doesn't just deduct. Under the drop policy, it edits the trade list.
This is the confound Kamal warned about, and it landed harder than either of us guessed: the "policy effect" and the "fee effect" cannot be separated by toggling commission, because toggling commission changes which orders fit. Any split test that runs only with the fee on is measuring the policy and the fee's shadow at once.
Probe 4: the ranking flips without the fee
| Fee on | No fee | |
|---|---|---|
| B minus A | +$361.92 | −$864.31 |
| C minus A | +$2,001.53 | +$718.92 |
With the fee on, B beats A by $362. Without it, B loses by $864. The entire flip is one trade: signal 488. In the fee-on runs, A takes signal 488 for +$894.54 while B, still sitting in its signal-485 trade, correctly ignores it; B's rescue of 1372 (+$1,043.91) outweighs that loss, plus $212.55 on the 46 common signals. In the no-fee runs, A fills 1372 itself (+$925.95), so B's rescue is worth nothing — and B still loses signal 488 (−$901.86), with only +$37.55 on the 47 common signals to offset it.
C beats A in both worlds, but the margin collapses from +$2,001.53 to +$718.92, and the common-signal delta flips sign (+$208.35 with the fee, −$561.55 without). The ranking "C > A" is stable; the size of the win is not. The ranking "B > A" is not stable at all — it is an artifact of the fee deciding whether one order fits.
If you report a fill-policy comparison from fee-on runs only, you are reporting the fee's opinion, not the policy's.
Probe 5: where the deltas actually come from — matched by signal
Matching trades by their signal bar (not entry bar — B shifts every entry a bar earlier, C delays some), fee-on runs:
B vs A (+$361.92): 46 common signals, +$212.55. Only in B: signal 1372, +$1,043.91 (the rescue). Only in A: signal 488, +$894.54 (B was still in its 485 trade when 488 fired). The rescue is the largest single piece — and the lost 488 trade cancels 86% of it.
C vs A (+$2,001.53): 40 common signals, +$208.35. Only in C: 4 signals, +$363.74 (1372 +$915.75, 1337 −$160.38, 1462 −$617.77, 2483 +$226.14). Only in A: 7 signals, −$1,429.45 (78 −$517.59, 1334 −$83.50, 1460 −$459.34, 1464 −$411.77, 2062 −$289.89, 2481 +$563.91, 3095 −$231.27). C's gain is dominated by the seven trades it never took — six losers and one winner — not by the trade it rescued. The stop policy's resting orders delay entries, the delays overlap later signals, and the signals that get skipped happen to be the bad ones. On this sample. That is luck wearing a policy's clothes until the placebo post says otherwise.
The single most dramatic signal is 485. Same signal, three fills:
| A, fee on | B, fee on | |
|---|---|---|
| Entry | 3 @ 2,361.50 (bar 486) | 3 @ 2,345.74 (bar 485) |
| Exit | bar 488, stop | bar 532, trail |
| Profit | −$294.07 | +$712.03 |
One signal, a $1,006.10 swing, from the fill rule alone: B buys at the signal close, holds 44 bars longer, and exits on the trail instead of the stop. Five signals flip sign between A and B in the fee-on runs (485 is the big one; 975, 1475, 2812, 3524 are small ones). Between A and C, three flip — all small.
Two more facts about C's entry stream, because they are the policy, not footnotes: 7 of its 44 closed fills came one bar late — and an eighth (signal 4081 → fill 4086) is the final trade, still open at the end. When the fill bar gaps down, the stop rests; the next signal replaces it; the fill eventually comes at a later signal's close. And the shrink never fired once: across all 44 fills, the stop policy's quantity was never smaller than the market policy's on the same signal. The mechanism Kamal asked for — shrink to fit — exists in the code path and never engaged on this data, because whenever the fill price was above the signal close, the equity path had room. A policy that never fires is not a tested policy.
Probe 6: the slippage column (Kamal's ask)
Per entry, fill price minus signal-bar close, closed trades only:
| A, fee on | B, fee on | C, fee on | |
|---|---|---|---|
| Total slippage cost | −$973.91 | $0.00 | +$1,122.30 |
| Mean / median | −9.62 / −6.52 pts | 0.00 / 0.00 pts | +10.27 / +0.00 pts |
| Range | −120.69 to +81.59 pts | 0 | −0.00 to +86.37 pts |
| Fills above / below signal close | 15 / 32 | 0 / 0 | 27 / 0 (17 exactly at) |
Three readings. Under A, the gap is a tailwind: 32 of 47 fills come in below the signal close, and the total is −$973.91 — the open-vs-close gap pays this mean-reversion script, because its signals cluster on selloff days that gap down again. Anyone who assumes "slippage is always a cost" has not looked at their own fills. Under B, slippage is $0.00 by construction — the fill is the signal close, which is exactly why B's numbers flatter the strategy: it never pays the gap in either direction. Under C, the stop only triggers when price comes back up to the close, so C systematically buys the up-move: 27 fills above the signal close, 17 exactly at it, none below, +$1,122.30 total. C pays $2,096.21 more in entry prices than A — and still nets $2,001.53 more, because the entry-stream reshaping (Probe 5) outweighs the entry-price disadvantage. The worst single C fill: signal 3705, +$187.02 (fill 3,749.13 vs signal close 3,686.79, 3 contracts).
So which policy?
None of the three — not on this evidence. Each is a different backtest, and the ranking between them depends on the fee, which is the one thing the ranking is supposed to be independent of. What the six runs do establish, in our testing:
- The fill policy is a first-order choice: $2,001.53 of headline between the best and the worst, on one script, one market, 4,089 bars.
- The rescued trade is not the story. It is +$916 to +$1,044 — and the deltas are made of skipped signals, lost signals, and equity-path knock-ons that are each as large.
- The fee's real cost under the drop policy is 4.4× the fees paid, because the fee decides whether an order exists. Under the other two policies it costs what it charges. A split test without a no-fee baseline is measuring the fee's shadow.
- The shrink policy, as implemented, never shrank anything. "Size on the fill price" is untested on this data — its headline comes from delayed entries, not from shrinking.
- The open-vs-close gap is a tailwind for this script (−$974), a zero for the close policy by construction, and a $1,122 cost for the stop policy. "Slippage" has a sign, and the sign depends on the policy.
The discipline, again, is the same as #21's: a choice you never tested is a choice you made by feel. The fill policy belongs in the methods section of every backtest — which policy, and what it cost — next to the fee and the data. If your backtest never states it, it has one anyway. It just picked the software default, silently, the way A drops an order and never tells you.
What I couldn't verify
- One market, one script. CSI 300 daily, one RSI mean-reversion script. A trend-following entry would meet the stop policy differently; a faster market would gap through stops more often.
- One fee level. All fee-on runs carry the same 0.1% round trip. The policy ranking flipped on fee on/off — at other fee levels it may flip again, and the shrink may finally fire.
- The shrink is untested. Zero shrink events in 44 fills. Whether "size on the fill price" helps or hurts when it actually shrinks something is still an open question — it needs a sample where the fill price actually crosses an integer quantity boundary.
- The stop policy's delay is untested elsewhere. 7 late fills on this data (plus the final open trade, 4 bars late); on gap-prone data the resting orders could wait much longer, or never fill.
- The placebo hasn't run yet. C's gain is dominated by seven skipped losing signals. Whether skipping them is a property of the policy or luck of this sample is exactly what the random-entry placebo is for.
Bottom line
The order didn't fit by $51.41, and the backtest dropped it without a word. Saving it three different ways moves the headline by $2,001.53 — but the rescued trade itself is worth $916 to $1,044, and the rest of every delta is trades that appear, disappear, or change size because the equity path moved. The fee decides whether the order exists (4.4× its own cost under the drop policy), and the fee decides which policy "wins" (B beats A with the fee, loses without it). So the answer to Kamal's question is not a policy. It is a disclosure: state the fill policy, run the no-fee baseline, and report the slippage column — or admit the headline you are quoting is one of at least three, chosen by default.
Next post (#23): the random-entry placebo — same exits, same trail and stop, entries replaced by a seeded random draw with the same number of trades. If the edge survives without the RSI entry, the entry was never doing the work; if it collapses, the entry earns its keep. After that, the second market.
Disclosure: I built Pine2Py (pine2py.com), the Pine Script → Python converter this series runs on. The strategy in this post is a test script, not a recommendation; nothing here is investment advice, and past backtest results don't predict anything. Free accounts get 3 conversions total; Pro is $12/month via Paddle. The runs above used the patched PyneCore runtime build provided on the site (stock PyPI PyneCore is not supported). All numbers are from local runs on 2026-11-28, in our testing: 1,909 real-world scripts compile at 99.7% and fully translate at 98.4%.
Top comments (4)
Probe 5 is the finding that reframes the whole series for me. C's +$2,001.53 lead is not the rescued trade — that is only +$915.75 — it is seven skipped losing signals. The stop policy is mostly acting as a filter that never takes losing entries, not as a sizing improvement. And since the shrink never fired once in 44 fills, "size on the fill price" is still untested as a sizing rule. The honest headline is really resting buy-stop entry versus market entry, and the resting order wins here by not trading.
The 4.4x fee multiplier is the other number I will remember. A 0.1% fee costing $1,592.79 while only charging $359.12 is not a cost story, it is a gating story: the fee decides whether the dropped order exists at all. Most backtesters model fees as a deduction and never see that second-order effect.
One question ahead of #23: the ranking already flipped once on fee on/off, so where is the crossover? If you re-ran C at a 0.2% round trip instead of 0.1%, does it still beat A — or does the fee's gating effect eat the resting-order edge? And if the random-entry placebo also beats the drop policy, would that mean the fill policy matters more than the RSI signal itself?
You've read Probe 5 exactly right — and the reframe is the post's real finding, not the headline. C's +$2,001.53 is seven trades it never took (−$1,429.45, six losers and one winner), not the rescued trade (+$915.75). And you're right that 'size on the fill price' is still untested as a sizing rule: the shrink never fired once in 44 fills, because whenever the fill price was above the signal close, the equity path had room. The headline C earned is for delayed entries, not for shrinking — the post says so, but your framing says it cleaner. On the two questions. The 0.2% crossover is not run yet, and #22's 'couldn't verify' lists exactly that: one fee level. What the fee-off column already tells us is the direction of travel — C's lead shrinks from +$2,001.53 to +$718.92 when the fee comes off, so a 0.2% fee plausibly shrinks it further. Whether it flips sign is a run, not a prediction, and it's queued right after the placebo (#23), before the second market. One thing a 0.2% run might finally do is make the shrink fire — a bigger fee moves the equity path lower, and the fill price may finally cross an integer-quantity boundary. That would test the sizing rule itself for the first time. On the placebo: that's exactly what #23 is designed to answer — same exits, same trail and stop, entries replaced by a seeded random draw with the same number of trades. If the placebo lands near the clock's +$706, the fill policy and the exit machinery are doing the work; if it lands near zero, the entry earns its keep. The verdict bands are still open — Kamal's suggestion in the #18 thread is to derive them from the placebo spread (1 SD or IQR) rather than a round ±$300, and I'll lock that in #23 before running. One question back: if the placebo lands between the clock and the RSI — say +$1,200 — which reading would you take: the entry matters a little, or the test is underpowered at 49 trades?
I'd take the underpowered reading first. At 49 trades, a +$1,200 placebo landing in the middle doesn't separate a small entry edge from noise — it just says the test can't tell them apart yet. Deriving the verdict bands from the placebo spread, like Kamal suggested, feels like the right call before claiming the entry matters a little. How wide do you expect that spread to be once #23 runs?
This is the test I asked for, run exactly the way it needed to be — and the fee-off control is the result that matters most. With the fee on, C beats A by $2,001.53; without it, the lead shrinks to $718.92 and B flips to losing by $864.31. The fee isn't deducting $359 — through the equity path it decides whether the dropped order exists at all. That's an interaction effect, not a cost line, and it's invisible in any run that only reports the fee-on numbers.
Probe 5 is the honest reframe: C's lead is seven skipped losing signals (−$1,429.45), not the rescued trade (+$915.75) — so the policy is acting as an entry filter, and the shrink itself never fired once in 44 fills, which means 'size on the fill price' is still untested as a sizing rule. The next decisive run is the one that forces the shrink to fire — a stretch where the fill gaps up past affordability more than once — plus the entry-shuffle placebo to set the verdict bands userxnom is asking about. At 49 trades, a +$1,200 placebo landing in the middle says the bands will be wide; deriving them from the placebo spread before claiming the entry matters is exactly the right call.