Navigation

    Backtrader Community

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

    holicst

    @holicst

    1
    Reputation
    902
    Profile views
    23
    Posts
    1
    Followers
    2
    Following
    Joined Last Online

    holicst Unfollow Follow

    Best posts made by holicst

    • RE: Implementation of OpenAI Gym environment for Backtrader

      Hi,

      This is a wonderful development. I also had this on my to-do list for the coming months... Congrats for this and I wish you all the best to make it a successful project!

      Cheers,
      Tamás

      posted in General Discussion
      H
      holicst

    Latest posts made by holicst

    • RE: Implementation of OpenAI Gym environment for Backtrader

      Hi,

      This is a wonderful development. I also had this on my to-do list for the coming months... Congrats for this and I wish you all the best to make it a successful project!

      Cheers,
      Tamás

      posted in General Discussion
      H
      holicst
    • Handling CTRL-C when trading live

      Hi Everybody, dear @backtrader,

      I’d like to handle CTRL-C (SIGINT) when trading Live. In this case I’d like to trigger method runstop(), and in the stop() method I want to save the statistics of my trading to a DB. I googled this and added the recommended code:

          def next(self, frompre=False):
      
              try:
      		...business logic here...
              except KeyboardInterrupt:
                  self.log('CTRL-C detected - stopping')
                  self.stopped=True
                  self.env.runstop()
                  return
      

      However, this does not work apparently:

      2017-05-16T12:27:15,
      2017-05-16T12:27:20,
      2017-05-16T12:27:25, Portfolio value: 99776.2408, cash: 97511.7685
      2017-05-16T12:27:25, Position: USD_CZK, size: 4093.0000, price: 23.8976, value: 97812.9177
      2017-05-16T12:27:25, Position: USD_MXN, size: 10487.0000, price: 18.7057, value: 196167.0954
      2017-05-16T12:27:25, Position: GBP_ZAR, size: 5780.0000, price: 16.9514, value: 97978.9764
      2017-05-16T12:27:25, Position: EUR_TRY, size: 24923.0000, price: 3.9304, value: 97956.6115
      forrtl: error (200): program aborting due to control-C event
      Image              PC                Routine            Line        Source
      libifcoremd.dll    00007FFDA97643E4  Unknown               Unknown  Unknown
      KERNELBASE.dll     00007FFDD2EE717D  Unknown               Unknown  Unknown
      KERNEL32.DLL       00007FFDD5DB2774  Unknown               Unknown  Unknown
      ntdll.dll          00007FFDD5FC0D61  Unknown               Unknown  Unknown
      

      How can I achieve the goal to be able to stop a live trading and in that moment save everything to the DB?

      Thanks and best regards,
      Tamás

      posted in General Code/Help
      H
      holicst
    • optstrategy() and plotting

      Hi Everybody, dear @backtrader,

      When I try to use optstrategy() with a Pandas data source, I cannot plot my results to png files. As I understand, this should be possible, according to the documentation:

      Cerebro.plot()
      savefig: set to True to save to a file rather than plot
      figfilename: name of the file. Use {j} in the name for the strategy index to which the figure corresponds and use `{i}`` to insert figure number if multiple figures are being used per strategy plot

      I'd like to plot my results after each run has finished.

      This is my code:

                 if g_save_plot==True:
                     plot_file_path = log_file_path.replace('.txt','_{j}_{i}.png')
                     cerebro.plot(savefig=True, figfilename=plot_file_path) #numfigs=len(g_instruments), 
                     cerebro.plot()
      

      However, when I call this, I get an error:

      Traceback (most recent call last):
       File "C:\Baixinho\train_keras_model.py", line 962, in <module>
         cancelled = bt_backtest.backtest(g_data_source, g_backtest_mode, g_resolution, loaded_training_df, training_fold_ranges_df, model, g_db, test_df, g_log_file_path)                
       File "C:\Baixinho\simulate_backtrader.py", line 995, in backtest
         cerebro.plot(savefig=True, figfilename=plot_file_path) #numfigs=len(g_instruments), 
       File "C:\Users\peter\Anaconda3\lib\site-packages\backtrader\cerebro.py", line 927, in plot
         start=start, end=end)
       File "C:\Users\peter\Anaconda3\lib\site-packages\backtrader\plot\plot.py", line 119, in plot
         if not strategy.datas:
      AttributeError: 'OptReturn' object has no attribute 'datas'
      

      And this is line 119 and 120 in plot.py (I've just upgraded backtrader to the latest version):

             if not strategy.datas:
                 return
      

      I don’t really get why “strategy” is an OptReturn object, but I’m not a Python expert.

      Do I misunderstand the usage of cerebro.plot() when optimizing strategies?

      Alternatively, it would be great to be able to save the plots separately, when a strategy finished (method stop()). Is that possible?

      Cheers,
      Tamás

      posted in General Code/Help
      H
      holicst
    • RE: Extreme spreads with Oanda - how to manage this?

      Hi @backtrader,

      Is it possible to get bid/ask lines in an Oanda datasource, similarly to what you've described in your "Escape from OHLC land" post? That would also solve the spread problem because that way calculating the spread would be super easy.
      As I can see there is an option ("bidask") that controls what is retrieved from Oanda, so I believe it is already partially implemented.

      Would it be possible to add the bid/ask lines to the data if the timeframe is set to bt.TimeFrame.Ticks?

      Cheers,
      Tamás

      posted in General Code/Help
      H
      holicst
    • RE: Extreme spreads with Oanda - how to manage this?

      @ThatBlokeDave
      Hi,

      Thanks for the tips. Probably number 2 would be the best. I wonder if it is interesting for @backtrader to include that in one of the future versions. Like to have self.datas[0].current_spread or something like that ;)

      Number 3 is also a good way to go but then I'll need to check the historical spreads for all the instruments and of course I need to sync the timezones.

      Thanks again and cheers,
      Tamás

      posted in General Code/Help
      H
      holicst
    • Extreme spreads with Oanda - how to manage this?

      Hi,

      I'm testing with my Oanda practice account and found some huge differences between the current price (1-minute timeframe) and the price on which I could buy/sell. Then I checked the historical spreads on the Oanda website and found that the spread is extremely high every day around 23:00. Actually that was the time when my strategy has lost a lot of money (21:00 local time). Other periods were fine, buy and sell prices were very close to the actual price.

      How can we avoid trading when the spread is so high? Is it possible to get the current spread of an instrument somehow?

      3_1494502268172_Market_order_4.jpg 2_1494502268172_Market_order_3.jpg 1_1494502268172_Market_order_2.jpg 0_1494502268172_Market_order_1.jpg

      Cheers,
      Tamás

      posted in General Code/Help
      H
      holicst
    • RE: How to correctly trade on data1 and data2?

      @asuralm Hi,

      I tried to reproduce your impressive results with Forex, but I had no luck. May I ask what your datas are, what are you trading?

      Cheers,
      Tamás

      posted in General Code/Help
      H
      holicst
    • RE: Oanda test

      @backtrader Hi,

      This is great. I'll try to figure out what the problem is today.

      Cheers,
      Tamás

      posted in General Code/Help
      H
      holicst
    • RE: Oanda test

      Hi,

      Thanks for the quick answers. I've adjusted the programs and the _name stuff is solved.

      Do you maybe have plans to tune the performance for subscribing to 100 instruments? Or should I try to take care of it and feed my data to my strategy?

      Cheers,
      Tamás

      posted in General Code/Help
      H
      holicst
    • RE: Oanda test

      Hi,

      Sorry, I don't want to spam this topic but I encountered another error:

      Exception in thread Thread-60:
      Traceback (most recent call last):
        File "C:\Users\peter\Anaconda3\lib\threading.py", line 914, in _bootstrap_inner
          self.run()
        File "C:\Users\peter\Anaconda3\lib\threading.py", line 862, in run
          self._target(*self._args, **self._kwargs)
        File "C:\Users\peter\Anaconda3\lib\site-packages\backtrader\stores\oandastore.py", line 379, in _t_candles
          **dtkwargs)
        File "C:\Users\peter\Anaconda3\lib\site-packages\oandapy\oandapy.py", line 38, in get_history
          return self.request(endpoint, params=params)
        File "C:\Users\peter\Anaconda3\lib\site-packages\backtrader\stores\oandastore.py", line 89, in request****
          content = json.loads(content)
        File "C:\Users\peter\Anaconda3\lib\json\__init__.py", line 319, in loads
          return _default_decoder.decode(s)
        File "C:\Users\peter\Anaconda3\lib\json\decoder.py", line 339, in decode
          obj, end = self.raw_decode(s, idx=_w(s, 0).end())
        File "C:\Users\peter\Anaconda3\lib\json\decoder.py", line 357, in raw_decode
          raise JSONDecodeError("Expecting value", s, err.value) from None
      json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
      
      

      I subscribed for all 70 forex instruments Oanda offers, could this be a problem?

      Best regards,
      Tamás

      posted in General Code/Help
      H
      holicst