I have encountered a few issues when using backtesting, which can affect the backtests in a huge way. I am not able to recall the few issues i have found, so I am mentioning one below which i just encountered.
I will use this thread to post about any other issue that might cause a huge difference to backtest results.
I have created a simple strategy to enter into a short trade if the prev close of a 15 min candle crosses below the Supertrend (144,3)
I am using this on the GBPINR March Future script. As per the charts on kite, there is no sell signal from the supertrend on 27th Feb, 2019.
But, the transactions list shown in the backtest points out that there was an entry taken on the same date.
I have provided the screenshots below,
There is nothing particularly wrong with the backtest results. In your entry condition you have specified ‘Previous close crosses below Supertrend’ hence it will compare the close of previous 15 min candle with the current [Candle (0)] value of supertrend.
If we look at the charts, we can easily see that the close of 16:45 candle of 26th feb crossed below supertrend value of 9:00 A.M 27th feb candle.
@Renko_Jhunjunwala Okay, wow. I didn’t see it that way, so thank you.
Good to know that is how it works.
@Streak But ideally, I don’t think there would be much of use to compare a previous Nth candle close with current supertrend value. I really think it should be compared with that corresponding candle’s supertrend value, if it’s possible. Anyways, thank you.
Now, i have noticed the below two issues with this:
The entry signal shown on 5-Feb-2019 is not included in the transactions of the backtest. I am not sure why this could be. It is highlighted as A in the chart
The entry as per the chart on 7-Feb-2019 must have been at 9:15 AM i.e. at point B1 at the price around 82.18.
But, the actual entry is taken on 7-Feb-2019 at 2:45 PM, i.e. at point B2 at a price of 81.77 when actually there was no signal as per the chart.
This could cause a huge difference in P/L in the backtests.
You are using supertrend with period as 144.
Now when you are backtesting from 1st Feb on 15min candle, that means each trading day has 32 candle.
Not when backtesting from 1st Feb, there will be a need of atleast 144 candles to be present before the supertrend can be calculated and few more candles for the supertrend signal to stabilise. Then the conditions can be validated.
That is why first few signals if any, will not get captured or the first trade can be captured incorrectly.
You can easily avoid lower the start date by 1week.
This problem in live deployment will not be encountered, because the system there automatically calculates the values on a abundance of candles, making sure that more than enough candles are present for technical calculations and the signals are precise.
Okay, thank you very much for the detailed explanation.
But, is there any way this can be rectified?
i.e. during backtesting also, can the calculations and signals be made precise by using enough/abundance of candles as necessary (just like when it is deployed)
Because, the backtesting results might vary by a huge margin because of these inaccurate trade calculations.
So, based on this backtesting we might actually think the strategy is good and deploy it. When actually, the strategy might not be that good.
So we are looking into ways for doing this dynamically for backtesting, that’s why by default we have enabled 3months for backtesting in intraday so mostly no one face’s this.
Now as your period is huge, you should try to backtest for as long duration as possible and then just ignore the first trade, the pnl only for the first trade can discounted for and the rest remains the same.
Here is another very important issue that needs to be rectified at the earliest.
This is mainly when testing CNC orders because of the gap ups and gap downs.
Let’s say if i enter long into a trade place a SL exit at 0.2% on a stock, and it opens say 1% gap down,
then the exit price should be the current price at when exit is triggered.
But, currently it just takes 0.2% value of the price as exit value, even though that price has not been hit.
This is a major issue and influences the backtest results in a very wrong way. Below is a few screenshots to help.