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/

    Charts & TradeID

    General Code/Help
    2
    2
    768
    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.
    • T
      Taewoo Kim last edited by

      1. Are only completed trades shown in the chart? (i.e. open positions don't show?)

      2. Currently, I am passing a tradeid (generated by str(uuid.uuid4())[:8]) to every order, so that I can keep references to them in an internal dict. If order is long, i would call self.sell(tradeid=some_tradeid). I've noticed in other forum posts that this isn't how people close out their positions. Is my understanding incorrect?

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

        @Taewoo-Kim said in Charts & TradeID:

        1. Are only completed trades shown in the chart? (i.e. open positions don't show?)

        Yes

        1. Currently, I am passing a tradeid (generated by str(uuid.uuid4())[:8]) to every order, so that I can keep references to them in an internal dict. If order is long, i would call self.sell(tradeid=some_tradeid). I've noticed in other forum posts that this isn't how people close out their positions. Is my understanding incorrect?

        tradeid has no specific requirements. It is just an identifier. It would seem simpler to use something like mytradeid = itertools.counter(1) and then use mynewtradeid = next(mytradeid) to have a unique reference which is a lot more palatable for human consumption. But any tradeid will actually do.

        If you use the tradeid and want to undo a buy(tradeid=x), you should either do sell(tradeid=x). Of course sell doesn't guarantee you close a position unless you specifiy the same size or have a sizer that does it for you. You may also use close(tradeid=x), because close` calculates the right size for you.

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