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/

    setting min period inside the strategy

    General Code/Help
    3
    8
    1397
    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
      siavash last edited by

      Hello,
      How can I set the first start candle inside the strategy. I found that this is done by setminperiod(minperiod) method. But I don't know how to set that inside a strategy.

      A B 2 Replies Last reply Reply Quote 0
      • A
        ab_trader @siavash last edited by

        @siavash minperiod is set automatically (usually) as soon as all data has non-NaN values. If you need to define the first bar of your backtest, then just check the date/time of the bars in the next(). If it is higher then your start date, then process your rules.

        • If my answer helped, hit reputation up arrow at lower right corner of the post.
        • Python Debugging With Pdb
        • New to python and bt - check this out
        1 Reply Last reply Reply Quote 0
        • S
          siavash last edited by

          I want to use for example 10 first candles inside the next method and after that sending order. I know that I can check date time inside the next method but it is so time consuming.

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

            @siavash said in setting min period inside the strategy:

            How can I set the first start candle inside the strategy I found that this is done by setminperiod(minperiod) method

            @siavash said in setting min period inside the strategy:

            I want to use for example 10 first candles inside the next method and after that sending order.

            Both things have nothing to do with each other. If you want to skip 10 candles in next, check the length of the strategy itself.

            @siavash said in setting min period inside the strategy:

            I know that I can check date time inside the next method but it is so time consuming.

            You are probably in the wrong business if you consider than programming something to make money automatically for you is time consuming.

            1 Reply Last reply Reply Quote 0
            • S
              siavash last edited by siavash

              I didn't understand your answer. What is time cosuming?????!!!! I mean that is there better way to set min period rather than using date time.

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

                @siavash said in setting min period inside the strategy:

                What is time cosuming?????

                You said that it is time consuming.

                @siavash said in setting min period inside the strategy:

                mean that is there better way to set min period rather than using date time.

                @backtrader said in setting min period inside the strategy:

                ... If you want to skip 10 candles in next, check the length of the strategy itself.

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

                  @backtrader
                  How can I skip. I dont know how?
                  I want to record 10 candles data and then send an order and save corresponding result in a text file. Also do this for remaining data. Could you please write code for help?🙏

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

                    @siavash said in setting min period inside the strategy:

                    @backtrader
                    How can I skip. I dont know how?
                    I want to record 10 candles data and then send an order and save corresponding result in a text file. Also do this for remaining data. Could you please write code for help?🙏

                    if len(self) > (self.len_self_first_time_next_was_called + 10):
                       # do something
                    

                    Again: if things consider things to be time consuming and you can't write that simple code, you have to reconsider if you want to be in algotrading.

                    1 Reply Last reply Reply Quote 0
                    • 1 / 1
                    • First post
                      Last post
                    Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors