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/

    What are Timers for?

    General Discussion
    2
    2
    868
    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.
    • Curtis Miller
      Curtis Miller last edited by

      I saw Timers in the documentation and people asking questions about them, but I have not seen an explanation for why they exist. What's their purpose? What's an example usage case (not in a code sense, but in "I want a Timer so I can do this" sense).

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

        One use case:

        • You can implement a logic in your strategy which continuously checks the time of the day to see if only 5 minutes remain until the end of the session. This is the only moment in the session in which your fund executes the daily operations.

        If this precise minute is missing (nothing was negotiated), your time comparison will fail. You can enhance the logic to not only check for == but also for >=, but you then need a bool to understand if you have already acted.

        • The timer will be called only once and 5 minutes before the session end without a constant logic check in next and with no bool involved, because it will only be called once.

        The strategy contains the datetime information and things can be done manually. In general is a way to express things in a different way which may be more elegant.

        Some people want to do portfolio rotation on the 15th of each month, but that day may be a weekend or a bank holiday. The timer will be called with the next possible day, allowing the rotation to always happen on the 15th or the 1st trading day thereafter (which matches the reality of life)

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