kernc/backtesting.py

How to handle multiple time frame Close prices?

Ish2K opened this issue · 1 comments

Ish2K commented

I have a simple strategy that has entry conditions based on 60mins timeframe and exit conditions based on 15mins timeframe. I have few issues here:

  1. I can't pass two dataframes, so I just passed one dataframe by merging 15mins and 60mins dataframes by adding "_entry" suffix to OHLC columns of 60mins dataframe. So dataframe has columns- Open, High, Low, Close, Open_entry, High_entry, Low_entry, Close_entry.

Here, problem arises when I am trying to enter the position it will take close prices of 15mins which is not accurate. How do I tackle this issue?

  1. If I reverse the process and by having OHLC with suffix for 15mins data and not 60mins data then the similar problem will happen when I will try to exit the trade. It will take 60mins' close price instead of 15mins close price.

Is there a way to accommodate two or more OHLC dataframes? Engine will only consider values of "Close" column when using "buy()", "sell()" or "close()" methods.

Am I missing something here?

See: #502 (comment)
Resample the df to 15min, and in your strategy, use:

        if self.index[-1].minute == 0:
            # Actions to take on round o'clock only
            ...