Hello all,
I have created the vortex indicator, and I am trying to use it in a rolling window, however I am unsure as to how to go about doing this, as the class has no Updated() function and does not output IndicatorDataPoint class objects. Is it possible to do this? My Indicator class is below:
class VI:
def __init__(self, period):
self.Name = "Vortex"
self.Time = datetime.min
self.IsReady = False
self.Value = 0 #arbitrary, not to be read - just outputted so as not to cause compiler err.
self.Uptrend = 0
self.Downtrend = 0
self.queue = deque(maxlen=period+1)
self.Period = period
def __repr__(self):
return f"{self.Name} -> IsReady: {self.IsReady}, Time: {self.Time}, Value: {self.Value}"
def Update(self, input):
self.queue.appendleft(input)
self.Time = input.EndTime
sum_trn = 0
sum_vm_uptrend = 0
sum_vm_downtrend = 0
lows = np.array([float(x.Low) for x in self.queue])
highs = np.array([float(x.High) for x in self.queue])
closes = np.array([float(x.Close) for x in self.queue])
if len(self.queue) == self.queue.maxlen:
for i in range(0, self.queue.maxlen - 1):
sum_trn += np.nanmax(
np.array([
highs[i] - lows[i],
highs[i] - closes[i+1],
lows[i] - closes[i+1]
]))
sum_vm_uptrend += abs(highs[i] - lows[i+1])
sum_vm_downtrend += abs(lows[i] - highs[i+1])
self.Vale.Downtrend = sum_vm_uptrend / sum_trn
self.Value.Uptrend = sum_vm_downtrend / sum_trn
self.IsReady = len(self.queue) == self.queue.maxlen
return self.IsReady
Shile Wen
Hi Marcel,
We can define a function to register callback functions. This way we can register a function to update our RollingWindows when the indicator is updated. I've shown this in the attached backtest.
Best,
Shile Wen
Marcel Madden
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!