Indicators - different subplot values for different lines
I have developed an indicator that can provide signals when a price hits a simple trend line.
My signal line is currently on a
subplot. However I would also like to plot my trend line on the main plot so I can easily see afterwards what is going on.
In other words:
subplot = True
subplot = False
I didn't spot anything in the line specific plotting options in the docs (https://www.backtrader.com/docu/plotting/plotting.html)
@ThatBlokeDave from my understanding
subplotis applicable to whole indicator, observer or data, but not to the particular line. So looks like you may want to have two indicators - trend and signal (which can call trend indicator inside) and plot them with different
As pointed out by @ab_trader,
subplotonly applies to what one could call first class citizens, i.e.: objects that hold lines themselves (Indicators and Observers) Data Feeds are also first class citizens, but they don't support
subplotbecause they are the target of such action (when
Rather than developing a new indicator for that line, a quick solution can be:
- Creating a
period=1of the line in question.
func=lambda x: x(basically the identity function for the unique value in the array). See Docs - Indicators for
Plot master is also documented in Docs - Plotting
- Creating a
Or even better, use the functionality that was specifically created to support this use case:
Thanks for the suggestions.
I managed to get the
SimpleMovingAveragesuggestion working by creating the SMA inside the strategy and feeding it the line.
I also tried applying the SMA idea inside my custom indicators
__init__method but could not manage to get anything to plot. I guess I cannot plot indicators within indicators (even though the SMA is calculated fine.)
It would be nice to be able to get the line to plot from within my custom indicator code if possible. So I do not need to create a second indicator in the strategy.
I also failed in my attempts to get a the
LinePlotterIndicatorworking. I think that is because I am not performing a calculation on the lines themselves. I am simply extracting the date from the line, converting it to a timestamp and calculating Y (price on the chart) from the slope and offset that is calculated during the indicators
__init__from values passed to it.
Having said that, It is late here and it is likely I am misinterpreting the docs!
I also tried applying the SMA idea inside my custom indicators init method but could not manage to get anything to plot. I guess I cannot plot indicators within indicators (even though the SMA is calculated fine.)
That cannot be done. Strategies plot any indicators directly created by itself. And Indicators plot the lines they have.
Ok noted, thanks.