Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. Noman Akhtar
    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 1
    • Topics 1
    • Posts 2
    • Best 0
    • Groups 0

    Noman Akhtar

    @Noman Akhtar

    0
    Reputation
    4
    Profile views
    2
    Posts
    1
    Followers
    0
    Following
    Joined Last Online

    Noman Akhtar Unfollow Follow

    Latest posts made by Noman Akhtar

    • RE: Passing historical trades to strategy

      @vladisld aah thanks so much. Let me try it out. Just to clarify (and I should have mentioned this previously) by historical trades, I meant the market trades and not just my trades. So, the 2 dataframes will have different time indexing. One way, is that i group the trades by ohlcv time intervals so they have the same time indexing as ohlcv data and json dump all the trades for the particular time intervals as another column into ohlcv but it will be nice to have the flexibility to pass two dataframe containing different information independent of each others time indexing if that makes sense

      posted in Indicators/Strategies/Analyzers
      Noman Akhtar
      Noman Akhtar
    • Passing historical trades to strategy

      Hi,

      New to backtrader so still in the process of learning. I want to pass historical trades as a separate dataframe to my strategy along with ohlcv dataframe. Could you link me to an article that describes how I may be able to do that and then reference the columns in the strategy class?

      I do,

          data = bt.feeds.PandasData(dataname=trades)
          # trades is a pandas dataframe with ['timestamp', 'side', 'price', 'amount'] as the columns.
          cerebro.adddata(data)
      

      My Strategy Class is as follows:

      class StrategyOne(bt.Strategy):
      
          def __init__(self):
              self.dataprice = self.datas[0].price
      
          def log(self, text, datetime=None):
              datetime = datetime or self.datas[0].datetime(0)
              print('{}, {}'.format(datetime, text))
      
          def next(self):
              self.log('{} Close: {}'.format(len(self), self.dataprice[0]))
      

      When I run the strategy, it says
      AttributeError: 'Lines_LineSeries_DataSeries_OHLC_OHLCDateTime_Abst' object has no attribute 'price'

      What would be the correct way to approach this?

      Many thanks

      posted in Indicators/Strategies/Analyzers
      Noman Akhtar
      Noman Akhtar