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/

    How do i identify when price action gets tight?

    Indicators/Strategies/Analyzers
    2
    3
    704
    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.
    • S
      Sagittarius19 last edited by

      Hello,

      I am trying to write a script to identify and buy when the closes of the past 15 seconds stay between two prices. Below is the code i have so far. I am using tick data so the time between ticks can vary. Meaning (close[0], close[1] and close[2] can all have different spans of time between them. Hence why i am using time for my entry.

      Any idea how to make this work? In this particular case, i am trying to buy when the close has stayed in a 5 cent range for atleast 15 seconds.

       def next(self):
      
          for i, d in enumerate(self.datas):
              if (len(self.datas[i])>0):
      
                  close  = self.datas[i].close
                  price_up2 = price[-1] +.02
                  price_down2 = price[-1] - .02
                  
                  if not position:                        
                      if close_up2c > close[0] > close_down2c:
                          start_time = time.time()
                          if time.time() - start_time <= 15:
                              return
                          else: 
                              self.buy(data = d)
      
      1 Reply Last reply Reply Quote 0
      • B
        backtrader administrators last edited by

        The first thing is to use the actual time reference

        @sagittarius19 said in How do i identify when price action gets tight?:

        if time.time() - start_time <= 15:
        

        This is the time in your PC/Laptop/Raspberry Pi, which may have nothing to do with the trading time and the speed and which the data delivers ticks/bars.

        See: Docs - DateTime Management

        S 1 Reply Last reply Reply Quote 0
        • S
          Sagittarius19 @backtrader last edited by

          @backtrader Got it. Thanks for pointing this out

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