Using Custom Indicators
Does anyone know where in the docs I can find support for using custom indicators pre-calculated ?
What I am trying to do is use a csv file with the standard OHLCV columns but with another column (or two or three) which have pre-determined values and which will drive the trading/backtesting of the strategy.
For example, the indicator value would be +15 at the close of one bar which would drive a position at the opening of the next one etc etc.
Coding the strategy new in BackTrader would be quite cumbersome and so I'm looking to avoid it.
Ideally I would be able to push this and start trading live using BackTrader using hourly signals but one thing at a time I guess !!
One of the design goals of backtrader was to be able to quickly prototype things and that's why one can define and redefine what's in the data sources and things derived from the data sources.
If your data already contains the information in the
csvformat, you simply need to extend one of the
CSVdata feeds to load your extra column and it will be available to you.
This topic is therefore of course covered in the documentation: Extending a Data Feed
You still need to tell
CSVGenericDatawhere your fields are. Have a look for it at Data Feed Reference
There is a blog post documenting the birth of
GenericCSVData: Blog Post
In addition and maybe to full simulate an indicator you can wrap the extra data value in an indicator:
class MyIndicator(bt.Indicator): lines = ('myline',) def __init__(self): self.lines.myline = self.data.myvaluename
myvaluenameis the name you will assign to the extra data value present in your feed.
Thank you @backtrader for your prompt response - this is fantastic.
I will have a go today.