For code/output blocks: Use ``` (aka backtick or grave accent) in a single line before and after the block. See:

Instant values of indicators

  • I am trying to compile an array mixing 1 min data with the values of indicators on higher time frames (e.g. the real-time value of the 15 min RSI at 8:07 on a still open 15 min bar).

    I have added the 1 min data with replaydata and compression=15 and used an analyzer to store the values. However, it only delivers values every 15 min:

    2010-01-04 08:14:00,,,
    2010-01-04 08:29:00,,75.0,
    2010-01-04 08:44:00,46.666666666666664,58.2028390736719,0.33877015095549723

    Any suggestions on how I could do it?

  • administrators


    • Post some sample code (it really helps)

    • If the target is to write the values of indicators use the standard functionality Writer

      self.mysma = bt.indicators.SMA(, period=30)
      self.mysma.csv = True

      The default behavior is to not write the value of indicators with a writer to avoid cluttering in the csv output and thus selected indicators must have the csv flag activated.

    • If a single data feed is added to the system with replaydata, only this data will be output. In this case the only data known to cerebro is the one with timeframe=bt.TimeFrame.Minutes and compression=15. The original is NOT in the system

      • Add it too with: cerebro.adddata(data)

        The original behavior of backtrader enforced adding the larger timeframe data feeds after the smaller timeframe feeds. With the new sychronization mechanism available since 1.9.x., this is no longer needed. In any case the suggestions would be for this:

        • Add the larger timeframe (your replaydata) after the smaller timeframe (adddata)
        • In that case: self.data0 will be the smaller timeframe and self.data1 the larger timeframe. Use the appropriate reference when creating the indicators
        • Although not strictly needed use This will keep the buffers fully sync'ed and allows plotting.

Log in to reply