Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. you
    3. Posts
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    Y
    • Profile
    • Following 0
    • Followers 0
    • Topics 7
    • Posts 11
    • Best 0
    • Groups 0

    Posts made by you

    • Possible to change 4-hr bar start time?

      Hi,

      I am working on a BT strategy trading HSI Futures using IB aaa broker. Is there a way that I can have one hour bar from IB resampled to 4 hours bar and also adjust the start time of the 1st bar of the day to 9:00am instead of from 8:00?

      With trading hours of HSI futures: 9:15 am - 12:00 noon, 1:00 pm - 4:30 pm & 5:15 pm - 3:00 am.

      If I can adjust the 1st 4-hr bar to start at 9:00 then I can have the full day separated into 4-hr sessions with 9:00-12:59, 13:00-16:59, 17:00-20:59, 21:00-00:59, 01:00-04:59.

      Thanks

      posted in General Code/Help
      Y
      you
    • How to combine historical plus real time data under IB connection

      Hello,

      Using IBStore , is there a way that I can 1st load like 2 months of historical data then immediately load real time data into the same single data feed so that I can get longer time range for sma?

      Thanks

      posted in General Code/Help
      Y
      you
    • Backtrader 1.9.46.116 - Is docheckover declaration missing in resamplerfilter.py __call__

      Running with backtrader-master-1.9.46.116, my program quit everytime after running for a little while with the following message:

      ..beta/lib/python3.5/site-packages/backtrader/resamplerfilter.py", line 650, in call
      if docheckover:
      UnboundLocalError: local variable 'docheckover' referenced before assignment

      Without knowing the actual use of the variable, I added the following and looks like can temporarily fix the issue.

      def __call__(self, data, fromcheck=False, forcedata=None):
          consumed = False
          onedge = False
          takinglate = False
          # ADD HERE
          docheckover = False
      
      posted in General Code/Help
      Y
      you
    • RE: Bbands using Ema instead of sma

      Thanks - will test with the latest version

      posted in General Code/Help
      Y
      you
    • RE: Bbands using Ema instead of sma

      Hi

      Here is one example:
      Live data from IB on AUD-201706-GLOBEX

      bbands with SMA: (period=20, devfactor=2.0)
      top: 0.751921 mid: 0.751146 bot: 0.750371 2017-04-07T14:21:30
      
      bbands with EMA: (period=20, devfactor=2.0, movav=bt.indicators.MovAv.EMA)
      top: 0.792232 mid: 0.751423 bot: 0.710615 2017-04-07T14:21:30
      

      Compare to IB, the EMA top and bot point in the program are much higher (IB value : top 0.7524 bot: 0.7504) but the mid point matches at 0.751423. Also SMA values matches with IB.

      Any suggestion how I can further check on this?

      posted in General Code/Help
      Y
      you
    • Bbands using Ema instead of sma

      Hi

      Can I use ema instead of default sma for bbands indicator? I tried to pass bt.indicators.MovAv.EMA to param movav when creating bands , the code starts and run without isssue but the bbands top and bot values are much bigger than the expected value.. it works perfectly fine with sma.

      Thanks

      posted in General Code/Help
      Y
      you
    • RE: next() not generated anymore after "IB and Trader Workstation connectivity lost"

      I also believe the daily disconnection was due to IB server reset. Thanks for the pointer to issue #283, I will further check on that.

      Below is the log related to the puzzle: IB and TWS disconnected but program continue to receive tickPrice and tickSize events. There is no more STORE NOTIF logged after the errorCode=1100 TWS to IB disconnection or even after received errorCode=1102 TWS to IB connection resumed. It probably also means that cerebro and strategy is not receiving any of this ticks after 1100 error there no next() event was generated....

      ***** STORE NOTIF: <tickSize tickerId=16777217, field=3, size=1000000>
      ***** STORE NOTIF: <tickSize tickerId=16777217, field=3, size=1000000>
      <currentTime time=1490330404>
      ***** STORE NOTIF: <currentTime time=1490330404>
      **<error id=-1, errorCode=1100, errorMsg=Connectivity between IB and Trader Workstation has been lost.>**
      <tickPrice tickerId=16777217, field=1, price=111.332, canAutoExecute=1>
      <tickSize tickerId=16777217, field=0, size=500000>
      <tickSize tickerId=16777217, field=0, size=500000>
      <tickSize tickerId=16777217, field=0, size=1000000>
      <tickPrice tickerId=16777217, field=2, price=111.334, canAutoExecute=1>
      <tickSize tickerId=16777217, field=3, size=3000000>
      <tickSize tickerId=16777217, field=3, size=3000000>
      **<error id=-1, errorCode=1100, errorMsg=Connectivity between IB and Trader Workstation has been lost.>**
      **<error id=-1, errorCode=1100, errorMsg=Connectivity between IB and Trader Workstation has been lost.>**
      <tickSize tickerId=16777217, field=3, size=1000000>
      <tickPrice tickerId=16777217, field=1, price=111.333, canAutoExecute=1>
      <tickSize tickerId=16777217, field=0, size=500000>
      <tickSize tickerId=16777217, field=0, size=500000>
      <tickPrice tickerId=16777217, field=2, price=111.335, canAutoExecute=1>
      <tickSize tickerId=16777217, field=3, size=7000000>
      <tickSize tickerId=16777217, field=0, size=1000000>
      <tickSize tickerId=16777217, field=3, size=7000000>
      <tickSize tickerId=16777217, field=3, size=5000000>
      **<error id=-1, errorCode=1100, errorMsg=Connectivity between IB and Trader Workstation has been lost.>**
      <tickSize tickerId=16777217, field=3, size=3000000>
      <tickSize tickerId=16777217, field=0, size=2000000>
      <tickSize tickerId=16777217, field=0, size=3000000>
      <tickSize tickerId=16777217, field=3, size=2000000>
      <tickSize tickerId=16777217, field=3, size=3000000>
      <tickPrice tickerId=16777217, field=1, price=111.334, canAutoExecute=1>
      <tickSize tickerId=16777217, field=0, size=1000000>
      <tickSize tickerId=16777217, field=0, size=1000000>
      <tickSize tickerId=16777217, field=3, size=2000000>
      <tickSize tickerId=16777217, field=3, size=1000000>
      <tickPrice tickerId=16777217, field=2, price=111.336, canAutoExecute=1>
      ...
      ...
      <error id=-1, errorCode=2103, errorMsg=Market data farm connection is broken:cashfarm>
      **<error id=-1, errorCode=1102, errorMsg=Connectivity between IB and Trader Workstation has been restored - data maintained.>**
      <error id=-1, errorCode=2104, errorMsg=Market data farm connection is OK:cashfarm>
      <tickPrice tickerId=16777217, field=6, price=111.445, canAutoExecute=0>
      <tickPrice tickerId=16777217, field=7, price=110.865, canAutoExecute=0>
      <tickPrice tickerId=16777217, field=9, price=110.92, canAutoExecute=0>
      <tickPrice tickerId=16777217, field=1, price=111.328, canAutoExecute=1>
      <tickSize tickerId=16777217, field=0, size=4000000>
      <tickPrice tickerId=16777217, field=2, price=111.33, canAutoExecute=1>
      <tickSize tickerId=16777217, field=3, size=1000000>
      <tickSize tickerId=16777217, field=0, size=4000000>
      <tickSize tickerId=16777217, field=3, size=1000000>
      <tickPrice tickerId=16777217, field=1, price=111.329, canAutoExecute=1>
      
      posted in General Code/Help
      Y
      you
    • next() not generated anymore after "IB and Trader Workstation connectivity lost"

      Hello,

      I am connecting to IB for live data, everyday around 12:00pm HKT, the following error is received:

       ***** STORE NOTIF: <currentTime time=1490330404>
      <error id=-1, errorCode=1100, errorMsg=Connectivity between IB and Trader Workstation has been lost.>
      <tickPrice tickerId=16777217, field=1, price=111.332, canAutoExecute=1>
      

      After receiving the 1100 error message, the program continue to receive tickPrice and tickSize events but the notify_data() and notify_store() events never resumed and next() event is also never get generated. It is not resumed event after receiving the 1102 message from IB "Connectivity between IB and Trader Workstation has been restore - data maintained". To resume, I have to kill the program and restart from fresh.

      Has anyone got similar problem and if there is a way to resume the data feed in this scenario without restarting the program?

      Thanks very much for your help!

      posted in General Code/Help
      Y
      you
    • IndexError: deque index out of range

      I was running sample program ibtest.py with these parameters and got
      a 'Index Error: deque index out of range' error after received ~1100 ticks and ~180 ticks for the two data feed.... this error can be re-produced very often but not every time... wonder if anyone has seen this before...

      >> python ibtest.py --port 4001 --data0 AUD.USD-CASH-IDEALPRO --timeframe Seconds --compression 10 --data1 AUD.USD-CASH-IDEALPRO --timeframe1 Seconds --compression1 60 --replay --usestore --trade --notifyall --debug
      
      :~/dev/t1-p3.5/src/myalgo$ Traceback (most recent call last):
        File "ibtestorg.py", line 467, in <module>
          runstrategy()
        File "ibtestorg.py", line 275, in runstrategy
          cerebro.run(exactbars=args.exactbars)
        File "/home/x/dev/t1-p3.5/lib/python3.5/site-packages/backtrader/cerebro.py", line 810, in run
          runstrat = self.runstrategies(iterstrat)
        File "/home/x/dev/t1-p3.5/lib/python3.5/site-packages/backtrader/cerebro.py", line 940, in runstrategies
          self._runnext(runstrats)
        File "/home/x/dev/t1-p3.5/lib/python3.5/site-packages/backtrader/cerebro.py", line 1256, in _runnext
          strat._next()
        File "/home/x/dev/t1-p3.5/lib/python3.5/site-packages/backtrader/strategy.py", line 296, in _next
          super(Strategy, self)._next()
        File "/home/x/dev/t1-p3.5/lib/python3.5/site-packages/backtrader/lineiterator.py", line 236, in _next
          clock_len = self._clk_update()
        File "/home/x/dev/t1-p3.5/lib/python3.5/site-packages/backtrader/strategy.py", line 290, in _clk_update
          for d in self.datas if len(d))
        File "/home/x/dev/t1-p3.5/lib/python3.5/site-packages/backtrader/strategy.py", line 290, in <genexpr>
          for d in self.datas if len(d))
        File "/home/x/dev/t1-p3.5/lib/python3.5/site-packages/backtrader/linebuffer.py", line 163, in __getitem__
          return self.array[self.idx + ago]
      IndexError: deque index out of range
      
      posted in General Code/Help
      Y
      you
    • RE: next() called multiple times within timeframe and bid/ask availability

      Thanks very much for your reply. May I further check the following:

      • With IB LIVE data, when using resample and replay e.g. (data, timeframe=Minutes, compression=5), if there is really no market event triggered within the 5 minutes e.g. from 10:00am to 10:05am, no bar will be generated at 10:05am as next() has not been called due to lack of data trigger. Is there available option or standard mechanism that can force generation of the 10:05am bar or it has to be implemented locally? I thought I have the qcheck=0.5 default to force this but seems it has no effect.

      • With IB LIVE data, when using replay(data, timeframe=Minutes, compression=5), next() will be called for each tick received within the 5 mins compression period with the same len(self.data0) value e.g. len(self.data0)=299 between 10:00am to 10:05am. Is there a standard mechanism in next() that I can dintinguish the intra-period ticks and the end of period tick? Or do I need to check the event time e.g. look for event time at e.g. 10:05:00.000000

      • With IB LIVE data, when using resample(data, timeframe=Minutes, compression=1), sometime next() will be called multiple times at start of a minute e.g. 10:00am but with exact same values (open, high, low, close and indicators). I have checked the time and sales in IB and there is no trades happened from 09:59:59am and 10:00:01am so wonder what may trigger the duplicate next() call.

      -- still learning to operate the platform and really appreciate your time and effort making this available to all

      posted in General Code/Help
      Y
      you
    • next() called multiple times within timeframe and bid/ask availability

      Hello, I am new to the platform and got some questions would like to seek your advice:

      1. I am using IB as broker and called cerebro.replaydata(...) with timeframe=Minutes and compression=1. When receiving DELAYED feed, next() was called with every one minute period, however, when switched to LIVE, the next() call is called many times within the minute which looks like tick from IB. Is it the expected bahavior that the next() is called multiple times during the one minute period during LIVE feed?

      2. Is it possible to get latest bid/ask in the next() call together with other line data e.g. open, high, low or need to be a separate data feed? I tried to search some previous discussion on this topic but still not sure if it is possible yet..

      3. I am trying to build a strategy that reads AUD.USD.CASH-IDEALPRO and AUD Futures. For AUD.USD.CASH feed, I would like to build indicators base on 5 and 15 minutes period and for AUD Futures I would like to get the latest bid/ask price at the point when placing Futures orders. Should I create 3 data feeds for above e.g.

      • cerebro.replaydata(AUD.USD.CASH, timeframe=Minutes, period=5, ...)
      • cerebro.replaydata(AUD.USD.CASH, timeframe=Minutes, period=15,...)
      • cerebro.replaydata(AUD.FUTUREs, timeframe=Ticks, period=1,...) plus how to get bid/ask

      Sorry if these are very primitive questions and any help will be much appreciated.

      posted in General Code/Help
      Y
      you
    • 1 / 1