Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. Noah Bastola
    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 0
    • Groups 0

    Noah Bastola

    @Noah Bastola

    0
    Reputation
    134
    Profile views
    4
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Noah Bastola Unfollow Follow

    Latest posts made by Noah Bastola

    • RE: Example code for live trading using binance

      @rodrigo-brito Actually I was able to load the library, but could you run me through how the code works? I ran the code as given, but it doesn't seem to fetch any data. This is the output I get:

      2019-03-18 17:28:40.131205 - fetch_ohlcv - Attempt 0
      Fetching: BTC/USDT, TF: 5m, Since: 1552944300000, Limit: 99999

      posted in General Code/Help
      Noah Bastola
      Noah Bastola
    • RE: Example code for live trading using binance

      @rodrigo-brito How do I import ccxtbt, as shown in your imports?

      posted in General Code/Help
      Noah Bastola
      Noah Bastola
    • Example code for live trading using binance

      Hi all,

      I was wondering if there was any kind of reference that I could look at to get started with live trading. I use the platform Binance, and I want to feed in downloaded csv data into the backtesting strategy I have made.

      In the code below, I download the most recent 5 minute bar data and feed it into the backtrader. My plan was to re-run the backtrader every 5 minutes with the next set of downloaded data and send orders requests using the Binance API.

      # Add a strategy
      cerebro.addstrategy(TestStrategy)
      df = pd.DataFrame(get_klines('DLTBTC',5))
      df[0]=pd.to_datetime(df[0],unit='ms')
      df.to_csv('data.csv',index=False)
      datapath = os.path.join(os.getcwd() + '/data.csv')#modpath, '../../datas/orcl-1995-2014.txt')
      
      # datapath = os.path.join(os.getcwd() + '/'+path)#'/historicalDLTBTC.csv'#modpath, '../../datas/orcl-1995-2014.txt')
      
      # Create a Data Feed
      data = bt.feeds.GenericCSVData(
          dataname=datapath,
          # Do not pass values before this date
          dtformat = ('%Y-%m-%d %H:%M:%S'),
          datetime = 0,
          high = 2,
          low = 3,
          open=1,
          close=4,
          volume=5,
          openinterest=-1,
          timeframe = bt.TimeFrame.Minutes,
          compression=5,
          )
      

      If this is the best way to go about live trading using binance, how can I retrieve variables from the init portion of the TestStrategy class so that I can keep track of the trades and position?

          # To keep track of pending orders and buy price/commission
          self.order = None
          self.buyprice = None
          self.buycomm = None
          self.loopIteration = 0
          self.buyType = None
          self.inTrade = False
      
      posted in General Code/Help
      Noah Bastola
      Noah Bastola
    • Using EMA on a list of values

      Hi all,

      I think I have a pretty simple question, but I'm having trouble finding examples for what I want in the documentation.

      The code I am trying to mimic in backtrader:

      lrc = list(talib.LINEARREG(df['Close Price'], timeperiod=clen))
      lrs = []
      slrs = []
      for i in range(clen,len(lrc)-1):
          lrs.append(lrc[i+1]-lrc[i])
      lrs = pd.Series(lrs)
      for i in range(1,len(lrs)):
          slrs.append(talib.EMA(lrs[-(20+i):-i], timeperiod=slen).values[-1])
      

      The code I am trying to write:

      def linreg(self):
          lrs = previous lrc - current lrc
          slrs = EMA(lrs,timeperiod=50)
          return(slrs)
      def __init__(self):
          # Keep a reference to the "close" line in the data[0] dataseries
          self.dataclose = self.datas[0].close
          self.datahigh = self.datas[0].high
          self.datalow = self.datas[0].low
          # To keep track of pending orders and buy price/commission
          self.order = None
          self.buyprice = None
          self.buycomm = None
      
          # Add a MovingAverageSimple indicator
          self.sma = bt.indicators.SimpleMovingAverage(
              self.datas[0], period=self.params.maperiod)
          # Add Linear Regression indicator
          self.lrc = bt.talib.LINEARREG(self.data,timeperiod=59)
      

      What I want to do:
      I want to create a list of new values by subtracting the current lrc value from the previous bar's lrc value. Then, I want to take the EMA of this new list of values and store in slrs.

      Visual examples:
      closePrices = [1,2,3,4,5,6,7,8,9......]
      lrc = [ema with a rolling window ]
      lrs = [rolling subtraction of lrc[0]-lrc[1]]
      slrs = [ema of lrs with a rolling window ]

      Please let me know if I need to clarify anything! Thanks!

      posted in General Code/Help
      Noah Bastola
      Noah Bastola