For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Different commissions for each order type

  • I would like to set different commissions depending on the order type, if it is buy/sell operations, it should charges a percentage comm = X, and if it is a close operation, it should charge double: 2X.

    def next(self):
        if condition1:
        elif condition2:

    Is there any way through commission scheme or other method to do this?
    Thank you in advance.

  • As you can see here:

    For order management 3 primitives:

    • buy
    • sell
    • cancel

    For order execution logic the following execution types:

    • Market
    • Close
    • Limit
    • Stop
    • StopLimit

    So I think this should work:

    if self.p.exectype == 'Close':
    else: // can be Market, Limit, Stop, or StopLimit

  • @balibou thank you for your reply, I think exectype == 'Close' refers to the "close price" rather than close operation.
    I've made a simple solution:

    commissions = []
    class CommInfo_My(bt.CommInfoBase):
        global commissions
        def _getcommission(self, size, price, pseudoexec):
            if commissions:
                comm = commissions[0] * size * price
            if not pseudoexec:
            return comm
    def next(self):
        if condition1:
        elif condition2:

Log in to reply