Sergei

How to backtest with 3-hour data interval?

Programming


I have a strategy that works well with 3-hour candles. However, I don't see such option in the backtest setting. How can I do that?
 
Hiroki

You can choose 1 hour data, then add a time checking variable as follows:


from AlgoAPI import AlgoAPIUtil, AlgoAPI_Backtest
from datetime import datetime, timedelta

class AlgoEvent:
    def __init__(self):
        self.last_time = datetime(1970,1,1)
        
    def start(self, mEvt):
        self.evt = AlgoAPI_Backtest.AlgoEvtHandler(self, mEvt)
        self.evt.start()
        
    def on_marketdatafeed(self, md, ab):
        if md.timestamp>=self.last_time+timedelta(hours=3):
            self.last_time = md.timestamp

            # your trading logic below...