Hacking out a Breakout Strategy on Tick Data
I'm obviously new to Backtrader (fantastic framework by the way).
I want to create a breakout strategy using the H & L of current bar (with a 5 pip buffer for example), dynamically. I do not want to use the open of the next bar as that is too late (standard backtrader usage).
My idea is:
- Get tick data and use the method here to load it: https://www.backtrader.com/blog/posts/2016-03-08-escape-from-ohlc-land/escape-from-ohlc-land/
OR just set each tick as O,H,L,C and load as first data stream
Resample to desired BreakOut time-frame as second data stream.
Compare the tick data stream to the resampled data stream and execute the market orders
The problem is keeping both streams in sync so that, after a breakout, the current resampled bar (where the BO occurred) is then used for the next breakout and also using the previous bar of the resampled data stream for SL calculation of created orders.
Maybe its possible using the datetime values of both streams??
Any sample code is much appreciated.
Apologies if this has been covered before, I wasn't able to find exactly what I was looking for during my search.
using the H & L of current bar
just wondering - how do you know the H and L of the current bar before the bar close?
oops my error, I meant to say 'previous bar'
If you issue buy stop order on each bar using Hcur of the bar as the stop price, than it will be executed on the next bar at the Hcur (or Onext if it will be a large gap). I assume this is what you want.
Hmm, I will test that out and see how the results pan out, thank you
You will also need to cancel orders which were not executed after the period of waiting (probably one bar in your case).