FRENESDE

The next() method

next() is called once per bar, in chronological order. Inside it, index [0] means the current bar, [-1] the previous one, [-2] the one before.
As long as indicators lack history, Backtrader calls prenext() instead: this is the minimum period. With an SMA 50, the first real decision comes on the 50th bar.
An order sent in next() is executed by default at the open of the next bar. Between the close and the open, the price can jump: that is a gap.
Reading a future bar would mean knowing the answer before the question: that is look-ahead bias, which produces beautiful and false backtests.

Examples

Key terms

next()
Method called at each new bar
Index [0]
The current bar; [-1] is the previous bar
Minimum period
Number of bars needed before the first decision
Look-ahead
Mistakenly using information from the future
Take the mission on Doji Academy

← Back to the index