Problems backtesting Support Strategy

Course Name: Price Action Trading Strategies Using Python, Section No: 20, Unit No: 6, Unit type: Notebook



Hello,



I would like to point and issue with the backtesting loop in this notebook. Note that we start the loop checking if  'entry_flag' or 'exit_flag' are True:





While in previous notebooks, like Section 7, Lesson 3, for the Head and Shoulders Strategy we're checking first the parameter of the signal:





For the Support Strategy it's a problem comparing first 'entry_flag' and 'exit_flag' because these parameters rely on the signal column of the dataframe. As you know, if we have a signal different from 0, we enter in a trade and set this 'entry_flag' as True.



So, if we first compare the 'entry_flag' and not the signal value, we're recording in the 'round_trips_details' dataframe the entry one period later than we should, as the loop will change to the next day for the 'entry_flag' get changed and record all the data for the entry. That's a mess because the backtest result changes completely.



If we first compare the signal column like we did in Section 7, Lesson 3, we first check if at the current period there's a signal, if there's a signal, we record correctly our entry with current period's price.



Please check the difference in backtest when we compared first the 'entry_flag':





With the output when we first compare the signal value:





This is obviously an important detail. Please confirm with me I'm correct and update this notebook and the code in 'price_action_util_quantra.py' script.



Thanks in advance!

Hi Daniel,



We are looking into your query and will get back to you.



Thanks.

Sure, waiting for you answer.

Hi Daniel,



The strategy mentioned in section 20 unit 6 (Backtesting Support Level), is used on minute data, while the head and shoulders (Section 7) is on daily data.



For minute frequency, we had to do a change in the backtester function to accommodate the shorter time frame. As mentioned in the backtesting support level notebook, we will follow the same procedure as in previous notebooks with a minor variation. As this strategy runs on 15-minute price data, we will take a long position at the Close price of the next 15-minute candle if the signal is generated as 1 for the current candle. This is not that significant for the daily data as we can generate the signal a few minutes before the day's Close and easily take the trade at the Close price of that same day. To accommodate this in our code we will check the entry_flag condition first and then the entry conditions so as to append the entry for the next candle after the close is below the support level. Apart from this minor variation, the code for backtesting is the same as that used in the previous notebooks.



This change does not affect the other notebooks and hence the function in the "price_action_util_quantra.py" file does not have to be changed because this file contains the code for backtester which is at daily frequency.



Hope this helps.

 

You're right, this was explained in the notebook and I didn't read it. This was intentionally for the purpose of the strategy, thanks for the clarification!

Hello again Rekhit,



This design is also implemeted in Section 27, Lesson 8, type: Notebook for the intraday_backtester which is causing one-period lag at closing trade.



Is this intentional? Because for this strategy nothing is said about this design in the notebook… Again, this is causing different backtesting results.



 

Hello Daniel,



Yes, this is intentional. As we are working intra-day time period, we used the same logic as it was applied earlier.



I hope this helps.

 

Thanks!