With a strategy with multiple instruments, anyway to make one plot per?
-
I have multiple instruments with corresponding data feeds. The resultant plot() is way too busy, and would like to have a plot() for each instrument, even if that meant that the top portfolio section is the same between plots. Can this be done?
Thanks.
-
No and yes. Plots are strategy-based and not data-based.
But you could selectively disable which data feeds have to be shown and then replot. This is completely untested, but it should be something like this:
st = cerebro.run(....)[0] # assume only interest in 1st strategy (probably the only one) for i in range(len(st.datas)): for j, d in enumerate(st.datas): d.plotinfo.plot = i == j cerebro.plot()
-
Thanks,
That does work. Alternatively is there a way to get access to this raw data so I can plot myself? -
Each line in a data feed has:
- An attribute
array
which holds the data - Method
getzero(idx, size)
to return the data from the beginning - Method
plot(idx=0, size=None)
which if called asplot()
will simply give you the entire array
- An attribute
-
@backtrader
This works for me but all the buy/sell signal is on the first plot.
How do I plot the buy/sell signal for each datafeed on its own separate plot?
Thanks in advance. -
@vhphan said in With a strategy with multiple instruments, anyway to make one plot per?:
but all the buy/sell signal is on the first plot.
You probably bought and sold only what's on the first plot.
@vhphan said in With a strategy with multiple instruments, anyway to make one plot per?:
How do I plot the buy/sell signal for each datafeed on its own separate plot?
That happens automatically. But we don't know what you have done and how, so there is no way to tell what, why, how ...
-
@backtrader
Thanks.
You are right. I did bought and sold on the first plot.
I managed to fix the code.