Navigation

    Backtrader Community

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

    cgi1

    @cgi1

    2
    Reputation
    1081
    Profile views
    26
    Posts
    0
    Followers
    0
    Following
    Joined Last Online

    cgi1 Unfollow Follow

    Best posts made by cgi1

    • Save cerebro data to file for later plotting it on another computer

      Here is how I work in general

      I am working on a strategy which works on a bigger set of indicators and price action / swing trading setups. My approach is, to integrate several trading ideas into one strategy.

      Said that, there are particular branches for each idea. E.g.:

      • master branch holds stable status of strategy
      • feature_x branch holds one newly generated stop-rule
      • feature_y branch holds a new filter for ranging markets

      After developing a new stop-rule / entry / pattern etc I need to backtest it to see if it works for a lot of market data. The normal process here is:

      1. Checkout feature_x
      2. Backtest it on about 140 symbols for 10-17 years
      3. Find bugs / Find market conditions in backtest which I did not concider in before / ...
      4. Adjust it
      5. If not satisfied: Repeat at 1. If satisfied: Merge it into master branch

      So the step of backtesting a huge dataset is done very often. Therefore my interest in having the backtest process done quickly, automated and away from my laptop is very high.

      Due to some resource-consuming custom indicator (Support/Resistance) one backtest runs approx. 90 seconds per symbol. I outsourced the backtesting to a powerful linux server which runs 12 backtests in parallel.

      Problem

      So the problem right now is, that my log entries tell me, at which symbols on which dates the current feature have an impact on (e.g. Your new stop rule triggered on 2008-01-19 on EURUSD=X). But I need a chart to see if the program executes it in a situation which I created it for. So i started to use savefig option (cerebro.plot(style='candlestick', savefig=save_fig, dpi=900, width=32, height=18, numfigs=5)) which has been nicely provided by @xnox, but zooming into it looks like this (even with the provided settings):

      0_1499418575958_f4c26c51-43f4-44fb-b544-9c998699c349-grafik.png

      Proposal

      So my idea is to save all the cerebro data to file (e.g. by a linux server) and load the plotter later (on a normal computer) with the saved data. Do you think this is a reasonable way?

      posted in General Code/Help
      C
      cgi1

    Latest posts made by cgi1

    • Add aditional arguments to an order

      Hi *,

      i am searching for a possibility to add some additional information to a new order. In my particular case it would be nice to add some general information (e.g. distances to other lines; the first SL in a buy_bracket operation or free text information like "This trade has been opened by signal XY")

      In more general: I am searching for a place to store information around a trade opening which can be accessed later on easily within next and holds a reference to the order.

      Thanks and BR!
      cgi1

      posted in General Code/Help
      C
      cgi1
    • RE: Choppiness Index (CHOP)

      Wrote a first version: https://github.com/mementum/backtrader/pull/330

      posted in Indicators/Strategies/Analyzers
      C
      cgi1
    • Choppiness Index (CHOP)

      Has someone worked on the Choppiness Index (CHOP) indicator yet?

      From tradingview:

      The Choppiness Index (CHOP) is an indicator designed to determine if the market is choppy (trading sideways) or not choppy (trading within a trend in either direction).

      Implementing the formula should be not very difficult:

      100 * LOG10( SUM(ATR(1), n) / ( MaxHi(n) - MinLo(n) ) ) / LOG10(n)
      n = User defined period length.
      LOG10(n) = base-10 LOG of n
      ATR(1) = Average True Range (Period of 1)
      SUM(ATR(1), n) = Sum of the Average True Range over past n bars
      MaxHi(n) = The highest high over past n bars

      posted in Indicators/Strategies/Analyzers
      C
      cgi1
    • RE: Wrong value of Indicator in another CustomIndicator

      @backtrader said in Wrong value of Indicator in another CustomIndicator:

      Of course. You can pass any number of data-feed-like objects to indicators. They will be available as self.dataX or the corresponding self.datas[X]

      Nice. For reference:

      self.sr = SR(self.datas[0], self.atr)
      

      Gives

      0_1500206033324_aa7601ee-6719-4a33-a326-8accde974350-grafik.png

      inside custom indicator SR. So it can be used like

      class SR(bt.Indicator):
          def __init__(self, logger, master, fromdate, todate):
      
              # self.datas[0] is yahoo market data (as default)
              self.atr = self.datas[1]
      
      

      DONE

      posted in Indicators/Strategies/Analyzers
      C
      cgi1
    • RE: Wrong value of Indicator in another CustomIndicator

      Thanks for the good explanation! That´s a view of data feeds I did not had in before.

      So self.datas[0] within SR(bt.Indicator) are now set correctly to the values of ATR.

      The limitation now is, that there is no YahooDataFeed available anymore, because the data feed gets overwritten by

      self.sr = SR(self.atr, [...])
      

      Is it possible to pass multiple data feeds to the indicator?
      In this case the market data (YahooDataFeed) and another indicator (ATR)

      Something like:

      self.sr = SR([self.datas[0], self.atr, self.further_indi], [...])
      
      posted in Indicators/Strategies/Analyzers
      C
      cgi1
    • RE: Wrong value of Indicator in another CustomIndicator

      Generating it new in the custom indicator worked for me:

      
      
      class SomeStrategy(bt.Strategy):
      
          def __init__(self):
              self.atr = bt.indicators.ATR(self.datas[0], subplot=False)
      
      
      posted in Indicators/Strategies/Analyzers
      C
      cgi1
    • Wrong value of Indicator in another CustomIndicator
      class SomeStrategy(bt.Strategy):
      
          def __init__(self):
              self.atr = bt.indicators.ATR(self.datas[0], plotname="ATR", subplot=True)
              self.sr = SR(logger=self.indi_logger, master=self, fromdate=self.p.fromdate_trading, todate=self.p.todate_trading)
      

      Within my custom indicator SR I need to access the ATR line value within SR->next(). So I pass the whole self to it during init:

      class SR(bt.Indicator):
      
          def __init__(self, logger, master, fromdate, todate):
              self.logger = logger
              self.master = master
              self.atr = self.master.atr
      

      In this example I would assume to access the ATR line value of candle 2001-09-10 using self.atr[0] (which is about 0.51). Instead I get the final ATR line value of today (which is 2.67588x):

      0_1500123944740_d9a63f06-ed90-4f72-a12b-a417082e73ff-grafik.png

      Do I need to calculate the shift manually to get the correct ATR value or is there another way to achieve this?

      Thanks & BR!

      Doc Reference

      posted in Indicators/Strategies/Analyzers
      C
      cgi1
    • RE: Save cerebro data to file for later plotting it on another computer

      Thanks for the reply. Just wrote a test:

              try:
                  pickle.dump(cerebro, open(pickle_file_path, "wb"))
                  logger.debug("Successfully pickled cerebro instance to file (%s)!" %pickle_file_path)
              except:
                  logger.exception("Failed to pickle cerebro instance to file (%s)" %pickle_file_path)
      

      but it fails with

      File "/Users/g/PycharmProjects/g1trd/master.py", line 236, in runstrat
          pickle.dump(cerebro, open(pickle_file_path, "wb"))
      TypeError: can't pickle _thread.RLock objects
      
      posted in General Code/Help
      C
      cgi1
    • Save cerebro data to file for later plotting it on another computer

      Here is how I work in general

      I am working on a strategy which works on a bigger set of indicators and price action / swing trading setups. My approach is, to integrate several trading ideas into one strategy.

      Said that, there are particular branches for each idea. E.g.:

      • master branch holds stable status of strategy
      • feature_x branch holds one newly generated stop-rule
      • feature_y branch holds a new filter for ranging markets

      After developing a new stop-rule / entry / pattern etc I need to backtest it to see if it works for a lot of market data. The normal process here is:

      1. Checkout feature_x
      2. Backtest it on about 140 symbols for 10-17 years
      3. Find bugs / Find market conditions in backtest which I did not concider in before / ...
      4. Adjust it
      5. If not satisfied: Repeat at 1. If satisfied: Merge it into master branch

      So the step of backtesting a huge dataset is done very often. Therefore my interest in having the backtest process done quickly, automated and away from my laptop is very high.

      Due to some resource-consuming custom indicator (Support/Resistance) one backtest runs approx. 90 seconds per symbol. I outsourced the backtesting to a powerful linux server which runs 12 backtests in parallel.

      Problem

      So the problem right now is, that my log entries tell me, at which symbols on which dates the current feature have an impact on (e.g. Your new stop rule triggered on 2008-01-19 on EURUSD=X). But I need a chart to see if the program executes it in a situation which I created it for. So i started to use savefig option (cerebro.plot(style='candlestick', savefig=save_fig, dpi=900, width=32, height=18, numfigs=5)) which has been nicely provided by @xnox, but zooming into it looks like this (even with the provided settings):

      0_1499418575958_f4c26c51-43f4-44fb-b544-9c998699c349-grafik.png

      Proposal

      So my idea is to save all the cerebro data to file (e.g. by a linux server) and load the plotter later (on a normal computer) with the saved data. Do you think this is a reasonable way?

      posted in General Code/Help
      C
      cgi1
    • RE: YahooFinance Data Feeds

      Thanks for the reply.

      This means that some lines (a sample line would help) contains prices which can be parse, but the string null that where the volume should be, or is it something else?

      Exactly: So sometimes the datafeed provider (in this case Yahoo on 2017-06-08) does not provider any Volume for some of the symbols. E.g. EURHKD=X:

      Date,Open,High,Low,Close,Adj Close,Volume
      2003-12-01,9.347397,9.278463,9.339722,9.290833,9.290833,null
      2003-12-02,9.287244,9.278581,9.393217,9.380319,9.380319,null
      
      2017-06-06,8.783572,8.734257,8.789911,8.784152,8.784152,null
      2017-06-08,8.780444,8.732892,8.782912,8.748856,8.748856,0 <<<<< Date of download!
      

      Some symbols are including Volume==0. E.g. EURUSD=X

      Date,Open,High,Low,Close,Adj Close,Volume
      2003-12-01,1.203398,1.194401,1.204007,1.196501,1.196501,0
      2003-12-02,1.196101,1.194600,1.210903,1.208897,1.208897,0
      
      2005-09-20,null,null,null,null,null,null <<<< Some dates are does not even contain any data
      
      2017-06-06,1.127053,1.120523,1.127993,1.127142,1.127142,0
      2017-06-08,1.126507,1.127142,1.119946,1.122083,1.122083,0 <<<<< Date of download!
      

      Meanwhile on the same date a lot symbols (e.g. IFX.DE) contain Volume and works as expected.

      Date,Open,High,Low,Close,Adj Close,Volume
      2000-03-14,71.400002,80.000000,71.400002,78.900002,78.900002,9579700
      2000-03-15,76.900002,76.949997,70.800003,73.040001,73.040001,5855009
      

      Hope this helps. If you need further information please let me know.

      posted in General Discussion
      C
      cgi1