kernc / backtesting.py

:mag_right: :chart_with_upwards_trend: :snake: :moneybag: Backtest trading strategies in Python.
https://kernc.github.io/backtesting.py/
GNU Affero General Public License v3.0
5.54k stars 1.07k forks source link

Define a Specific Purchase Price Upon self.buy() ? #341

Closed windowshopr closed 3 years ago

windowshopr commented 3 years ago

Not really an issue, just wondering, is it possible that, when all conditions are met to initiate a buy order, to tell the backtester at what price I would like to log as that trade's purchase price? The way it works by default is, it uses the latest Close price as the purchase price if trade_on_close=True, however part of my strategies involve timing entries, like for example when the price crosses above a moving average. So technically, I'd like to "purchase" the stock at the moving average price (using this example), and not wait until the bar closes to purchase.

Is this where using either a limit price or stop price in the self.buy() would work? Or is this even possible? :P Thanks!

kernc commented 3 years ago

You must be looking for Strategy.buy(limit=), which simulates a limit order.

windowshopr commented 3 years ago

That is! Thanks a lot!