I managed to get my optimizations to run as quick as optstrategy by subclassing Cerebro and pulling out some stuff out of run() and addstrategy() into different functions (one to initialize data loading, and another which gets re-executed from outside the class for optimization).
I also manage multiprocessing from the outside.
Do you mind to share some code? Or kind of a layout of what and where was implemented in more details?
@ab_trader - I am doing my best. I have already submitted pull requests for new Fisher Transform indicator and Simulated Order. And I am sharing all my code snippets here along with explanations whenever relevant.
When I say the framework should have this or that, I dont mean that someone should implement them but that we shall implement it for everybody's benefit.
@ab_trader If I can use the fractal indicator to reference the true/false for any candle, like fractal[-14] to find out if 14 candles back was a high or low, then it will work, because I have to be able to get the high/low value from the fractal, not just knowing whether or not it is. I'll mess around with it, definitely looks cleaner than my method lol.
File "/home/user/PycharmProjects/backtrader/Strategies/VixLive.py", line 615, in notify_timer
self.initial_position = self.position.size
File "/home/user/PycharmProjects/backtrader/venv/lib/python3.8/site-packages/backtrader/lineseries.py", line 461, in _ _ getattr _ _
return getattr(self.lines, name)
AttributeError: 'Lines_LineSeries_LineIterator_DataAccessor_Strateg' object has no attribute 'position'
The error backtrace above seems strange. Accessing the position property in the strategy should call the bt.Strategy's getposition method:
def getposition(self, data=None, broker=None):
data = data if data is not None else self.datas
broker = broker or self.broker
position = property(getposition)
This should be reflected in the error backtrace. It looks like the self.position was called from the indicator and not from the strategy.
It could be useful to if you could share the whole VixLive.py code?
By default data0 is used as the "primary", correct?
vx2_1_min = cerebro.rolloverdata(*rollfeeds_vx2_minute, **rollkwargs_vx2_minute) -- is data0 since it's called & added first.
@Laurent-Michelizza Thank you very much! when I log the position,I also find this question and use almost your way to solve it.
But in the future,I guess,we do a auto-close function when the future expires, it is more easy to use. After this four times reading the source code,I maybe try this function.