Multiple timeframes / what is "current" data for larger timeframes?
-
Hi,
I intend to use multiple timeframes as indicated in another post, and I would like to know what is backtrader behavior when calling "current" data of larger timeframes?
Basically, let say I have 2 timeframes: 1H (1 hour) & 4H (4 hours).
- "next()" is called to process timestamp 2019/05/06 02:00:00
- at this time, the "current" bar of the larger timestamp is not finished (started at at 2019/05/06 00:00:00 & will close at 2019/05/06 04:00:00)
If I call data for current 4H bar, what will backtrader give me?
- OHLCV of the last closed bar (timestamp 2019/05/05 20:00:00)
- O of the current non-finished bar (timestamp 2019/05/06 00:00:00) & NaN for the HLCV data?
- O of the current non-finished bar (timestamp 2019/05/06 00:00:00) & current values for HLCV derived from the 2 1H closed bars as current projection:
- H from highest of the 2 1H closed bars
- L from lowest of the 2 1H closed bars
- C from close of 2nd 1H closed bar
- V from sum of the 2 1H bar Vs
?
Is there a way to chose between these different behaviors? (I would like to use basically the 3rd option)
I thank you in advance for your help.
Have a good afternoon.
Best regards,
Pierre -
You may want to study documentation related to data feeds -
Docs - Multiple timeframe
Docs - Data resampling
Docs - Data - replayPart of the questions (maybe even all of them) will be answered.
-
@pierrot said in Multiple timeframes / what is "current" data for larger timeframes?:
at this time, the "current" bar of the larger timestamp is not finished (started at at 2019/05/06 00:00:00 & will close at 2019/05/06 04:00:00)
There isn't such a thing as "not finished". You have the bar and it has a timestamp. You may know when the bar starts and ends, the system doesn't. The system can only see the incoming timestamp, which by convention is the latest timestamp of the entire period. The system cannot know if that bar has been constructed from 1 million ticks in 4 hours or it has been generated with 4 ticks during the last nanosecond of the 4 hour period. You may want to assume something, the system assumes nothing.
A larger timeframe will only be delivered to you when the timestamp is smaller or equal than the timestamp of the next smaller timeframe (now you can recurse downwards until you find the smallest timeframe)
Any timestamp larger than that cannot be delivered, because it hasn't been reached.
As suggested by @ab_trader in another post, you probably need to write a
next
method and use someprint
statements and read about resampling and replaying as also suggested. -
Hi,
Thanks for your help.
Yes I did started playing with someprint
statements. Things start to be clearer.
Thanks for your help!
Bests,
Pierre