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/

    The call ordering for `next()` vs `notify_order()`

    General Code/Help
    3
    5
    51
    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.
    • K
      kegan last edited by

      Why is next() called first, then notify_order() for the same day?

      Here is an example:

      End of DAY1:
      (1a) next() is called.
      (1b) Then notify_order() is called for orders from DAY0.

      End of DAY2:
      (2a) next() is called.
      (2b) Then notify_order() is called for orders from DAY1.

      The use case I am having problem with, is that I want to sell half of my position at the end of DAY1.

      But I cannot know what is the half of my position because when next() is called, notify_order() has not been called yet. Due to the notify_order() may have successfully sold some positions from previous days.

      Shouldn't notify_order() be called first? Similar to the real world, when we make plans at the end of the day (with next()), we should already know what are all the successful/failed execution for that day (with notify_order()).

      Thank you.

      1 Reply Last reply Reply Quote 0
      • K
        kegan last edited by

        I think I made a mistake. After double checking my code. It seems the ordering is correct.

        It is:

        End of DAY1:
        (1a) notify_order() is called for orders from DAY0.
        (1b) next() is called.

        End of DAY2:
        (2a) notify_order() is called for orders from DAY1.
        (2b) next() is called.

        Appreciate if anyone can comment on this.

        Thank you.

        1 Reply Last reply Reply Quote 0
        • R
          rajanprabu last edited by

          Its very difficult to comment without your code. Could you please post the code. In general next () is where BT sends signal to broker instance. If you want to know number of share use self.position.size to access it..

          Docs - Position

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

            @kegan said in The call ordering for `next()` vs `notify_order()`:

            Appreciate if anyone can comment on this.

            if you prefer to trust strangers from the internet, but not to bt documentation or your own results, than - sequence of next() and notify_order() calls is correct and corresponds to reality.

            K 1 Reply Last reply Reply Quote 1
            • K
              kegan @ab_trader last edited by

              @ab_trader @rajanprabu I have solved my issue. I was my mistake to begin with. I didn't check my code properly.

              Thank you for taking the time to reply :-)

              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(); }); }