Backtrader Community

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

    Li Mike

    @Li Mike

    7
    Reputation
    18
    Profile views
    49
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Li Mike Unfollow Follow

    Best posts made by Li Mike

    • Any guidance on when to use self. ?

      Hi, I see some code in strategy as follows:

      def __init__(self):
          # To control operation entries
          self.orderid = None
      
          # Create SMA on 2nd data
          sma = btind.MovAv.SMA(self.data1, period=self.p.period)
          # Create a CrossOver Signal from close an moving average
          self.signal = btind.CrossOver(self.data1.close, sma)
      

      I wonder why the sma isn't prefixed by self. while signal is. Is there any guidance tell us when to use self or not?

      posted in General Discussion
      Li Mike
      Li Mike
    • RE: Any guidance on when to use self. ?

      Got it. I misunderstood something stupidly.

      posted in General Discussion
      Li Mike
      Li Mike
    • RE: what lines are there in a strategy?

      That's what I want, thank you.

      posted in General Discussion
      Li Mike
      Li Mike
    • RE: How to make Market order valid.

      @ab_trader thank you for your reply.
      Suppose the data is as follows:
      2019-01-01, ...
      2019-02-15, ...
      At first bar, that is 2019-1-1, I issue an order, then it will be executed at the second bar, that is 2019-2-15. Now, I want the order to expire on 2019-1-10. How to do it?
      I think if I can set a valid day for the market order, the problem can be solved easily.

      posted in General Discussion
      Li Mike
      Li Mike
    • RE: bt.If( ) doesn't protect float division by zero.

      My fault. Thank you.

      posted in General Discussion
      Li Mike
      Li Mike
    • RE: Walk Forward Analysis Demonstration

      @barton05 said in Walk Forward Analysis Demonstration:

      jsonConfigMap

      Thank you for your code, Barton05. When I run your code, I get NameError: name 'jsonConfigMap' is not defined. Could you tell mei how to fix it?

      posted in General Discussion
      Li Mike
      Li Mike
    • how to update a trade?

      Hi, backtrader. In the doc, it says a strategy can
      be notified through notify_trade(trade) of any opening/updating/closing trade.

      I know how to open, close a trade. But I don't know how to update a trade, could anyone give an example?

      Thanks in advance.

      posted in General Discussion
      Li Mike
      Li Mike

    Latest posts made by Li Mike

    • RE: Resample data with timeframe.days at specific (non-midnight) time

      @backtrader In chinese future market, sessionstart is 21:00 and sessionend is 15:00 next day. So, you see sessionstart is indeed larger than session end. Can backtrader process this situation correctly?

      posted in General Code/Help
      Li Mike
      Li Mike
    • session start and session end in different day.

      Hi, in Chinese furtures market. A trading day starts at 21:00 and ends at 15:00 next day. That means session start and session end in different day. When live trading, the resample won't behave correctly by default. So, I wonder if it is possible to set session start and session end in different day?

      posted in General Code/Help
      Li Mike
      Li Mike
    • live trader error when resampling.

      Hi, I am runing a live paper trade.
      I accept ticks data and add it to cerebro, and resample to 10s bars in backtrader.
      I get an error:
      File "e:\myquant\venv_quant389\lib\site-packages\backtrader\cerebro.py", line 1591, in _runnext
      dt0 = min((d for i, d in enumerate(dts) if d is not None and i not in rsonly))
      ValueError: min() arg is an empty sequence

      I did some debug and find that the problem comes from the following snippet.

      In Cerebro's _runnext method, there is a snippet as follows.

                  if d0ret:
                      dts = []
                      for i, ret in enumerate(drets):
                          dts.append(datas[i].datetime[0] if ret else None)
      
                      # Get index to minimum datetime
                      if onlyresample or noresample:
                          dt0 = min((d for d in dts if d is not None))
                      else:
                          dt0 = min((d for i, d in enumerate(dts)
                                     if d is not None and i not in rsonly))
      

      dt0 = min((d for i, d in enumerate(dts)
      if d is not None and i not in rsonly))
      this statement got 'min() arg is an empty sequence' error.
      I think when sometime there is no tick, the err ocurs.

      How to fix this problem?
      Thanks in advance.

      posted in General Code/Help
      Li Mike
      Li Mike
    • how extend a live data feed

      Hi, there. I wonder how to extend a live data feed to include for example askprice line?

      posted in General Code/Help
      Li Mike
      Li Mike
    • how to display buysell observer in an indicator plot?

      for example, how to display buysell in a RSI plot?

      posted in General Discussion
      Li Mike
      Li Mike
    • what's the meaning of buy/sell in writer csv

      I use the following command to write results to a csv file. In the csv, I find two columns "buy" and "sell". It seems they are not buy or sell prices. I wonder what is the meaning of them. Thanks in advance.

      cerebro.addwriter(bt.WriterFile, csv=True, out='mywriter.csv', rounding=2)

      posted in General Discussion
      Li Mike
      Li Mike
    • Can support long and short position simultaneously?

      Hi, backtraders. In Chinese futures market, for the same contract, you can hold long and short positions simultaneously. and we have four commands to submit an order: open_long, close_long, open_short, close_short.

      I wonder if it's possible to customize bt to support Chinese future market?

      posted in General Discussion
      Li Mike
      Li Mike
    • question on replay

      Hello, backtrader. I have a question on replay. pls see the following.

      class SmaCross(bt.Strategy):
      
          def __init__(self):
              self.SMA0 = bt.ind.MovingAverageSimple(self.data0, period=5)
              self.SMA1 = bt.ind.MovingAverageSimple(self.data1, period=5)
      
          def next(self):
              pass
      
              if self.data0.datetime.datetime() == datetime.datetime(2010, 1, 1, 12,
                                                                     19) or self.data0.datetime.datetime() == datetime.datetime(
                      2010, 1, 1, 12, 18):
                  print(self.data0.datetime.datetime(), 'd1_sma', self.SMA1[0], 'd1_sma[-1]', self.SMA1[-1])
      
      
      ##########################
      # main
      #########################
      
      
      cerebro = bt.Cerebro()
      
      data = bt.feeds.GenericCSVData(
          dataname='./candles00.csv',
          timeframe=bt.TimeFrame.Minutes,
      )  # 1 minute bar
      
      cerebro.adddata(data, name='1min')
      cerebro.replaydata(data, timeframe=bt.TimeFrame.Minutes, compression=60, name='60m')  # 60 minute bar
      
      cerebro.addstrategy(SmaCross)
      cerebro.broker.setcash(10000)
      results = cerebro.run()
      
      
      
      

      and the following is the output.
      I expect that sma[-1] for data1 at 12:19 should be equal to sma[0] at 12:18, but they are not. I wonder how to make them equal.
      QQ图片20210327102135.png

      posted in General Discussion
      Li Mike
      Li Mike
    • RE: OandaV20Store‘s callback method _t_streaming_prices

      I know it is created and start as a thread by streaming_prices. But I don't know who whill call back it.

      posted in General Discussion
      Li Mike
      Li Mike
    • OandaV20Store‘s callback method _t_streaming_prices

      Hi, friends. I am studying OandaV20Store, there is method:

          def _t_streaming_prices(self, dataname, q):
              '''Callback method for streaming prices'''
              try:
                  response = self.oapi_stream.pricing.stream(
                      self.p.account,
                      instruments=dataname,
                  )
                  # process response
                  for msg_type, msg in response.parts():
                      if msg_type == 'pricing.ClientPrice':
                          # put price into queue as dict
                          q.put(msg.dict())
      

      The comment says it is a Callback method for streaming prices. I guess every time a new data come, then the method will be called. I wonder which method trigger this method? could someone gives me a hint?

      posted in General Discussion
      Li Mike
      Li Mike