Expected behavior
Order should executed when price reaches 160 some day else.
Code sample
from backtesting import Backtest, Strategy
from backtesting.test import GOOG
import pandas as pd
class MyStrategy(Strategy):
def init(self):
pass
def next(self):
if not self.position:
if self.data.datetime == pd.Timestamp('2004/10/21'):
self.buy(stop=160)
GOOG['datetime'] = GOOG.index
bt = Backtest(GOOG, MyStrategy,
cash=100000, commission=0.003,
exclusive_orders=True,
trade_on_close=True,
finalize_trades=True
)
output = bt.run()
print(output['_trades'])
bt.plot()
Actual behavior
Order executed with price 160 next day which wont happen in practice.
print(output['_trades']) prints
Size EntryBar ExitBar EntryPrice ExitPrice SL TP PnL ReturnPct EntryTime ExitTime Duration Tag
0 623 45 2146 160.0 801.2 None None 399467.6 4.0075 2004-10-22 2013-02-28 3051 days None
Additional info, steps to reproduce, full crash traceback, screenshots
No response
Software versions
backtesting.__version__: '0.6.5'
pandas.__version__: '2.2.3'
numpy.__version__: '2.2.3'
bokeh.__version__: '3.7.0'
- OS:
Expected behavior
Order should executed when price reaches 160 some day else.
Code sample
Actual behavior
Order executed with price 160 next day which wont happen in practice.
print(output['_trades']) prints
Size EntryBar ExitBar EntryPrice ExitPrice SL TP PnL ReturnPct EntryTime ExitTime Duration Tag
0 623 45 2146 160.0 801.2 None None 399467.6 4.0075 2004-10-22 2013-02-28 3051 days None
Additional info, steps to reproduce, full crash traceback, screenshots
No response
Software versions
backtesting.__version__: '0.6.5'pandas.__version__: '2.2.3'numpy.__version__: '2.2.3'bokeh.__version__: '3.7.0'