Backtrader Community

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. Meng Xiaofeng
    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 2
    • Posts 9
    • Best 0
    • Controversial 0
    • Groups 0

    Meng Xiaofeng

    @Meng Xiaofeng

    0
    Reputation
    58
    Profile views
    9
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Meng Xiaofeng Unfollow Follow

    Latest posts made by Meng Xiaofeng

    • RE: Backtrader 2.0?

      I think the Chart functionality can be enhanced, for example, to visualize the process of back testing (just like the strategy tester in MT5), instead of show the chart only after the testing is done, so that it is easier to watch how the strategy works in each step from the chat.

      posted in General Discussion
      Meng Xiaofeng
      Meng Xiaofeng
    • RE: How to know the first index in the next function of indicator?

      many thanks for anwser!
      but still the question: is it possible to get the first index and use the index explicitly?

      posted in General Code/Help
      Meng Xiaofeng
      Meng Xiaofeng
    • How to know the first index in the next function of indicator?

      Hi,
      I am trying to make my own indicator in which i want to find which bar in the history is higher than current high.
      how do I know which one is the first bar( -1, -2, -3 ....) so that the loop can have a end point?

      class MyInd(bt.Indicator):
          lines = ('example',)
       
          def next(self):
               for (i = -1; i > ?; i--)
                     if self.data.high[i] > self.data.high[0]:
                         distance = -i;
                         break;
      

      Thanks!

      posted in General Code/Help
      Meng Xiaofeng
      Meng Xiaofeng
    • RE: Sell/Buy signal labels are missing in the plotting of forex data

      Now I got your idea! didn't realise there is such buy/sell observer.
      now i know that the backtrader has a very flexilbe design and love it more.

      Just a remark: can't the Sell/buy observer be a bit smarter so that it can always plot properly?

      Thanks!

      posted in General Code/Help
      Meng Xiaofeng
      Meng Xiaofeng
    • RE: Sell/Buy signal labels are missing in the plotting of forex data

      anyone could help?

      posted in General Code/Help
      Meng Xiaofeng
      Meng Xiaofeng
    • RE: Sell/Buy signal labels are missing in the plotting of forex data

      it seems that it is because of the data in forex csv file: the number is too small,
      it will work if i change the price to bigger values, such as from "000000;1.123210;1.123240;1.123200;1.123240;0"
      to "000000;3210;3240;3200;3240;0".

      so it looks a bug in backtrader when handling precision of the price.

      posted in General Code/Help
      Meng Xiaofeng
      Meng Xiaofeng
    • RE: Sell/Buy signal labels are missing in the plotting of forex data

      @backtrader Hi sorry for the format issue, it's my first post and I have fixed it.
      Could you have a look again?

      Thanks!

      posted in General Code/Help
      Meng Xiaofeng
      Meng Xiaofeng
    • RE: Sell/Buy signal labels are missing in the plotting of forex data

      @backtrader said in Sell/Buy signal icons are missing in the plot:

      position as this

      Wow, thanks for your quick reply!

      The "buy/sell Icons" i meant is as following (in the black circle that i drew):
      0_1560931792157_Screen Shot 2019-06-19 at 10.04.44.png

      but they are missing in first picture (1 minutes csv data).
      any idea?

      posted in General Code/Help
      Meng Xiaofeng
      Meng Xiaofeng
    • Sell/Buy signal labels are missing in the plotting of forex data

      Hello!
      I am using the 1-minutes forex csv data for backtesting, odd thing observed is that the buy/sell icons are missing in the plotting.
      using daily csv data from yahoo is fine, so looks there is some tricky issue in the csv part.
      Could anybody please help me with the issue?

      the code is

      from datetime import datetime
      import backtrader as bt
      
      class SmaCross(bt.SignalStrategy):
          def __init__(self):
              sma1, sma2 = bt.ind.SMA(period=1), bt.ind.SMA(period=60)
              crossover = bt.ind.CrossOver(sma1, sma2)
              self.signal_add(bt.SIGNAL_LONG, crossover)
      
      
      if __name__ == '__main__':
          # Create a cerebro entity
          cerebro = bt.Cerebro()
      
          # Add a strategy
          #cerebro.addstrategy(MyStrategy, period=15)
      
          cerebro.addstrategy(SmaCross)
      
          # sh: 000001.SS
          # BT: BTC-USD
          # SP500: ^GSPC
          #data0 = bt.feeds.YahooFinanceData(dataname='BTC-USD', fromdate=datetime(2018, 1, 1),
          #                                  todate=datetime(2019, 6, 1), decimals=5)
      
          data0 = bt.feeds.GenericCSVData(
          dataname='./eurusd-1m/DAT_ASCII_EURUSD_M1_201904.csv',
      
          fromdate=datetime(2019, 4, 1),
          todate=datetime(2019, 4, 10),
      
          nullvalue=0.0,
      
          dtformat=('%Y%m%d %H%M%S'),
          #tmformat=('%H:%M:%S'),
      
          datetime=0,
          time=-1,
          high=2,
          low=3,
          open=1,
          close=4,
          volume=-1,
          openinterest=-1,
          timeframe=bt.TimeFrame.Minutes,
          compression = 1,
          separator=';',
          decimals=5,
          headers=False
          )
      
          cerebro.resampledata(data0, timeframe=bt.TimeFrame.Minutes,
                                compression=30)
         
          # Set our desired cash start
          cerebro.broker.setcash(1000000.0)
      
          # Add a FixedSize sizer according to the stake
          #cerebro.addsizer(bt.sizers.FixedSize, stake=2)
          cerebro.addsizer(bt.sizers.PercentSizer, percents=90)
      
          # Set the commission - 0.1% ... divide by 100 to remove the %
          cerebro.broker.setcommission(commission=0.0005)
      
          # Print out the starting conditions
          print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
      
          # Run over everything
          cerebro.run()
      
          # Print out the final result
          print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
          cerebro.plot(style='bar')
      

      The CSV data looks as following:

      20190401 000000;1.123210;1.123240;1.123200;1.123240;0
      20190401 000100;1.123230;1.123230;1.123140;1.123190;0
      20190401 000200;1.123210;1.123310;1.123200;1.123310;0
      20190401 000300;1.123330;1.123360;1.123310;1.123340;0
      20190401 000400;1.123330;1.123330;1.123250;1.123250;0
      

      The plotting:
      0_1560927695451_Screen Shot 2019-06-19 at 09.00.57.png

      posted in General Code/Help
      Meng Xiaofeng
      Meng Xiaofeng