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

Why won't order.Accept? Is it because I need volume?



  • This is my first week working with Backtrader, and I must say, it's been a ton of fun. The documentation is incredible and there seems to be a strong community supporting it. On to my problem.

    My script is working perfectly when I'm using bt.feeds.YahooFinanceData() as my data source. The problem stems using my own data source which contains the following columns: datetime, open, high, low, and close. I currently DON'T have volume. My data is in 30 minute intervals and I'm currently reading it in using the following code:

    data = bt.feeds.GenericCSVData(
        dataname=datapath,
        # Do not pass values before this date
        fromdate=datetime.datetime(2019, 12, 5, 16, 30),
        # Do not pass values after this date
        todate=  data0.index.max().to_pydatetime(),
        datetime=0,
        open=1,
        high=2,
        low=3,
        close=4,
        volume=-1,
        timeframe=bt.TimeFrame.Minutes,
        compression=30)
    

    So what's my problem? Once some long conditions are met, my script should submit a buy limit order:

    if self.datalow[0] > self.ema_l[0]:
          # previous close less than the previous close
          # BUY, BUY, BUY!!! (with all possible default parameters)
             self.log('BUY CREATE, %.2f' % self.dataopen[0])
             self.order = self.buy(exectype = bt.Order.Limit,
             price = self.dataclose[0], 
             valid = datetime.now() + timedelta(hours = 2))   
    

    I separated my order.status for both order.Submitted and order.Accepted within my notify_order function:

        def notify_order(self, order):
            # https://www.backtrader.com/docu/order-creation-execution/order-creation-execution/
            # Check the order status. 
            # If it is submitted/accepted, leave the fucntion 
            if order.status in [order.Submitted]:
                self.log(f"Order submitted but not complete. Price at {self.order.price}")
                return
            
            if order.status in [order.Accepted]:
                self.log(f"Order accepted but not complete. Price at {order.price}")
                return
    

    As can be seen in the log. The order is submitted but never accepted. Why would this happen? Could it be because I don't have a volume column and Backtrader needs to know that there is some amount of volume there to be able to make the trade?

    2020-10-07T01:30:00, BUY CREATE, 1583.70
    2020-10-07T02:00:00, Order submitted but not complete. Price at 1583.7
    2020-10-07T02:00:00, Close, 1584.10
    2020-10-07T02:00:00, BUY CREATE, 1584.10
    2020-10-07T02:30:00, Order submitted but not complete. Price at 1584.1
    2020-10-07T02:30:00, Close, 1585.80
    2020-10-07T02:30:00, BUY CREATE, 1585.80
    2020-10-07T03:00:00, Order submitted but not complete. Price at 1585.8
    2020-10-07T03:00:00, Close, 1589.00
    

    Thanks for the help!



  • Do you have the same issue if you add a dummy volume column (let's say 100 each line) to your own data source ?



  • Excerpt from docs:

    Order Execution Logic
    The broker uses 2 main guidelines (assumptions?) for order execution.

    • The current data has already happened and cannot be used to execute an order.
    • Volume does not play a role


  • @EMR, Already tried this, and it, unfortunately, produced the same results.



  • @ab_trader As can be seen in the last output block, there is a buy order at 1:30 at $ 1583.70. The order is submitted but not complete. It proceeds to close at a higher price. Why would it be incapable of buying at the closed price?

    PS
    I do have coc (cheat on close) set to True.



  • Is there a way to delete this topic? I was able to resolve the problem.



  • @Adham-Suliman said in Why won't order.Accept? Is it because I need volume?:

    Is there a way to delete this topic? I was able to resolve the problem.

    No, this is not an editable forum.


Log in to reply
 

});