backtesting.py icon indicating copy to clipboard operation
backtesting.py copied to clipboard

Buy at Open, close at Close of the same candlestick

Open tombohub opened this issue 5 years ago • 4 comments

Can you make it so we can buy at Open and close the position at Close the same candlestick?

Thanks

tombohub avatar Feb 11 '21 19:02 tombohub

The recommended approach for trading within candlesticks is to obtain/load OHLC data in a lower time-frame.

kernc avatar Feb 12 '21 00:02 kernc

Thank you, that is viable approach. The only issue with that is that intraday data is not as free and easy to get as daily data so when we want to run across good amount of stocks we would need to pay for data

tombohub avatar Feb 12 '21 05:02 tombohub

while we're at it, is it possible to specify the exact price we want to make it in? In that case, we can specify any OHLC, or combinations. We can set a flag somewhere if we don't want to accidentally cheat with it.

arisliang avatar Jun 16 '21 00:06 arisliang

while we're at it, is it possible to specify the exact price we want to make it in? In that case, we can specify any OHLC, or combinations. We can set a flag somewhere if we don't want to accidentally cheat with it.

Instead of market order use limit order for the required price. If you mean completely different price like the options premium of this stock then it is not possible without serious modifications.

I think it may be possible to do several transactions in one bar by calling self._broker.next() after each order in Strategy.next(). This way the order will be processed and it will accept new order in the same bar. It is not verified, just an idea to experiment with.

AGG2017 avatar Oct 09 '21 23:10 AGG2017