r/pinescript • • 1d ago

strategy() defaults that quietly shape a backtest: zero commission, zero slippage, touch-fills on limits, 1:1 margin

A lot of "why does my backtest look so much better than live" questions come down to properties nobody set. Here is what the current v6 docs say the broker emulator does when you leave the strategy() declaration alone, and what each setting actually changes.

Commission: none by default. If you don't pass commission_type and commission_value, every fill is free. You can model a flat fee per order, a fee per contract/share/lot/unit, or a percentage of the transaction value. Cost scales with trade count, so high-turnover strategies are the ones most distorted by leaving this at zero.

Slippage: 0 ticks by default. slippage is a fixed number of ticks applied in the unfavorable direction (higher fills for longs, lower for shorts). Because it is constant, the docs point out it can push simulated fills outside the candle's range, so piling on slippage makes results unrealistically worse rather than more honest. Pick a value you can justify for the instrument's tick size and liquidity.

Limit orders: touch = fill by default. backtest_fill_limits_assumption defaults to 0, meaning a limit order fills as soon as price reaches its level. Setting it to N requires price to move N ticks beyond the level before the order fills. The "Limit order execution" input in Settings/Properties can override it. Strategies built on limit entries near local extremes are the most sensitive to this, since a level that was only touched is exactly where a real queue may not have filled you.

Margin: 100% by default (1:1). margin_long and margin_short default to 100; lower values show up as the "Long/Short leverage" inputs. If available funds drop below the required margin, the emulator generates a margin call and liquidates four times the quantity needed to cover the loss, to avoid repeated margin calls on the following bars. strategy.margin_liquidation_price returns the price at which that would trigger. The docs also flag margin below about 0.2% (leverage above 500:1) as typically unrealistic, and 0% as equivalent to infinite leverage.

Pyramiding: 1 by default. Repeated strategy.entry() calls in the same direction won't add to an open position until you raise pyramiding. One documented exception: if several strategy.entry() calls create limit, stop or stop-limit orders on the same tick, the emulator fills each one that price triggers, which can exceed the limit.

Order size: qty beats the defaults. A non-na qty in strategy.entry() or strategy.order() ignores default_qty_type / default_qty_value. Pass na when you want the default size to apply.

The declaration is only a default. All of the above can be overridden in Settings/Properties. When comparing your numbers with a published strategy, check the publication's "Properties" tab first: it lists the initial capital, order size, leverage, pyramiding, commission and slippage the author used.

A simple habit that helps: set commission, slippage and the limit-fill assumption explicitly in the declaration, even with rough first guesses, so the zero-cost case is a choice rather than an accident.

For those running limit-order strategies: do you use backtest_fill_limits_assumption = 1, or something larger tied to the instrument's typical spread?

Reference: TradingView Pine Script v6 docs, Concepts > Strategies (sections on commission, slippage and unfilled limits, margin and leverage, pyramiding, position sizing).

2 Upvotes

1 comment sorted by

1

u/Kamalmosadegh 1d ago

I use 1 as the floor, not the answer — and I tie anything larger to the spread, not to a round number. For a limit strategy the touch-fill default is the one that flatters the backtest most, because in live trading a touch rarely gets you filled at that exact price when you are competing at the same level.

A quick check that makes the difference visible: run the same strategy twice, once with backtest_fill_limits_assumption = 0 and once with = 1, keeping commission and slippage fixed. If net profit drops by more than about 20-30% or the trade count falls sharply on the = 1 run, the edge was mostly coming from fills you would not get live. On the instruments I test, 1 is usually enough to kill the fantasy fills; going to 2 or 3 only makes sense if the typical spread is 2-3 ticks wide, so the assumption matches how far price has to move through your level before you are realistically filled.

One more check worth doing in the same run: add commission_value = 0.1 with commission_type = strategy.commission.percent and slippage = 2, then compare. If a strategy only survives at zero costs, it was not an edge, it was a defaults artifact.