Hi all,
i'm new to this platform, and am stuck implementing following part of a strategy. i have experimented quite a few things, and read the online help available, but its not working out. any help is welcome !
Strategy algorithm snippet : (fixed data feed size being used : 1000 periods)
- start with an EMA (say, EMA of 200 periods)
- generate the EMA line
- generate the EMA crossings w.r.t. datas.close
- count number of crossings created in 3)
- if count is < 10
5a) decrease EMA period by 1
5b) goto step 2)
else
5c) print out final EMA period and use it for rest of the strategy.
While implementing above, i create EMA of x period in __init__ of strategy, something like:
self.current_ema = bt.indicators.ExponentialMovingAverage(self.datas[0].close, period=self.emasize)
i can generate the crossings line in 3) either in __init__ (line processing) or in next (element processing)
however, the count of crossings can be generated only in next (or so i believe !)
The problem is, once i generate the count and reach 5b), how do i create the next EMA in 2) ? the control flow wont go back to __init__ for creating a new indicator.
any ideas/ help welcome !