Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/

    Force bracket to close at the end of the day

    General Code/Help
    3
    5
    733
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • E
      ElliotP last edited by

      Evening,

      I have read the docs, searched and forums and google searched quite a lot. I would like to set up my strategy to be forced to sell at the end of each day.

      My data is hourly. I have tried to count bars but this is a little limiting. I have read about different order execution types (MOC), but I'm not sure how to implement that in a bracket order or how to break it apart and do it manually.

      I have read about the idea of pre-loading data, but I very much would like to be able to convert this to live data if I needed to quite easily, so ideally I would be able setup some way. Ideas?

      B 1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators @ElliotP last edited by

        @elliotp said in Force bracket to close at the end of the day:

        but I'm not sure how to implement that in a bracket order

        I don't think that's a realistic scenario with a broker, because a Market-On-Close order is a Market oder per se and has no price tag associated. And a bracket by definition has price tags for the orders around the main order, hence the name bracket.

        Your best bet:

        • Issue an order and await execution
        • With the execution in the hand create 3 orders: upper side, lower side, MoC as OCO orders - See Docs - OCO Orders
        • If any of them execute the others will be cancelled.

        In any case, it may still not be supported by your broker.

        1 Reply Last reply Reply Quote 0
        • E
          ElliotP last edited by

          @backtrader said in Force bracket to close at the end of the day:

          Market-On-Close

          Furthering on this idea of buying/selling at the close of a day; I can't think about how to do it.

          One idea is to set a marketorder for daily bars, but that won't really hold up during live trading.

          Another idea would be to buy a small stake at open, count the bars and then buy more when you know it is at the end of the day with Market Order.

          I'm not sure how to implement a Market-On-Close or a Market Order for the last bar of the day. Any thoughts?

          1 Reply Last reply Reply Quote 0
          • A
            ab_trader last edited by

            Just an idea - looks like you are trading intraday, check the timestamp of the each bar, then at 1 bar before the end of a session cancel all active limit and stop orders and issue the market order to close the position - just self.close() It should be executed at the open of last bar.

            1 Reply Last reply Reply Quote 1
            • E
              ElliotP last edited by

              That's a fantastic idea, I can't believe I didn't think about that. Thank you

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Copyright © 2016, 2017, 2018 NodeBB Forums | Contributors
              $(document).ready(function () { app.coldLoad(); }); }