Why cancel? you can totally profit from both of those brackets if something fluctuates up and down intraday =)
Posts made by xnox
RE: Simultaneous bracket order - Cancel one when another has been submitted & accepted
BracketOrder: stopamount and limitamount instead of stop|limitprice in the bracket order
I'm using CFD/FX brokers and most of them accept what is known as the bracket order in backtrader. However, they often offer to specify stopamount and limitamount, rather than stopprice and limitprice. E.g. instead of specifying a buy bracket of 2400, stopprice 2350, limitprice 2500. One can specify buy bracket 2400, -50, +100. The advantage of using amounts instead of the price, is that when the buy order is executed at 2400.1 (due to slippage / spread) the oco that are opened are adjusted accordingly and become 2350.1 and 2500.1 respectively.
Would it be possible to implement stopamount / limitamount for the bracket orders, and make sure that the bracket sides are adjusted +/- relative to the (first or average weighted) executed price of the initial order?
RE: How to prevent multiple submission of limit / bracket orders?
I do keep a simple set of my order levels, add working orders to the set, and remove them when they are fully closed or expire. That way in next I can check what I need to reopen.
I have tried to write a custom fill order function which would reject duplicate orders, but it felt a lot more error prone than simply tracking state and not submitting duplicates.
RE: Upgrading from 220.127.116.11 -> 18.104.22.168 breaks things
TypeError: adddata() got an unexpected keyword argument 'compression'
Adding compression to the
resampledatacall, still results in the inability to plot.
Upgrading from 22.214.171.124 -> 126.96.36.199 breaks things
I'm trying to upgrade from backtrader 188.8.131.52 to a more recent release, and things break for me.
First of all, I operate mostly on minute data and previously all of my charts would work on minute bars.
Now, the data appears to be loading in a daily timeframe, even though it is clearly minute data.... How do I fix this?
Then when I try to plot things, I get the following traceback:
cerebro.plot() File "/home/xnox/ig/backtrader/backtrader/cerebro.py", line 739, in plot start=start, end=end) File "/home/xnox/ig/backtrader/backtrader/plot/plot.py", line 218, in plot self.plotdata(data, self.dplotsover[data]) File "/home/xnox/ig/backtrader/backtrader/plot/plot.py", line 656, in plotdata color=color, label=datalabel) File "/home/xnox/ig/backtrader/backtrader/plot/finance.py", line 594, in plot_lineonclose **kwargs) File "/home/xnox/ig/backtrader/backtrader/plot/finance.py", line 534, in __init__ ax.add_line(self.loc) File "/usr/lib/python3/dist-packages/matplotlib/axes/_base.py", line 1708, in add_line self._update_line_limits(line) File "/usr/lib/python3/dist-packages/matplotlib/axes/_base.py", line 1730, in _update_line_limits path = line.get_path() File "/usr/lib/python3/dist-packages/matplotlib/lines.py", line 925, in get_path self.recache() File "/usr/lib/python3/dist-packages/matplotlib/lines.py", line 632, in recache raise RuntimeError('xdata and ydata must be the same length') RuntimeError: xdata and ydata must be the same length
Any idea how to work out which line / what is bombing out here?
How to add Indicator over resampled data? E.g. 10-day sma for minute data
I'm trying to use btrun, and code a generic strategy which I can control with btrun. My data is typically minute bars, however, in the strategy, I would like to use a 10-day indicator. How can I do this in the strategy? Or btrun options?
If I script against celebro directly, I would add data0 as usual, then call resampledata to generate resampled data1, and then in the strategy add sma indicator with period=10 against data1.
Somehow, I wish any indicator could be added with data resampling, e.g.
self.sma = bt.indicators.SimpleMovingAverage(self.data, resample=bt.TimeFrame.Days, period=self.params.sma)
I've now tweaked btrun locally to always add data first, and then add resampled one too. Such that I get the minute and daily data feeds for indicators to work on, but this seems extra work.
I guess I could do sma over 1440... but that assumes 24h trading with no missing minutes and is not the same as resampling to days first, and then doing 10-day sma.
How to add takeprofit / stoploss?
In my broker when sending an order, I can set stop-loss and take-profit levels on it. Such that e.g. I can send a limit buy order, with stoploss and takeprofit levels and forget about it. It will either remain open, or close with profit/loss. Simulating this with backtrader appears to result in errors.
In order notification, if buy order is executed I execute two sell orders: one limit order with stop loss, and one stop order with take profit. This eventually fails and results in stategy executing both of the sell orders. Ideally if one of these sell orders is executed, i would like the other one to be instantly killed.
How should I code takeprofit/stoploss on my positions?
Should I extend the bbroker itself to support stoploss/takeprofit?