Charts & TradeID



    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?


  • administrators

    @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), becauseclose` calculates the right size for you.


Log in to reply
 

Looks like your connection to Backtrader Community was lost, please wait while we try to reconnect.