Navigation

    Backtrader Community

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    1. Home
    2. Ivan
    For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See: http://commonmark.org/help/
    I
    • Profile
    • Following 0
    • Followers 0
    • Topics 6
    • Posts 18
    • Best 0
    • Groups 0

    Ivan

    @Ivan

    0
    Reputation
    785
    Profile views
    18
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    Ivan Unfollow Follow

    Latest posts made by Ivan

    • RE: Different results with MT4 for the same data

      Thanks @backtrader ! I will provide the code samples and history data as soon as I find a time.

      posted in General Code/Help
      I
      Ivan
    • Different results with MT4 for the same data

      Hi,
      I exported the history data from my MT4 application and used them as data input for backtader.

      My test strategy is trivial: Buy/Sell when two MAs cross over. The same simple algorithm is implemented in backtrader and MT4 and applied to the same data.

      The results which I get using MT4 and backtrader are not same: sometimes the buy/sell operation is executed in the same time on both platforms but sometimes not (more often).

      Does anybody have similar experience? What could be the reason?

      Thanks!

      posted in General Code/Help
      I
      Ivan
    • RE: Oanda test

      @backtrader

      python oandatest.py --token XXX --account XXX --data0 EUR_USD --timeframe Days


      Strategy Created

      Datetime, Open, High, Low, Close, Volume, OpenInterest, SMA
      Traceback (most recent call last):
      File "oandatest.py", line 481, in <module>
      runstrategy()
      File "oandatest.py", line 297, in runstrategy
      cerebro.run(exactbars=args.exactbars)
      File "D:\Anaconda3\envs\python3.4.5\lib\site-packages\backtrader\cerebro.py",
      line 810, in run
      runstrat = self.runstrategies(iterstrat)
      File "D:\Anaconda3\envs\python3.4.5\lib\site-packages\backtrader\cerebro.py",
      line 940, in runstrategies
      self._runnext(runstrats)
      File "D:\Anaconda3\envs\python3.4.5\lib\site-packages\backtrader\cerebro.py",
      line 1153, in _runnext
      newqcheck = not any(d.haslivedata() for d in datas)
      File "D:\Anaconda3\envs\python3.4.5\lib\site-packages\backtrader\cerebro.py",
      line 1153, in <genexpr>
      newqcheck = not any(d.haslivedata() for d in datas)
      File "D:\Anaconda3\envs\python3.4.5\lib\site-packages\backtrader\feeds\oanda.p
      y", line 255, in haslivedata
      return bool(self._storedmsg or self.qlive) # do not return the objs
      File "D:\Anaconda3\envs\python3.4.5\lib\site-packages\backtrader\lineseries.py
      ", line 429, in getattr
      return getattr(self.lines, name)
      AttributeError: 'Lines_LineSeries_DataSeries_OHLC_OHLCDateTime_Abst' object has
      no attribute '_storedmsg'

      posted in General Code/Help
      I
      Ivan
    • Oanda test

      Hi,
      when I run oandatest.py with minimum parameters (only token, account and data0) I get this error:

      Traceback (most recent call last):
      File "oandatest.py", line 481, in <module>
      runstrategy()
      File "oandatest.py", line 202, in runstrategy
      timeframe = bt.TimeFrame.TFrame(args.timeframe)
      File "D:\Anaconda3\envs\python3.4.5\lib\site-packages\backtrader\dataseries.py
      ", line 53, in TFrame
      return getattr(cls, name)
      AttributeError: type object 'TimeFrame' has no attribute ''

      Any help? Thanks!

      posted in General Code/Help
      I
      Ivan
    • Problem with resampling of intraday data

      I am using 1min data for EURUSD, from the csv file. Data are read correctly and plotted fine.
      Ia m also resampling these data to daily timeframe but something doesn't work correctly. I am getting peculiar chart for daily data.

      0_1485528401703_1min_resample.png

      In next() function I print this:

      txt = ','.join(
                  [self.data.datetime.date(0).isoformat() +" "
                   + self.data.datetime.time(0).isoformat()+", 1min data (OHLC): "
                  '%.5f' % self.data.open[0]+", "
                  '%.5f' % self.data.high[0]+", "
                  '%.5f' % self.data.low[0]+", "
                  '%.5f' % self.data.close[0]+", Daily data (OHLC):"
                  '%.5f' % self.data1.open[0]+", "
                  '%.5f' % self.data1.high[0]+", "
                  '%.5f' % self.data1.low[0]+", "
                  '%.5f' % self.data1.close[0]
                  ])
      
      print(txt)
      

      The excerpt of the output:

      2016-01-04 15:53:00, 1min data (OHLC): 1.08115, 1.08151, 1.08112, 1.08147, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 15:54:00, 1min data (OHLC): 1.08146, 1.08151, 1.08122, 1.08128, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 15:55:00, 1min data (OHLC): 1.08128, 1.08133, 1.08113, 1.08131, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 15:56:00, 1min data (OHLC): 1.08135, 1.08146, 1.08104, 1.08118, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 15:57:00, 1min data (OHLC): 1.08117, 1.08148, 1.08079, 1.08083, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 15:58:00, 1min data (OHLC): 1.08082, 1.08083, 1.08037, 1.08048, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 15:59:00, 1min data (OHLC): 1.08048, 1.08054, 1.08012, 1.08015, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:00:00, 1min data (OHLC): 1.08016, 1.08046, 1.08016, 1.08046, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:01:00, 1min data (OHLC): 1.08045, 1.08048, 1.08021, 1.08037, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:02:00, 1min data (OHLC): 1.08039, 1.08099, 1.08037, 1.08097, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:03:00, 1min data (OHLC): 1.08098, 1.08123, 1.08064, 1.08076, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:04:00, 1min data (OHLC): 1.08076, 1.08093, 1.08064, 1.08085, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:05:00, 1min data (OHLC): 1.08085, 1.08102, 1.08021, 1.08022, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:06:00, 1min data (OHLC): 1.08016, 1.08062, 1.08016, 1.08062, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:07:00, 1min data (OHLC): 1.08060, 1.08060, 1.08011, 1.08032, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:08:00, 1min data (OHLC): 1.08031, 1.08047, 1.07985, 1.08000, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:09:00, 1min data (OHLC): 1.08000, 1.08059, 1.07998, 1.08050, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:10:00, 1min data (OHLC): 1.08050, 1.08051, 1.07998, 1.08007, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:11:00, 1min data (OHLC): 1.08008, 1.08013, 1.08000, 1.08002, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:12:00, 1min data (OHLC): 1.08006, 1.08009, 1.07992, 1.08003, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:13:00, 1min data (OHLC): 1.08003, 1.08005, 1.07873, 1.07884, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:14:00, 1min data (OHLC): 1.07885, 1.07912, 1.07846, 1.07855, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:15:00, 1min data (OHLC): 1.07855, 1.07871, 1.07841, 1.07854, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:16:00, 1min data (OHLC): 1.07853, 1.07886, 1.07847, 1.07852, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:17:00, 1min data (OHLC): 1.07852, 1.07879, 1.07850, 1.07861, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:18:00, 1min data (OHLC): 1.07861, 1.07865, 1.07835, 1.07846, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:19:00, 1min data (OHLC): 1.07848, 1.07860, 1.07824, 1.07836, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:20:00, 1min data (OHLC): 1.07836, 1.07857, 1.07826, 1.07848, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:21:00, 1min data (OHLC): 1.07848, 1.07868, 1.07840, 1.07860, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:22:00, 1min data (OHLC): 1.07862, 1.07866, 1.07820, 1.07820, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:23:00, 1min data (OHLC): 1.07821, 1.07841, 1.07816, 1.07818, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:24:00, 1min data (OHLC): 1.07818, 1.07829, 1.07812, 1.07818, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      2016-01-04 16:25:00, 1min data (OHLC): 1.07818, 1.07853, 1.07815, 1.07848, Daily data (OHLC):1.08718, 1.08727, 1.08451, 1.08516
      

      Resampling of 1min data is done with this command:

      cerebro.resampledata(data, timeframe=bt.TimeFrame.Days)
      

      What could be the problem here?

      posted in General Code/Help
      I
      Ivan
    • RE: Pivot Point and Cross Plotting - plotting doesn't work

      Actually, weekly indicator value is correct but the presentation on the graph is wrong.

      posted in General Code/Help
      I
      Ivan
    • RE: Pivot Point and Cross Plotting - plotting doesn't work

      The code is not perfect but you can reproduce the issue with it:

      from __future__ import (absolute_import, division, print_function,
                              unicode_literals)
      
      from datetime import datetime
      import os.path 
      import sys 
      
      import backtrader as bt
      
      class TestIndicator(bt.Indicator):
       
          lines = ('h', 'l')
          plotinfo = dict(subplot=False)
          
          params = (
              ('is_bars_aggregated', True),
              ('_autoplot', False),  # attempt to plot on real target data
          )
          
          
          def _plotinit(self):
              # Try to plot to the actual timeframe master
              if self.p._autoplot:
                  if hasattr(self.data, 'data'):
                      self.plotinfo.plotmaster = self.data.data
      
          def __init__(self):
              
                    
              if self.p.is_bars_aggregated:
                  high = self.data.high
                  low = self.data.low
              else:
                  high = self.data.high(-1)
                  low = self.data.low(-1)            
              
              self.lines.h=high                
              self.lines.l=low
                      
              if self.p._autoplot:
                  self.plotinfo.plot = False  # disable own plotting
                  self()  # Coupler to follow real object
      
      
              
      class TestStrategy(bt.Strategy):
          
              
          def __init__(self):
              
              self.TIDaily = TestIndicator(self.data0, is_bars_aggregated=False, plot=False)
              self.TIWeekly = TestIndicator(self.data1, is_bars_aggregated=True, _autoplot=True, plot=False)
              self.TIMonthly = TestIndicator(self.data2, is_bars_aggregated=True, _autoplot=False, plot=False)
              
               
      
          def notify_order(self, order):
              pass
              
      
          def notify_trade(self, trade):
              pass
      
          def next(self):
              pass
              
        
      
      if __name__ == '__main__':      
              
           
          # Create a cerebro entity
          cerebro = bt.Cerebro()
      
          # Add a strategy
          cerebro.addstrategy(TestStrategy)   
      
          data = bt.feeds.YahooFinanceData(dataname='^GSPC', fromdate=datetime(2016, 11, 1), todate=datetime(2016, 11, 30))
          
          data2=data.clone()
          data2.plotinfo.plot=False
          data3=data.clone()
          data3.plotinfo.plot=False
          
          cerebro.adddata(data)
          cerebro.resampledata(data2, timeframe=bt.TimeFrame.Weeks)    
          cerebro.resampledata(data3, timeframe=bt.TimeFrame.Months)
        
          cerebro.broker.setcash(10000.0)
      
          # Add a FixedSize sizer according to the stake
          cerebro.addsizer(bt.sizers.FixedSize, stake=1)
          # Set the commission        
          cerebro.broker.setcommission(commission=0.000)
          #cerebro.broker.setcommission(commission=7.0, margin=1000.0, mult=10.0)
      
          # Print out the starting conditions
          print('Starting Portfolio Value: %.2f' % cerebro.broker.getvalue())
      
          # Run over everything
          cerebro.run()
      
          # Print out the final result
          print('Final Portfolio Value: %.2f' % cerebro.broker.getvalue())
      
          # Plot the result
          cerebro.plot(style='candle')
      
      posted in General Code/Help
      I
      Ivan
    • RE: Pivot Point and Cross Plotting - plotting doesn't work

      It can't be simpler :) Just calculate Low of the previous bar in an indicator for weekly or monthly data and show the indicator on daily data. That it what I showed for SP500, Low and High (blue and red line).

      posted in General Code/Help
      I
      Ivan
    • RE: Pivot Point and Cross Plotting - plotting doesn't work

      Ok, I put here what I got and what I think I should get. This example uses simple indicator which calculates high and low of the previous bar. Each bar on chart represents one trading day and the indicator is calculated for weekly data and plot on daily chart.
      Weekly indicator should have the same value for the week November 7-11 but instead of that the same value is from November 8-14. I hope I managed to explain where is the problem.

      0_1485368085338_GSPC_Daily_BT.png

      0_1485368105181_GSPC_Daily_BT_expected.png

      posted in General Code/Help
      I
      Ivan
    • RE: Pivot Point and Cross Plotting - plotting doesn't work

      This seems to be a bug or I don't understand something :(
      I created an indicator similar to PivotPoint which uses the values from previous bar for the calculation.
      My original data are daily data but I also resample to weekly and monthly.
      When I plot my indicators on daily chart everything is fine for the indicator that works on daily data.
      For the indicators that use resampled data (weekly&monthly), values seem not to be ok. For example, for weekly indicator, its value is changed each Tuesday, not Monday. Similar for monthly indicator, it changes its value not on the first trading day in the month but on the day after.
      I am using last version of Backtrader.

      posted in General Code/Help
      I
      Ivan