Backtrader Community

    • 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/

    Optimizing MA crossover periods in optstrategy

    Indicators/Strategies/Analyzers
    2
    2
    285
    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.
    • W
      wykazox last edited by

      Hi All,

      I have what I think is a fairly basic question, but can't seem to find the answer anywhere!

      Say I have a simple MA crossover strategy(buy when fast MA crosses over slow MA, sell when fast MA crosses under slow MA).
      Now, I want to test a wide range of parameters, but I would like to ensure that fast MA period is always smaller than the slow MA period.
      This could also roughly cut the optimisation time in half.

      I tried tinkering with cerebro.optstrategy:

      cerebro.optstrategy(
              MACross,
              MAfast=list(range(2, 50, 2)),
              MAslow=[x > MAfast for x in list(range(10, 200, 10))],)
      

      or

      cerebro.optstrategy(
              MACross,
              MAfast=list(range(2, 50, 2)),
              MAslow=[x > self.p.MAfast for x in list(range(10, 200, 10))],)
      

      or other variants using

              MAslow=[x > MACross.p.MAfast for x in list(range(10, 200, 10))],)
      
              MAslow=[x > strategy.p.MAfast for x in list(range(10, 200, 10))],)
      

      but none of these seem to work...
      I get errors like:

      NameError: name 'MAfast' is not defined
      

      or

      NameError: name 'self' is not defined
      

      etc...

      Not sure how I can approach that problem...
      Thanks for your help!

      1 Reply Last reply Reply Quote 0
      • W
        wykazox last edited by

        @run-out OK, wow, I thought it would be something way simpler...
        I might just keep on deleting them from my results.

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