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!