0

During backtesting in TradingView, trades can seem more profitable than they appear because the spread is not factored in. This is especially true on lower timeframes with a tighter stop loss.

For example, lets say I am trading a forex pair with a 2 pip spread but my stop loss is only 10 pips. The difference when backtesting and live trading is huge.

I understand there is no tick data when backtesting and so far I've only been advised to use slippage instead. Unfortunately slippage increases the loss per trade despite wanting a fixed 1% risk per trade (equity * risk per trade) and I seem unable to resolve this.

How could you best mimic the bid-ask spread without it affecting the risk per trade when a trade loses?

I dont have much code to provide other than:

risk = 1 // As in 1% of the account balance

positionSize = strategy.equity * (risk/100)

strategy.entry(id="Long", direction=strategy.long, qty=positionSize)

I have tried using commissions and slippage but none of these seem to offer an adequate solution. I have also thought about using an ECN/razor/raw type trading account to avoid larger spreads from standard trading accounts while using an accurate rate of commission_type=strategy.commission.cash_per_contract. Perhaps this would alleviate the discrepancies between live/backtesting?

Any guidance on this tricky subject would be greatly appreciated. Thanks in advance!

PPP
  • 7
  • 2

1 Answers1

1

I can't answer fully as I'm working on something similar.

But this may be part of the answer:

Pine Script V5 how to consider the spread and commission in backtesting?

I've just done some basic testing working with the following in the strategy line:

Comission_type=strategy.comission.percent Comission_value= TBC

Before adding this to the strategy, determine TBC value in % using a fixed value trade backtest e.g. profit / loss = spread in ticks using, default_qty_value = 10 contracts. Back test with no slippage.

Under list of trades in the back tester, the profit column shows you a %, use that value.

Not sure if this is right or not, but may offer an in sight other than slippage.

(Nb, Tradingview, Pineconnector, Lightsail, MT4, Oanda looks like 20 ticks average actual slippage on WTICOUSD hourly - 10 seconds trade time). So you can add that value in aswell.

Sniper Bob
  • 26
  • 1
  • Haha thanks Sniper Bob, you linked a post which I answered myself after struggling for weeks to understand! Thanks for sharing your thoughts, nice to know I am not alone! – PPP Apr 21 '23 at 15:05