Backtrader Community

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

    SVetter

    @SVetter

    3
    Reputation
    9
    Profile views
    4
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    SVetter Unfollow Follow

    Best posts made by SVetter

    • Create Indicator Line from DataFrame (not from data in Cerebros)

      Hi everyone,
      I have tried finding an answer to this in the community, but never found the exact solution unfortunately. I have seen and understood that backtrader does not intend to rely on any other modules / libraries and I fully understand that decision.

      I am however struggling with the thought of having to port all indicators that are already out there using Pandas and wanted to work around that by (a) using PandasData to feed Cerebros (works perfectly fine, great job!) and (b) by using the same dataframe that is fed to Cerebros in "runstrat" to perform calculations from existing indicators using pandas.

      I have therefore made the dataframe a global variable to be accessed in "runstrat" as well as in my indicator class.

      # Get a pandas dataframe
      datapath = ('pandas-data.txt')
      # Simulate the header row isn't there if noheaders requested
      skiprows = 1 if _ARGS.noheaders else 0
      header = None if _ARGS.noheaders else 0
      
      _DATAFRAME = pandas.read_csv(datapath,
                                  skiprows=skiprows,
                                  header=header,
                                  parse_dates=True,
                                  index_col=0)
      

      feeding Cerebros:

      data = bt.feeds.PandasData(dataname=_DATAFRAME)
      

      and pulling it into the indicator:

      df = _DATAFRAME
      
      # Existing indicator logic using "df" 
      df['H-L']=abs(df['High']-df['Low'])
      df['H-PC']=abs(df['High']-df['Close'].shift(1))
      ...
      

      However at the end of the calculation using Pandas, I end up needing to assign the result (which is a column in the Pandas dataframe, so a "Series" (?) ) to my "self.lines.custom_indicator" if I am not mistaken?

      Is there a way to transfor this particular column into the line that I want the indicator to spit out? The functions in "backtrader" (e.g. bt.All()) were not documented and I'm not quite sure if I may have missed a very easy way to do this?

      Let me know if you need more code examples. I'm really excited to use this library and would assume someone else has had this issue / question?

      Thanks!

      (I have tried porting some of the more complicated indicators, buut would really save a lot of time if I could fall back onto the existing Pandas implementations)

      posted in General Code/Help
      SVetter
      SVetter
    • RE: Create Indicator Line from DataFrame (not from data in Cerebros)

      thanks for the feedback. very helpful!

      posted in General Code/Help
      SVetter
      SVetter

    Latest posts made by SVetter

    • RE: Create Indicator Line from DataFrame (not from data in Cerebros)

      thanks for the feedback. very helpful!

      posted in General Code/Help
      SVetter
      SVetter
    • What really makes a good trader?

      I just stumbled across this project this week and am really excited to put it to use in my scanners / backtesting. As a more generic question for the community here: do you all use this to work on live trading strategies? (or maybe more as a programming hobby?)

      I have so far only been trading manually, as well as reviewing all my charts manually. Has programming these tasks really given you a whole new edge in the live trading? What do you think makes a great trader once we are using tools like this fine Cerebro? :)

      Best,
      S

      posted in General Discussion
      SVetter
      SVetter
    • RE: How to get each line name in the indicator

      @ezfine
      Not sure why you would need that? Can you maybe give some more context? Given that you have created the lines mav1-mav2 (and given they are not generated dnyamically), why do you need to iterate instead of addressing them individually?

      posted in General Discussion
      SVetter
      SVetter
    • Create Indicator Line from DataFrame (not from data in Cerebros)

      Hi everyone,
      I have tried finding an answer to this in the community, but never found the exact solution unfortunately. I have seen and understood that backtrader does not intend to rely on any other modules / libraries and I fully understand that decision.

      I am however struggling with the thought of having to port all indicators that are already out there using Pandas and wanted to work around that by (a) using PandasData to feed Cerebros (works perfectly fine, great job!) and (b) by using the same dataframe that is fed to Cerebros in "runstrat" to perform calculations from existing indicators using pandas.

      I have therefore made the dataframe a global variable to be accessed in "runstrat" as well as in my indicator class.

      # Get a pandas dataframe
      datapath = ('pandas-data.txt')
      # Simulate the header row isn't there if noheaders requested
      skiprows = 1 if _ARGS.noheaders else 0
      header = None if _ARGS.noheaders else 0
      
      _DATAFRAME = pandas.read_csv(datapath,
                                  skiprows=skiprows,
                                  header=header,
                                  parse_dates=True,
                                  index_col=0)
      

      feeding Cerebros:

      data = bt.feeds.PandasData(dataname=_DATAFRAME)
      

      and pulling it into the indicator:

      df = _DATAFRAME
      
      # Existing indicator logic using "df" 
      df['H-L']=abs(df['High']-df['Low'])
      df['H-PC']=abs(df['High']-df['Close'].shift(1))
      ...
      

      However at the end of the calculation using Pandas, I end up needing to assign the result (which is a column in the Pandas dataframe, so a "Series" (?) ) to my "self.lines.custom_indicator" if I am not mistaken?

      Is there a way to transfor this particular column into the line that I want the indicator to spit out? The functions in "backtrader" (e.g. bt.All()) were not documented and I'm not quite sure if I may have missed a very easy way to do this?

      Let me know if you need more code examples. I'm really excited to use this library and would assume someone else has had this issue / question?

      Thanks!

      (I have tried porting some of the more complicated indicators, buut would really save a lot of time if I could fall back onto the existing Pandas implementations)

      posted in General Code/Help
      SVetter
      SVetter