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/

    After stop-loss is executed stop algorithm for x amount of hours

    General Code/Help
    2
    6
    44
    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.
    • cept0r
      cept0r last edited by

      I was looking around on how to implement a timer so that every time I get stopped out I want to stop the strategy for x hours and start it up again once x hours has passed.
      What is a simple way to implement this?

      Let's say I have something like this:

      if not self.position:
          if buy_signal1:
               self.buy()
      
      if self.position:
          if sell_signal1:
                self.sell()
          if stop_signal:
                self.sell()
                if stop_signal:
                      [insert timer code here?]
      
      1 Reply Last reply Reply Quote 0
      • run-out
        run-out last edited by

        You can simply have a variable (self.no_trade_time) or something like that, place it at the beginning of next and if the time is before that time, no trades. Every time you stop, set the variable 4 hours out.

        run-out 1 Reply Last reply Reply Quote 1
        • run-out
          run-out @run-out last edited by

          To clarify, you have a return if current time is less than self.no_trade_time.

          cept0r 2 Replies Last reply Reply Quote 0
          • cept0r
            cept0r @run-out last edited by

            @run-out Thank you!

            1 Reply Last reply Reply Quote 0
            • cept0r
              cept0r @run-out last edited by

              @run-out
              So I did not get the full picture of what you are trying to explain.

              This is what I got so far:

              self.t1 = close + datetime.timedelta(hours=4)
              

              Current close + 4hours stored in a variable

              Stop-loss:

                      if pos == step4:  # 4
                          if close <= buy4:
                              self.stoploss = self.sell(price=stop, size=-pos, exectype=bt.Order.Stop)
                              self.log('Close below buy step 4.. creating stoploss @ %.2f' % stop)
                              print(pos)
                              if close >= sell1:
                                  self.cancel(self.stoploss)
                                  self.log('Current price reached sell 1 cancelling stop... %.2f' % close)
                                  print(pos)
              

              Where do I place my "timer" variable so that if the stoploss executes the algorithm initiates the variable and stops the algorithm for x hours ?

              1 Reply Last reply Reply Quote 0
              • run-out
                run-out last edited by

                You can set up your variable in notify_order at the end. When the order has traded, set your variable to four hours out, then check that variable at the beginning of next.

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