Negative Commission in Pine Script: What It Means and How to Fix It
3 min read · Updated
If your TradingView Strategy Tester shows a negative commission, or a backtest that looks far better than it should, the commission setting is the first place to look. This page covers what a negative commission does in Pine Script, why it shows up by accident, and how to set costs that match your broker.
Where commission is set in Pine Script
A strategy's trading costs come from two arguments in the strategy() call:
- commission_type: how the cost is measured.
strategy.commission.percentis a percent of the order value,strategy.commission.cash_per_contractis a fixed amount per contract andstrategy.commission.cash_per_orderis a fixed amount per order. - commission_value: the number used with that type. It defaults to 0, so a strategy with no commission set trades for free.
The same two settings appear in the strategy's Settings > Properties tab. A value typed there replaces the one in the code for your chart, which is why two people can run the same script and see different results.
What a negative commission does
A negative commission_value is applied as a credit. Every fill adds money to the account where a cost would normally take it away. Some exchanges pay a rebate to orders that add liquidity, so a small negative value can describe a real rebate plan. For a retail trader paying a broker, a negative number almost always comes from a typo or a copied script, and it makes every trade look better than it would have been.
The effect grows with the number of trades. A strategy that trades 400 times a year with a credit of $2 per contract per fill gains $1600 per contract from the setting alone, before a single price move is counted.
How to spot it
- In the Strategy Tester's List of Trades, net profit on small winning trades is larger than the price move times the contract value.
- Scratch trades (entry and exit at the same price) show a profit.
- The Performance Summary shows commission paid as a negative number.
- Results get noticeably better when you raise the trade frequency, with no change to the entry logic.
How to set it correctly
- Find your broker's real all-in cost per contract per side: commission, exchange fee, clearing and regulatory fees together.
- For futures, use
commission_type=strategy.commission.cash_per_contractwith that per-side amount. The Strategy Tester charges it on the entry and again on the exit, so a $2.50 per-side cost becomes $5 a round turn. - For stocks and ETFs priced per share, use
cash_per_orderfor a flat ticket fee, orpercentif your broker charges a percentage. - Add slippage with the
slippageargument, measured in ticks. One tick per side is a fair starting point for liquid index futures such as ES and NQ. - Check the Properties tab after loading the script, so a leftover value there does not replace your code.
Example for an ES strategy with a $2.50 per-side cost and one tick of slippage:
strategy("ES levels test", overlay=true,
commission_type=strategy.commission.cash_per_contract,
commission_value=2.5, slippage=1)
Why this matters before trading a strategy live
Costs decide whether many intraday strategies make money. One tick on ES is 0.25 points, worth $12.50, so a strategy that averages a few ticks per trade can turn from profitable to losing once real commission and slippage are in. If a backtest only works with zero or negative costs, it will not hold up live. The Pine Script FAQ on backtests and alerts covers the other reasons a backtest and live results drift apart, and how to spot overfit trading systems covers the rest of the checklist.
Testing a strategy against daily levels
Little Bird Trading publishes the next session's support, resistance and pivot levels for 20 markets, 23 symbols in all, including ES, NQ, SPY and QQQ. Through MyLinedChart the levels load onto your chart or download as data, so you can test entries at those prices with realistic costs set. The sample day trade plan shows what one day's plan looks like.
FAQ
Can commission_value be negative in Pine Script?
Yes. The Strategy Tester treats a negative value as a credit on every fill. Use it only to model a real rebate you receive.
Is TradingView commission charged per side or per round turn?
Per fill. The amount is charged on the entry and again on the exit, so enter your per-side cost.
Why does my strategy show different results on someone else's chart?
The Properties tab settings, including commission and slippage, can differ from the values in the code. Compare those first.
Is this financial advice?
No. This page is education about how backtests are configured. You make and own your trades.
Educational content only. Not investment advice.