any update on when amend would be available in backtrader.
Posts made by skytrading54
order price modification support ?
Looking for a use case to be able to modify low / high side of a bracket order once the main order is filled, brokers like IB support modification of existing order price etc.
Any plans to support order modification on backtrader - ideally price modification on unfilled limit/stop-limit orders.
While for a single order it would be easier to cancel and replace it with new one, how do we achieve it for bracket orders low and high side once main order is filled, ability to modify the original order seems to be the solution, any thoughts in current backtrader framework.
RE: Issue with Stop-Loss on Multiple Stock Datas
@cwse to answer your question -- Will OCO be supported by interactive brokers in the near future if i go down this avenue?
There is something better available in IB called bracket order which combines OCO , Stop Loss Order and Take Profit Order together with main order.
It works like this.
Issue 3 orders in one go,
- The main order (Limit)
- Take Profit (Limit)
- Stop Loss (this could be actual stop loss or trail or trail limit order)
All of these are in one group (grouped by parent orders id) and when we create the orders one by one; the transmit flag (of IBOrder) is false for first 2 and should be true on last one. So all of them gets into IB system at once based on last orders transmit=true when you submit them one by one.
From IB side, Only first main order is sent/live at the exchange (rest 2 are not active), Only when first one is filled next 2 are propagated to exchange. Since these 2 (take profit & stop loss) are OCO; whichever gets filled at exchange first, IB cancels the other one.
- Main Order - Buy @ Limit price 100 - transmit=false
- Take Profit - Sell @ Limit price 110 - transmit=false, m_parentId= main order id.
- Stop Loss - Sell @ Stop Loss price 98 - transmit=true, m_parentId= main order id.
submit all 3, they are entered in IB system, however IB will send only parent order to exchange first. Only when that is executed it will send next 2 as OCO. When one of this is filled (resulting in profit or loss) other is cancelled automatically.
exception in ibbroker.py
I am using following methods to set commission in both cases getting following exception, any pointers what's going wrong...
Product is emini future.
cerebro.broker.setcommission(commission=1.25, margin=2000.0, mult=50.0)
comminfo = CommInfo_FIXED(commission=1.25,stocklike=False) # 1$
where CommInfo_FIXED is following class.
params = (('stocklike', False), ('commtype', bt.CommInfoBase.COMM_FIXED),)
def _getcommission(self, size, price, pseudoexec):
both varieties gives following error when trade is executed.
ERROR Exception in message dispatch. Handler 'commissionReport' for 'commissionReport'
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\ib\opt\dispatcher.py", line 44, in call
File "build\bdist.win32\egg\backtrader\stores\ibstore.py", line 1377, in commissionReport
File "build\bdist.win32\egg\backtrader\brokers\ibbroker.py", line 525, in push_commissionreport
closedvalue = comminfo.getoperationcost(closed, pprice_orig)
AttributeError: 'NoneType' object has no attribute 'getoperationcost'
indicator using a value from the data other than close
I believe most of the built in indicators are using close value from the data for computation, for example SMA indicator is using close values of all the bars to derive sma... (is this correct)
I have following 2 scenarios to build indicators
- if I would like to force this to use say high values of the bar to compute the average, what would be the change.
- if I would like to use volume from the bar to compute volume average over a period, what would be the change.
appreciate any example if available.
RE: Suggestion: caching
my 2 cents..
following approach might work using existing multiprocessing architecture.
- since optimization iterations are mainly based on parameters which are passed on as ranges... we might simply consider to compute first, all the indicators which make use of those range based parameters and save all of those to the file, even this could be done by having multiple processes each dedicated to that specific indicator.
- Once this computation is done, then actual strategy processing should begin using various combinations of those indicators as applicable. It would only need to read the cached data from file in read only mode for that specific indicator, so no worry about locking, this would as well be multiprocessing as is used today, just that indicators have been computed earlier separately.
RE: Memory error in optimization run.
well, my data size is not big... its 1 min ohlc bar for 1 year and resampled to 5 mins compression.
When I ran it with about 50 iteration it works fine. A higher number of iterations (150++) gives this error, which means memory is increasing per iteration.
I see any point of time 10 process spawned by backtrader for this optimization run, is there a way it can release the memory from some of the previous runs as it progresses into next iterations....
Memory error in optimization run.
Hi, I am getting memory error while running optimization and the run does not continue after that.
-E--Strategy::init--loop params-- xception in thread Thread-3: Traceback (most recent call last): File "C:\Python27\lib\threading.py", line 810, in __bootstrap_inner self.run() File "C:\Python27\lib\threading.py", line 763, in run self.__target(*self.__args, **self.__kwargs) File "C:\Python27\lib\multiprocessing\pool.py", line 389, in _handle_results task = get() MemoryError
I am using 4 parameters variations..
cerebro.optstrategy(TestStrategy,smaperiod_fast=xrange(40,150,15), smaperiod_slow=range(150,300,15), p1=range(25,45,8), p2=range(50,300,15))
However the max memory consumed is 1.7 GB, with 32 bit it should go upto 4GB without any issue. Attached is snapshot of the all the processes spawned for optimization run.
Any idea what could be wrong here... I am using backtrader Release 22.214.171.124