Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. Rodrigo Brito
    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 3
    • Topics 4
    • Posts 14
    • Best 4
    • Groups 0

    Rodrigo Brito

    @Rodrigo Brito

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

    Rodrigo Brito Unfollow Follow

    Best posts made by Rodrigo Brito

    • Example of usage with Bitcoin in Binance

      Hi everyone,

      I published a little contribution in my Github. A example of usage of Backtrader with Binance integration. Using the CCXT lib for broker and feed.

      The base strategy uses a simple RSI + SMA filter, with stop loss of 3%.

      Feel free to contribute and improve the example: https://github.com/rodrigo-brito/backtrader-binance-bot

      Best regards,
      Rodrigo Brito

      posted in General Discussion
      Rodrigo Brito
      Rodrigo Brito
    • RE: Example code for live trading using binance

      Hi @Noah-Bastola,

      I'm using backtrader for bitcoin/usdt trades in production. The easy way is integrate with binance API through CCXT Store lib. A simple example is available below:

      https://gist.github.com/rodrigo-brito/3b0fca2487c92ad97869247edd5fd852

      posted in General Code/Help
      Rodrigo Brito
      Rodrigo Brito
    • RE: Anyone use backtrader to do live trading on Bitcoin exchange?

      Hi everyone.
      About the problem with the position calculation in my simple example. I think it is a problem with bt-ccxt-store. I create a workarround, ignoring the position value and store this value manually inside the Strategy Class. Other customization is the buy() and sell() functions, the sizer does not work very well with binance. When the fee is charged in BNB, it does not include the wallet value. I'm using this class to create custom buy and sell operations. For now, I'm using backtrader to get the historical information and indictators. All other operations I'm doing manually.
      Custom code: https://gist.github.com/rodrigo-brito/8c82020f04e946e3f0c39c7243cfe1ee

      posted in General Discussion
      Rodrigo Brito
      Rodrigo Brito
    • RE: How to draw point on the chart without using indicator?

      It is an interesting feature. Sometimes I want to visualize critical points such as "stop loss".

      posted in General Code/Help
      Rodrigo Brito
      Rodrigo Brito

    Latest posts made by Rodrigo Brito

    • RE: Anyone use backtrader to do live trading on Bitcoin exchange?

      Hi everyone.
      About the problem with the position calculation in my simple example. I think it is a problem with bt-ccxt-store. I create a workarround, ignoring the position value and store this value manually inside the Strategy Class. Other customization is the buy() and sell() functions, the sizer does not work very well with binance. When the fee is charged in BNB, it does not include the wallet value. I'm using this class to create custom buy and sell operations. For now, I'm using backtrader to get the historical information and indictators. All other operations I'm doing manually.
      Custom code: https://gist.github.com/rodrigo-brito/8c82020f04e946e3f0c39c7243cfe1ee

      posted in General Discussion
      Rodrigo Brito
      Rodrigo Brito
    • Money Flow Index (MFI)

      I implemented the MFI for Backtrader, but I think this can be improved:

      #!/usr/bin/env python3
      
      import math
      import backtrader as bt
      
      class MFI(bt.Indicator):
          lines = ('mfi', 'money_flow_raw', 'typical', 'money_flow_pos', 'money_flow_neg')
      
          plotlines = dict(
              money_flow_raw=dict(_plotskip=True),
              money_flow_pos=dict(_plotskip=True),
              money_flow_neg=dict(_plotskip=True),
              typical=dict(_plotskip=True),
          )
      
          params = (
              ('period', 14),
          )
      
          def next(self):
              typical_price = (self.data.close[0] + self.data.low[0] + self.data.high[0]) / 3
              money_flow_raw = typical_price * self.data.volume[0]
              
              self.lines.typical[0] = typical_price
              self.lines.money_flow_raw[0] = money_flow_raw
      
              self.lines.money_flow_pos[0] = money_flow_raw if self.lines.typical[0] >= self.lines.typical[-1] else 0
              self.lines.money_flow_neg[0] = money_flow_raw if self.lines.typical[0] <= self.lines.typical[-1] else 0
      
              pos_period = math.fsum(self.lines.money_flow_pos.get(size=self.p.period))
              neg_period = math.fsum(self.lines.money_flow_neg.get(size=self.p.period))
              
              if neg_period == 0:
                  self.lines.mfi[0] = 100
                  return
      
              self.lines.mfi[0] =  100 - 100 / (1 +  pos_period / neg_period)
      
      

      I used two auxiliary lines to sum negative/positive values when typical_price change. There are some alternative to reduce it and compare two different lines given a period?

      posted in Indicators/Strategies/Analyzers
      Rodrigo Brito
      Rodrigo Brito
    • Standard MACD vs Talib MACD - Different Values

      Talib MACD returns a different value than std MACD with re-sample data.
      A report of @mr-m0nst3r

      Using this example: https://gist.github.com/rodrigo-brito/4f779001647ce1ce7235a7d254b7e75b
      With this dataset: https://github.com/rodrigo-brito/backtrader-binance-bot/blob/master/dataset/binance_nov_18_mar_19_btc.csv

      Without re-sample, it is ok:

      EMA12 = 6960.21 EMA26 = 6949.12 DIFF = 11.09
      STD MACD = 11.09
      TALIB MACD = 11.09
      --------------
      EMA12 = 6961.31 EMA26 = 6950.47 DIFF = 10.84
      STD MACD = 10.84
      TALIB MACD = 10.84
      --------------
      EMA12 = 6961.38 EMA26 = 6951.31 DIFF = 10.08
      STD MACD = 10.08
      TALIB MACD = 10.08
      --------------
      

      But, with a re-sample of 30 minutes, it returns a different value:

      cerebro.resampledata(data, timeframe=bt.TimeFrame.Minutes, compression=30)
      
      --------------
      EMA12 = 7031.31 EMA26 = 7057.54 DIFF = -26.23
      STD MACD = -26.23
      TALIB MACD = -83.05
      --------------
      EMA12 = 7012.22 EMA26 = 7046.41 DIFF = -34.19
      STD MACD = -34.19
      TALIB MACD = -90.54
      --------------
      EMA12 = 7004.46 EMA26 = 7040.14 DIFF = -35.68
      STD MACD = -35.68
      TALIB MACD = -88.64
      --------------
      

      The graphic result is also different:

      alt text

      posted in General Discussion
      Rodrigo Brito
      Rodrigo Brito
    • RE: Example of usage with Bitcoin in Binance

      Hi @diamonddogs95, I used https://github.com/xFFFFF/Gekko-Datasets to generate a database in SQLite. Then I open it and run this query https://github.com/rodrigo-brito/backtrader-binance-bot/blob/master/dataset/queries.sql

      posted in General Discussion
      Rodrigo Brito
      Rodrigo Brito
    • RE: Anyone use backtrader to do live trading on Bitcoin exchange?

      Hi, @pfederra

      1. I have the same issue in notify_order(), it works only in simulations to me.
      2. I think the fork has a lot of issues, but work very well for the main features, like order and feed.
      3. The get positions does not work for me very well, it has a precision issue. I'm using a function to get my wallet ballance and settting a custom sizer. I'm also defining a global variable with the last operation (BUY/SELL) to control the next operation. It is a working arrond, but working in live.
      posted in General Discussion
      Rodrigo Brito
      Rodrigo Brito
    • RE: Anyone use backtrader to do live trading on Bitcoin exchange?

      @coolernax I don't persist the feed or strategies positions. The feed loads a delayed history when started. About the trade position, I'm start always with no funds in crypto, the first operation should be a buy. Maybe it can be improved with a simple flag in the script.

      posted in General Discussion
      Rodrigo Brito
      Rodrigo Brito
    • RE: How to draw point on the chart without using indicator?

      It is an interesting feature. Sometimes I want to visualize critical points such as "stop loss".

      posted in General Code/Help
      Rodrigo Brito
      Rodrigo Brito
    • RE: Anyone use backtrader to do live trading on Bitcoin exchange?

      I published a simple example with Binance integration: https://github.com/rodrigo-brito/backtrader-binance-bot

      posted in General Discussion
      Rodrigo Brito
      Rodrigo Brito
    • Example of usage with Bitcoin in Binance

      Hi everyone,

      I published a little contribution in my Github. A example of usage of Backtrader with Binance integration. Using the CCXT lib for broker and feed.

      The base strategy uses a simple RSI + SMA filter, with stop loss of 3%.

      Feel free to contribute and improve the example: https://github.com/rodrigo-brito/backtrader-binance-bot

      Best regards,
      Rodrigo Brito

      posted in General Discussion
      Rodrigo Brito
      Rodrigo Brito
    • RE: Example code for live trading using binance

      Hi @pfederra. I'm receiving zero values too. I think it is a issue related to bt-ccxt-store.

      posted in General Code/Help
      Rodrigo Brito
      Rodrigo Brito