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

how two make an order valid until next bar?



  • Hi, in a daily bar strategy, I want to make an order valid until next bar, not next day, how to do it?
    self.buy(valid=?)

    Another question, how about make it valid until next two bars?

    Thanks in advance.



  • What is the nature of the data you are using?



  • It's about this.

    In Chinese stock market the price of any stock on any particular day may only go up by 10% (that is the upper bound price) or down by 10% based on previous date's close price. So if the price goes up by 10%, in most case, one can no longer buy it(as there will be many buy orders accumulated there).

    Suppose I create a market buy order today, then next trade day, the stock open at upper bound price and keep at that price all day, then my market order should not be executed.

    How to simulate this with backtrader. My idea is to issue a limit order,such as:
    buy(type=limit, price=data.close[0]*1.1-0.01, valid=next bar). I donn't if this is best solution, any idea.



  • Since this is exchange/broker implied conditions, than the best solution would be to write broker which rejects orders based on this rule.



  • @ab_trader thank you for your direction. There is another situation.

    Suppose I create a market buy order today, then next trade day, if the stock's OHLC prices are all at the upper bound price , then my market order should not be executed. But if any of O,L,C price is lower than the upper bound price, then the order could be executed at upper bound price.

    could this logic be implented in the broker?



  • I believe it is possible.


Log in to reply
 

});