Problem : Delayed Market Order Execution with Hour Data Feed
-
Hello everyone,
I am new to backtrader and I encounter the following problem and I cannot search for an solution on the community. May I have your help?
My Data Feed is on Hour basis
I execute the trade and close the position by the following code :
My Order suppose to be market order which is expected to trade at the open of next bar (next hour opening price)
However, it turns out that the order execute on the next day but not next hourMay I ask for your advise for executing the order at the coming hour instead of coming day
Thank you very much
-
For Further information, it seems the datetime of each bar has error
I found that the datetime of each bar is in the following way:
For example, suppose I feed hour data of 2021 - 12 -24
Then those bars' datetime are supposed to be like
2021-12-24 00:00:00
2021-12-24 01:00:00
2021-12-24 02:00:00
...However, each data bar of 2021 - 12 -24 have the datetime like the following:
2021-12-24 23:59:59
2021-12-24 23:59:59
2021-12-24 23:59:59
...I am wondering whether the error lead to my order execution delay. For the datetime error problem, I found some posts talking about it. However, the problem still exist after following their solution
-
I solved the problem. Thank you everyone.
For Future Readers,
The problem I mentioned actually is caused by the datetime error of the bar I mentioned in my second comment.
To solve the datetime error of the bar,
you have to align the timeframe and compression to your source during the data feed
And you have to use PandasDataFeed to Feed the data in this case (In my case, YahooDataCSV cannot feed it properly) -
Please check the following post:
https://community.backtrader.com/topic/5757/5min-data-from-yahoo