Overall Statistics |
Total Trades 0 Average Win 0% Average Loss 0% Compounding Annual Return 0% Drawdown 0% Expectancy 0 Net Profit 0% Sharpe Ratio 0 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0 Beta 0 Annual Standard Deviation 0 Annual Variance 0 Information Ratio 0 Tracking Error 0 Treynor Ratio 0 Total Fees $0.00 |
class DualThrustAlgorithm(QCAlgorithm): def Initialize(self): # set cash, dates, and brokerage fees self.SetCash(100000) self.SetStartDate(2017,3,1) self.SetEndDate(2017,5,1) self.SetBrokerageModel(BrokerageName.OandaBrokerage) # holds symbol data self.Data = {} self.SymbolData = {} # resolution designations self.PR = Resolution.Hour self.IR = Resolution.Hour # initialize forex pairs self.pairs =["USDJPY", "AUDUSD", "NZDUSD", "USDCAD", "EURUSD", "EURJPY"] for symbol in self.pairs: if symbol not in self.Data: fx = self.AddForex(symbol, self.PR, Market.Oanda) self.Data[symbol]= fx else: break # initialize indicators for all pairs for symbol in self.Data.keys(): macd = self.MACD(symbol, 11, 25, 8, self.IR) sma = self.SMA(symbol, 18, self.IR) rsi = self.RSI(symbol, 14, self.IR) self.SymbolData[symbol] = SymbolData(symbol,macd,sma,rsi) ## Create three Charts macdPlot = Chart('MACD') smaPlot = Chart('SMA') rsiPlot = Chart('RSI') ## Loop through SymbolData object dictionary and add a Series for each symbol and each indidcator for symbol, symbolData in self.SymbolData.items(): macdPlot.AddSeries(Series('{}_MACD'.format(symbol), SeriesType.Line,0)) smaPlot.AddSeries(Series('{}_SMA'.format(symbol), SeriesType.Line,0)) rsiPlot.AddSeries(Series('{}_RSI'.format(symbol), SeriesType.Line,0)) def OnData(self, data): pass def OnEndOfDay(self): for symbol, symbolData in self.SymbolData.items(): self.Debug(symbol) self.Debug(symbolData.MACD.Current.Value) self.Debug(symbolData.SMA.Current.Value) self.Debug(symbolData.RSI.Current.Value) ## Plot each indicator value for each SymbolData object on the appropriate Chart self.Plot('MACD', '{}_MACD'.format(symbol), symbolData.MACD.Current.Value) self.Plot('SMA', '{}_SMA'.format(symbol), symbolData.SMA.Current.Value) self.Plot('RSI', '{}_RSI'.format(symbol), symbolData.RSI.Current.Value) class SymbolData(object): def __init__(self, symbol, macd, sma, rsi): self.Symbol = symbol self.MACD = macd self.SMA = sma self.RSI = rsi
"""The reason why you can't produce any more indicators than the final pair in the list, is because the code keeps on overriding self.macd, self.sma and self.rsi. In order to save the objects once created, try creating a SymbolData object like so: class SymbolData(object): def __init__(self, symbol, macd, sma, rsi): self.Symbol = symbol self.MACD = macd self.SMA = sma self.RSI = rsi This SymbolData object can be stored in a dictionary that is keyed by the symbol just like self.Data in the above code. This way the indicators for each symbol will be properly stored. The backtest below shows a possible implementation."""