Backtrader Community

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. chaT123
    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/
    C
    • Profile
    • Following 0
    • Followers 0
    • Topics 7
    • Posts 16
    • Best 0
    • Controversial 0
    • Groups 0

    Posts made by chaT123

    • Backtesting Using Intraday Data

      My data is in the format below:
      bdeaa232-df1f-4913-a134-03a19c37e7a7-image.png 7/29/2019 6:00
      7/29/2019 6:15
      7/29/2019 6:30
      7/29/2019 6:45
      7/29/2019 7:00
      7/29/2019 7:15
      7/29/2019 7:30
      7/29/2019 7:45
      7/29/2019 8:00
      7/29/2019 8:15

      i.e I get a price every 15 minutes.
      This is stored in Pandas Dataframe.

      When I load it,

      data = bt.feeds.PandasData(...., timeframe=bt.TimeFrame.Minutes, compression = 1)

      Compression should be = 1 or 15?

      posted in General Code/Help
      C
      chaT123
    • Plot Data Series (Not Indicators) with Name.

      When plotting results, how can I add label name to each data series in self.datas[]? Now when I plot, on the upper left of each data series, it shows no name.

      I tried to set the name using self.datas[0].plotinfo(), but I cannot find how to add the name.

      posted in General Code/Help
      C
      chaT123
    • RE: Plot Backtesting Results in Multiple Graphs

      Thank you very much. Just to check, where should I use the plotinfo.plot = False? In the "def init(self):" inside the Strategy Class?

      posted in General Code/Help
      C
      chaT123
    • RE: Loading one data series and run cerebro.run(runonce=False) Got Error Message

      I juse tested self.broker.getvalue() is working.

      But self.stats.broker.value[0] not working. So I can just use self.broker.getvalue() right? My goal is to print out broker value every day.

      posted in General Code/Help
      C
      chaT123
    • Loading one data series and run cerebro.run(runonce=False) Got Error Message

      The below code has error message below when I load only one series of OHLC data (In Pandas DataFrame format). But it doesnt have problem when I add a second series of data. i.e with two data series it works.

      And when I use "runonce=True" setting, it works also.

      So it ONLY doesn't work when I load only one series of data and use "runonce=False" set up. Does anyone know what is wrong here?

      "C:\ProgramData\Anaconda3\lib\site-packages\backtrader\linebuffer.py", line 163, in getitem
      return self.array[self.idx + ago]
      IndexError: array index out of range

      class TestStrategy(bt.Strategy):
           def __init__(self):
      
              self.closePx = self.datas[0].close
             
              
      
          def next(self):
      
             # The LINE BELOW POP UP ERROR MSG ABOVE
              print(self.stats.broker.value[0])
             
              # ***************************************************************
      
          def stop(self):
              pass
      
      data = bt.feeds.PandasData(dataname=dailyOHLCDF, open='Open', high='High', low='Low', close = 'Close', volume = 'Volume'\
      , openinterest=None)
      
      
      cerebro = bt.Cerebro(stdstats=False)
      
      cerebro.adddata(data)
      cerebro.addobserver(bt.observers.Broker, plot = False)
      cerebro.broker.setcash(500000.0)
      cerebro.addstrategy(TestStrategy)
      thestrats = cerebro.run(runonce=False)
      posted in General Code/Help
      C
      chaT123
    • Plot Backtesting Results in Multiple Graphs

      How can I plot broker.value in one graph object while rest backtesting results in a separate graph object? Plotting everything together in one graph makes the details very small to see.

      posted in General Code/Help
      C
      chaT123
    • RE: How to code and track stop loss orders

      @ab_trader Thank you! Can I have an example code of an observer that output whether each trade is closed by stop loss order or market order (based on other rules)?

      posted in General Code/Help
      C
      chaT123
    • RE: How to add an indicator showing whether previous trade made money or lost money

      i.e to code the logic "buy if MA(20) > MA(40) AND last trade made money." in "def next(self):", can I use analyzer? Or best way is dasch's way above?

      posted in Indicators/Strategies/Analyzers
      C
      chaT123
    • RE: Fundamental Data

      Thank you. The fundamental data is in pandas dataframe format.
      Yes, adding a line and use it through method data.pe is what I need.
      What if I already have dataframe as hand, instead of a CSV file?

      posted in Indicators/Strategies/Analyzers
      C
      chaT123
    • RE: How to code and track stop loss orders

      I'm thinking maybe I create a dataframe X with date index equal to the security price input. And in the log function, I input the stop loss order information into columns of X[0]. Then at the end, I output the dataframe as a csv file. Is this supported?

      posted in General Code/Help
      C
      chaT123
    • RE: How to add an indicator showing whether previous trade made money or lost money

      Thank you all! Will I be able to use analyzer's value to determinate the next trade? I.e I buy if MA(20) > MA(40) AND last trade made money. How to code this with a analyzer showing if last trade made money?

      posted in Indicators/Strategies/Analyzers
      C
      chaT123
    • RE: How to code and track stop loss orders

      also how can I output the order notification to a csv file instead of command line output?

      posted in General Code/Help
      C
      chaT123
    • RE: How to code and track stop loss orders

      Thank you! So there is no way to record my order submit and execution history (e.g notify_order method) in a csv file? Also in WriterFile csv file, I want to specify which closing trade is based on stop loss order and which closing trade is based on other trading rules. e.g I want to add a column in the WriterFile csv file showing "S" if the closing trade is from stop loss order and "O" if closing trade is from other trading rules.

      posted in General Code/Help
      C
      chaT123
    • Fundamental Data

      I have fundamental data (say stock P/E time series) saved as a dataframe. How should I input and use it in backtrader? I load the dataframe using bt.feeds.PandasData and put "close" = "PE?

      posted in Indicators/Strategies/Analyzers
      C
      chaT123
    • How to code and track stop loss orders

      Can I have an example of when I should code in stop loss order?
      The best practice is I submit a stop loss order at the same time I submit the order to open a position?
      Also how can I track what are the stop loss order outstanding (size, and limit price) every day in the WriterFile csv file?

      posted in General Code/Help
      C
      chaT123
    • How to add an indicator showing whether previous trade made money or lost money

      Using the moving average cross over system. But I want to add another criteria that I only buy when the previous trade made money.
      I.e I buy if MA(20) > MA(40) AND last trade made money.
      How do I implement that indicator showing whether previous trade made money or not?

      posted in Indicators/Strategies/Analyzers
      C
      chaT123
    • 1 / 1