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/

    Pass actions to execute into strategy

    General Code/Help
    3
    4
    1281
    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.
    • Maxim Korobov
      Maxim Korobov last edited by Maxim Korobov

      Imagine that strategy should sometimes listen to outer world, which could say when to buy or sell. Signals come with array of order object with fields: ticker, size, date, action (buy/sell).

      Strategy should load array of orders before start, execute them in their times and do nothing untill last order will be executed.

      How to pass array of order objects into Strategy?
      Using params? It's now params.
      Using maybe datas array?

      1 Reply Last reply Reply Quote 0
      • A
        ab_trader last edited by

        You can build an indicator with necessary lines and trade based on it.

        • 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
        • B
          backtrader administrators last edited by

          This was outlined here: Community - Importing orders #219

          Your options:

          • The data feed contains the extra data. You then read it directly from the data feed

          • With separate data you load it into an indicator and check if the timestamp of the data feed matches the next timestamp of the action to be executed. And the indicator may signal with 1 (Buy) and -1 (sell), plus potentially extra lines for size, price and some other things.

          • As you point out ... you can pass it as a parameter to the strategy and do the check with the trading logic.

          The indicator solution seems the cleanest, because it does isolate data and logic.

          1 Reply Last reply Reply Quote 0
          • Maxim Korobov
            Maxim Korobov last edited by

            Done! Thanks for ideas!

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