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

ploting StopLimit, StopTrail observers

  • Hello

    Question: how can I get value of actual limit of bt.Order.StopTrail (and bt.Order.Limit)?

    Goal: I want to plot actual limit of bt.Order.StopTrail (and bt.Order.Limit) - to see on the plot how it is changing during time.

    I open bracket orders:

    os=self.buy_bracket(stopexec=bt.Order.Limit, stopprice=stopprice1,
                        limitexec=bt.Order.StopTrail, limitargs=dict(trailpercent=trailpercent1))

    and to make plot I use observer:

    class obsSellSLTS(bt.Observer):
        lines = ('StopLoss', 'TrailStop')
        plotinfo = dict(plot=True, subplot=False)
        plotlines = dict(
        def next(self):
            if len( #checking if bracket order is set
                 if[1].created.pricelimit is not None:
                     self.lines.StopLoss[0] =[1].created.pricelimit
                 if[2].created.pricelimit is not None:
                     self.lines.TrailStop[0] =[2].created.pricelimit

    but looks like '[2].created.pricelimit' is not the right data
    So: which data should I use:[2].created.pclose,[2].created.plimit,[2].created.price,[2].created.pricelimit,

    or from 'executed'[2].executed.pclose,[2].executed.plimit,[2].executed.price,[2].executed.pricelimit,

    or in any other source?

    kind regards

  • administrators

    @silverbald said in ploting StopLimit, StopTrail observers:

    I want to plot actual limit of

    @silverbald said in ploting StopLimit, StopTrail observers:


    This order type has no limit price. The actual order price is tracking the price of the asset. It will actually execute as a Market order when the price is met. The constantly updated price is stored in order.created.price

  • can be deleted

  • Hello

    Thank You to both of you. It helped me a lot.
    Sorry for late response but finally I found reason for issue and together with your suggestion it works well :-)


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