Is next() datas[0].Close in the future?
-
Hi I'm new and this is my first post.
When next is executed I'm not sure where I'm in the current time.
So the question:Is next() dataclose[0] in the future?
What I already tried:
def next(self): self.log(self.datetime.datetime(ago=0)) ...
2021-01-30, 2021-01-30 00:00:00
2021-01-30, Close, 34269.52Dataframe Entry:
Date 2021-01-30 34269.523438 Name: Close, dtype: float64
So it looks lik I'm in 2021-01-30 00:00:00 (morning) and can already access open and close. Close will only be calculatet when market has closed. Does that mean my strategies should not access dataclose[0] because it would be cheating and unrealistic?
-
@kjiessar You are always receiving data in "bars". A bar is a summary of all the trades over a certain time interval. Each interval will have its own Open, High, Low and Close. You receive the bar in
next()
just after the interval is complete so the Close is never in the future, it always just happened. The Open will be further in the past by the interval of time of that bar.Typically if you are using daily data, then
next()
is being called at the end of the trading day. If you place an order, the first opportunity for it to get filled is at the next days's Open price. -
Thank you that helped a lot.
So in general it looks like this:
There is no way to get in between an open and a close slice. If you want to do that you would need to use a finer granularity, like minutes instead of days. But then there woul again a be open and close.
-
@kjiessar said in Is next() datas[0].Close in the future?:
There is no way to get in between an open and a close slice. If you want to do that you would need to use a finer granularity, like minutes instead of days. But then there woul again a be open and close.
Actually, while I understand what you are saying, this is not entirely correct.
There is no way to get between bars because the ending time of the first bar is exactly the starting time of the next bar, market hours open and close aside for the moment.
The concept of the close bar is a construct we make, and allows us to quantify a period of time, and then another. Once we get to the end of the bar, we can conceptually stop, reassess, make decisions and move to the next bar. In reality, there is no time stop of course.
In backtrader, the bars are concrete blocks of time, and all the activity occurs between them. There are other methods other than time of course, like ticks, volume, or dollar values, but these are not part of how Backtrader works.
-
Thank you for your explanation
I was reading and found a reference to this post about BarReplayer_Openhttps://community.backtrader.com/topic/217/order_target_percent-calculation-problems
Corresponding Blogpost
https://www.backtrader.com/docu/filters-reference/So is it possible with the BarReplayer_Open to create orders in between open and close?
-
-
@kjiessar said in Is next() datas[0].Close in the future?:
So is it possible with the BarReplayer_Open to create orders in between open and close?
Orders are created at the moment the open price is available and executed during the bar. You can also take a look on
cheat-on-open
feature, which allows order creation at open price. This gives less hassle compare to the bar replayer mentioned.