For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Suggestions on close order

  • currently, close an order will call buy/sell in strategy class. and I found my future broker allow me to hold long position and short position at the same time,
    if I send one buy cmd and one sell cmd, I have two open positions! the only way to close the position is send a close cmd

    so, my suggestion is not to convert the close call within strategy class, XXStore or XXBroker will be better place

  • The idea of the close order is to provide the simplified method to close existing position. If you don't want to close existing position, than the close order should not be used. If you want to hold long and short positions at the same time, than use buy and sell orders to initiate the positions.

  • @ab_trader I do want to close the existing order, but there is no way to do that in this system, no close to override in BrokerBase. I am suggest move close from Strategy to BrokerBase, It makes code much more extensible without lose any convenient

  • Following the existing concept, I think that close order can be implemented at the strategy level only, similar to the target orders, for example. The reason is that it uses position size as an argument and position size relates to strategy. At the broker level it can be several positions open by different strategies in the same data feed. Simple moving of the close order to broker level can easily break the legacy of the bt scripts, since the call of the close order will be closing all positions in all strategies.

    If you desperately needs this, than sub-class the bbroker and write your own implementation. But honestly, the strategy can be written without using of the close order at all, therefore I think that this mod will bring more hassle than worth.

  • what @ab_trader said is what you should follow to prevent later issues. You could overwrite the close method of the strategy and check for your broker. If it is your broker, use a different way to close the order, if not, just call super(self).close(order)

Log in to reply