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/

    Trade a stock using a moving average crossover of a different stock

    General Code/Help
    3
    3
    97
    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.
    • B
      Beliavsky last edited by

      I just installed backtrader (thanks, developers) and ran the example that trades MSFT using a moving average crossover of MSFT. How do you test a strategy that trades MSFT using the moving average crossover of another symbol, for example QQQ?

      run-out A 2 Replies Last reply Reply Quote 1
      • run-out
        run-out @Beliavsky last edited by

        @beliavsky

        This is no problem. First you need to enter two symbols, QQQ and MSFT. You'll need to know the order entered. I like to put the signal first, so QQQ would be datas[0] and MSFT would be datas[1].

        Calculate a moving average crossover indicator in the init or a custom indicator class on the datas[0] line which is QQQ in this example.

        Then in next you can use the moving average crossover indicator to trigger your buy, but then use self.datas[1] to trade MSFT

        RunBacktest.com

        1 Reply Last reply Reply Quote 1
        • A
          ab_trader @Beliavsky last edited by

          @beliavsky

          https://www.backtrader.com/blog/posts/2015-09-03-multidata-strategy/multidata-strategy/

          • 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 2
          • 1 / 1
          • First post
            Last post
          Copyright © 2016, 2017, 2018, 2019, 2020, 2021 NodeBB Forums | Contributors