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


  • Hi all,

    I have created a custom broker by modifying a couple of functions from
    (calling the new file and putting it in my own code directory, -- not in the same folder as the original

    Now my question is: how can I call this one to be used instead?

    I tried to add a line

    import mybroker

    on top of the code, and though the import happens, it's still the original broker that gets used when I do:

    import backtrader
    import mybroker
    cerebro   = backtrader.Cerebro(maxcpus = 1)
    data      = PandasDataStrat1(dataname     = dataframe, 
                                         datetime     = -1, 
                                         open         = -1, 
                                         high         = -1, 
                                         low          = -1, 
                                         close        = -1,
                                         volume       = -1,
                                         openinterest = None)
        = 0.2, 
                                  margin     = 1000.0, 
                                  mult       = 100.0) = 100.0))

    So my question is: How to use my custom broker?

  • cerebro.setbroker(<instance of your broker class>)

  • administrators

    Why don't you use what's already documented?

    Example: Docs - Live Trading - Oanda v1.0

    The Cerebro reference says what setbroker does (can also be reached via the broker property): Docs - Cerebro

  • Thanks, worked like a charm. As usual, thank you for the prompt answer and the references;)

Log in to reply