Hello everyone,

As mentioned in the title I'm a complete beginner at developing algorithms. To get my feet wet I started of with a simple algorithm which can be found here: Dual Thrust Trading Algorithm. It's a strategy from the Strategy Library and I want to test some indicators to adjust the value of the two parameters dynamically. Unfortunately, I get an error on Line 86: TypeError : '>=' not supported between instances of 'decimal.Decimal' and 'NoneType'.

The code looks like this:

from clr import AddReference AddReference('System') AddReference('QuantConnect.Algorithm') AddReference('QuantConnect.Common') from System import * from QuantConnect import * from QuantConnect.Algorithm import * from datetime import datetime import decimal class DualThrustAlgorithm(QCAlgorithm): def Initialize(self): '''Initialise the data and resolution required, as well as the cash and start-end dates for your algorithm. All algorithms must initialized.''' self.SetStartDate(2013, 1, 1) self.SetEndDate(2015, 12, 31) self.SetCash(10000) equity = self.AddEquity('SPY', Resolution.Hour) self.syl = equity.Symbol self.__adx = self.ADX(self.syl, 30, Resolution.Hour) self.__macd = self.MACD(self.syl, 12, 26, 30, MovingAverageType.Exponential, Resolution.Hour) self.Schedule.On(self.DateRules.EveryDay(self.syl),self.TimeRules.AfterMarketOpen(self.syl,0),Action(self.SetSignal)) self.selltrig = None self.buytrig = None self.currentopen = None def SetSignal(self): history = self.History([self.syl.Value], 4, Resolution.Daily) if not self.__adx.IsReady: return if not self.__macd.IsReady: return if self.__adx > 75 and self.__macd.Current.Value > self.__macd.Signal.Current.Value: k1 = 0.1 k2 = 0.9 elif self.__adx > 50 and self.__macd.Current.Value > self.__macd.Signal.Current.Value: k1 = 0.3 k2 = 0.7 elif self.__adx > 25 and self.__macd.Current.Value > self.__macd.Signal.Current.Value: k1 = 0.4 k2 = 0.6 elif self.__adx > 75 and self.__macd.Current.Value < self.__macd.Signal.Current.Value: k1 = 0.9 k2 = 0.1 elif self.__adx > 50 and self.__macd.Current.Value < self.__macd.Signal.Current.Value: k1 = 0.3 k2 = 0.7 elif self.__adx > 25 and self.__macd.Current.Value < self.__macd.Signal.Current.Value: k1 = 0.6 k2 = 0.4 else: k1 = 0.5 k2 = 0.5 self.high = history.loc[self.syl.Value]['high'] self.low = history.loc[self.syl.Value]['low'] self.close = history.loc[self.syl.Value]['close'] self.currentopen = self.Portfolio[self.syl].Price HH, HC, LC, LL = max(self.high), max(self.close), min(self.close), min(self.low) if HH - LC >= HC - LL: signalrange = HH - LC else: signalrange = HC - LL self.selltrig = float(self.currentopen) - float(k1) * signalrange self.buytrig = float(self.currentopen) + float(k2) * signalrange def OnData(self,data): '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here.''' holdings = self.Portfolio[self.syl].Quantity if self.Portfolio[self.syl].Price >= self.selltrig: if holdings >= 0: self.SetHoldings(self.syl, 0.8) else: self.Liquidate(self.syl) self.SetHoldings(self.syl, 0.8) elif self.Portfolio[self.syl].Price < self.selltrig: if holdings >= 0: self.Liquidate(self.syl) self.SetHoldings(self.syl, -0.8) else: self.SetHoldings(self.syl, -0.8) self.Log("open: "+ str(self.currentopen)+" buy: "+str(self.buytrig)+" sell: "+str(self.selltrig))

 

Your help is much appreciated. Bear with me, I just learned a couple of fundamentals in Python weeks ago. I'm new to this hole thing.

Best,

JD