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
andcompression=15
and used an analyzer to store the values. However, it only delivers values every 15 min:datetime,Stochastic15,RSI15,MACD15 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?
-
Several
-
Post some sample code (it really helps)
-
If the target is to write the values of indicators use the standard functionality
Writer
- See: https://www.backtrader.com/docu/writer.html
- Don't forget to do this with your indicator:
self.mysma = bt.indicators.SMA(self.data, 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 tocerebro
is the one withtimeframe=bt.TimeFrame.Minutes
andcompression=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 since1.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 andself.data1
the larger timeframe. Use the appropriate reference when creating the indicators - Although not strictly needed use
cerebro.run(next=True
). This will keep the buffers fully sync'ed and allows plotting.
- Add the larger timeframe (your
-
-