Indicator vs Strategy
-
I'm new to backtrader and I'm trying to understand what to put in an Indicator vs what to put in a Strategy. The Documentation and other web examples use a mix of the 2 approaches. I've previously used TradingView Pine Script, and also Python with Pandas & Plotly.
I'm creating my 1st Strategy containing an indicator, but I will need to create Strategies that use multiple indicators. As per the docs, I'm trying to do as much as possible in__init__
and think in terms of vectors rather than scalars.
What are the Pros & Cons of creating a separate Indicator vs doing everything in the Strategy? -
These are my current thoughts/assumptions:
- Indicator is automatically plotted by cerebro.plot()
- Indicator can inherit from other Indicators
- Separate Indicator can be more easily re-used
Do everything in the Strategy is a bit simpler, involves less upfront thinking/design. Possibly the starting point to be refactored into a separate Indicator later.
-
@dr1ver said in Indicator vs Strategy:
What are the Pros & Cons of creating a separate Indicator vs doing everything in the Strategy?
Could you more specific about your question?
Indicators create signals that get used by the overall strategy. You can use multiple different datas and other inputs in indicators. They speed up the process and make your code efficient. Your strategy runs everything.
-
@dr1ver If you code these in the init as indicators, they will pre-load and your code will run many times faster. If you handle everything in next, code will run slower.
-
@run-out I understand that - I mentioned that in the initial post. My question is why were close_over_sma, close_over_ema, sma_ema_diff and buy_sig created in the Strategy rather than one or all of them being created as their own Indicator object?
What benefit was achived by creating them in the Strategy, and what benefit would have been achieved by creating them as Indicators?The question isn't about init vs next. I'm trying to understand when I should create my own Indicator objects and when I should just put everything into the Strategy object.