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

Why do my algorithm stop after one trade?



  • The algorithm seems to run one, but I never get another next called. What I'm I missing? After the first trade, I would expect to see the holding... to continue to happen in the console until the next trade is triggered.

    def runstrats(args=None):
        args = parse_args(args)
    
        cerebro = bt.Cerebro(stdstats=True)
    
        fromdate = None
        if args.fromdate:
            dtformat = '%Y-%m-%d' + ('T%H:%M:%S' * ('T' in args.fromdate))
            fromdate = datetime.datetime.strptime(args.fromdate, dtformat)
    
        todate = None
        if args.todate:
            dtformat = '%Y-%m-%d' + ('T%H:%M:%S' * ('T' in args.todate))
            todate = datetime.datetime.strptime(args.todate, dtformat)
    
        # This is the Interactive Broker client
        store = ibstore.IBStore(host='127.0.0.1', # env('IB_URL'),
                                port=7496, # env('IB_PORT'),
                                clientId=35,
                                notifyall=True
                                # _debug=True
                                )
    
        # Add Data
        data0 = store.getdata(dataname=ib_symbol,
                              timeframe=bt.TimeFrame.Minutes,
                              fromdate=fromdate,
                              todate=todate,
                              compression=1,
                              rtbar=True)
    
        # Resample Data
        cerebro.resampledata(data0,
                             timeframe=bt.TimeFrame.Minutes,
                             compression=1
                             )
    
        data0.addfilter(bt.filters.Renko, size=0.0001)
        cerebro.adddata(data0)
    
        # Set the behavior
        cerebro.signal_accumulate(False)
        cerebro.signal_concurrent(False)
    
        # Broker
        cerebro.broker = store.getbroker()
        cerebro.broker.setcommission(commission=2.47, margin=2000.0, mult=10.0)
    
        # Sizer
        cerebro.addsizer(bt.sizers.FixedReverser, stake=5)
    
        # Observer
        cerebro.addobserver(bt.observers.FundValue)
    
        # Strategy
        cerebro.addstrategy(TwoBlock, **eval('dict(' + args.strat + ')'))
    
        # Execute
        kwargs = dict(stdstats=True)
        kwargs.update(**eval('dict(' + args.cerebro + ')'))
        cerebro.run(**kwargs)
    

    Output below

    Server Version: 76
    TWS Time at connection:20200901 17:04:03 Central Standard Time
    01-Sep-20 17:04:06 INFO      holding...
    01-Sep-20 17:05:03 INFO      holding...
    01-Sep-20 17:06:02 INFO      holding...
    01-Sep-20 17:07:02 INFO      holding...
    01-Sep-20 17:08:03 INFO      holding...
    01-Sep-20 17:09:03 INFO      holding...
    01-Sep-20 17:10:03 INFO      Buying position
    01-Sep-20 17:10:03 INFO      2020-09-01: Oref 1 / Buy at 1.19185
    01-Sep-20 17:10:03 INFO      2020-09-01: Oref 2 / Sell Stop at 1.1911500000000002
    01-Sep-20 17:10:03 INFO      2020-09-01: Oref 3 / Sell TP Limit at 1.2016
    01-Sep-20 17:10:03 INFO      2020-09-01: Oref 4 / Sell Tail STOP 0.06
    01-Sep-20 17:11:03 INFO      2020-09-01: Order ref: 1 / Type Buy / Status Submitted
    01-Sep-20 17:11:03 INFO      ORDER ACCEPTED/SUBMITTED 01/09/1970, 12:54:29
    01-Sep-20 17:11:03 INFO      2020-09-01: Order ref: 2 / Type Sell / Status Submitted
    01-Sep-20 17:11:03 INFO      ORDER ACCEPTED/SUBMITTED 01/09/1970, 12:54:29
    01-Sep-20 17:11:03 INFO      2020-09-01: Order ref: 3 / Type Sell / Status Submitted
    01-Sep-20 17:11:03 INFO      ORDER ACCEPTED/SUBMITTED 01/09/1970, 12:54:29
    01-Sep-20 17:11:03 INFO      2020-09-01: Order ref: 4 / Type Sell / Status Submitted
    01-Sep-20 17:11:03 INFO      ORDER ACCEPTED/SUBMITTED 01/09/1970, 12:54:29
    
    


  • I found the bug. I turned on _debug=true and was able to see the issue. The realtimebars were coming in as I expected.


Log in to reply
 

});