Can I trade one timeframe, but run update_position() in another timeframe?

Yes but it's a little tricky. You need to set your routes to trade the lower timeframe so that the update_position() (and all other main methods of your strategy) is based on that timeframe. Then, you'd have to check if it's time to execute the strategy, only if the time has come for that bigger timeframe to close.

There are multiple ways to check if the bigger timeframe has closed, but here's an example for trading with (any) lower timeframe and the 4h timeframe as the targeted bigger timeframe:

Inside any method that you'd like to check for this condition (such as should_long(), write below code:

current_time = self.current_candle[0] + 60_000
one_min_count = jh.timeframe_to_one_minutes('4h')
timeframe_duration = one_min_count * 60_000
if current_time % timeframe_duration == 0:
    # then the a candle has been closed

As an alternative, you could use get_candles to get the bigger timeframes candles.

Last updated: 2 years ago