| 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 Probabilistic 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 -2.895 Tracking Error 0.085 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset |
from System.Drawing import Color
class MACD(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021,7, 8)
self.SetEndDate(2021, 9, 10)
self.SetWarmUp(timedelta(days = 45))
self.SetCash(25000) # Set Strategy Cash
self.resolution = Resolution.Daily
self.ticker = "EBAY"
self.tickerObj = self.AddEquity(self.ticker, self.resolution ).Symbol
self.dataPlot = Chart("MACD")
self.dataPlot.AddSeries(Series('MACD', SeriesType.Line, ''))
self.dataPlot.AddSeries(Series('Signal_Line', SeriesType.Line, ''))
self.AddChart(self.dataPlot)
self.symbolDataBySymbol = {}
self.symbolDataBySymbol[self.ticker] = SymbolData(self, self.ticker, self.resolution)
class SymbolData:
def __init__(self, algorithm, symbol, resolution ):
self.algorithm = algorithm
self.symbol = symbol
self.resolution = resolution
self.macd = algorithm.MACD(self.symbol,12,26,9,MovingAverageType.Exponential, self.resolution, Field.Low)
self.macd.Updated += self.OnSymbolDataUpdate
def OnSymbolDataUpdate(self, sender, updated):
self.algorithm.Plot('MACD','MACD', self.macd.Current.Value)
self.algorithm.Plot('MACD','Signal_Line', self.macd.Signal.Current.Value)
self.algorithm.Log(f"MACD {self.macd.Current.Value}\tSignal Line\t{self.macd.Signal.Current.Value}")
from System.Drawing import Color
import pandas as pd
import numpy as np
class EMAMomentumUniverse(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021,5, 1) # Set Start Date (2020,8, 1)
self.SetEndDate(2021, 7, 1) # Set End Date (2021, 1, 30)
self.SetWarmUp(timedelta(days = 45)) # Set days to Max indicator period
self.SetCash(25000) # Set Strategy Cash
self.resolution = Resolution.Daily
self.ticker = "OCGN"
self.tickerObj = self.AddEquity(self.ticker, self.resolution ).Symbol
self.dataPlot2 = Chart("BB")
self.dataPlot2.AddSeries(Series('SellSignal', SeriesType.Scatter, '', Color.Red,ScatterMarkerSymbol.Circle))
self.dataPlot2.AddSeries(Series('BuySignal', SeriesType.Scatter, '', Color.Green,ScatterMarkerSymbol.Circle))
self.dataPlot2.AddSeries(Series('Price', SeriesType.Line, '$'))
self.dataPlot2.AddSeries(Series('BollingerUpperBand', SeriesType.Line, '$'))
self.dataPlot2.AddSeries(Series('BollingerMiddleBand', SeriesType.Line, '$'))
self.dataPlot2.AddSeries(Series('BollingerLowerBand', SeriesType.Line, '$'))
self.dataPlot2.AddSeries(Series('MACD', SeriesType.Line, ''))
self.dataPlot2.AddSeries(Series('RSI', SeriesType.Line, ''))
self.dataPlot2.AddSeries(Series('MacdLine', SeriesType.Line, ''))
self.AddChart(self.dataPlot2)
self.symbolDataBySymbol = {}
#SymbolData(self, self.ticker, self.resolution)
self.symbolDataBySymbol[self.ticker] = SymbolData(self, self.ticker, self.resolution)
def OnData(self, data):
for symbol, symbolData in self.symbolDataBySymbol.items():
symbolData.UpdatePrice(self.Securities[symbol].Price)
class SymbolData:
def __init__(self, algorithm, symbol, resolution ):
self.algorithm = algorithm
self.symbol = symbol
self.resolution = resolution
self.price = 0.00
self.ema13 = algorithm.EMA(str(self.symbol), 13)
self.ema63 = algorithm.EMA(str(self.symbol), 63)
self.ema150 = algorithm.EMA(str(self.symbol), 150)
self.macdSignalLine = 0.00 # signal line for MACD based on 9 EMA
self.kama = algorithm.KAMA(str(self.symbol), 10,2,30, self.resolution)
self.macd = algorithm.MACD(self.symbol,12,26,9,MovingAverageType.Exponential, self.resolution, Field.Low)
self.rsi = algorithm.RSI(self.symbol,14)
self.bollinger = algorithm.BB(self.symbol, 20, 1, MovingAverageType.Simple, self.resolution, Field.Low)
self.lookback = 13
self.std = algorithm.STD(symbol, self.lookback,self.resolution)
self.macd.Updated += self.OnSymbolDataUpdate
self.df = pd.DataFrame(np.array([]),columns=['macd'])
def UpdatePrice(self, price):
self.price= price # for daily resolution it's the closing price on the day before
self.algorithm.Plot('BB', 'Price', self.price)
self.femaShort = float(str(self.ema13.Current.Value))>float(str(self.ema63.Current.Value))
#self.algorithm.Log(f"bollinger {self.bollinger}")
if not self.femaShort:
self.algorithm.Plot(str(self.symbol),'EmaSell',self.price)
self.algorithm.Log(f"Sell {self.price} Fema 13 {self.ema13.Current.Value} 63 {self.ema63.Current.Value}")
#if price<self.kama.Current.Value:
# self.algorithm.Plot(str(self.symbol),'KamaSell',self.price)
# self.algorithm.Log(f"Sell {self.price} kama {self.kama.Current.Value}")
if self.macd.Current.Value<0 :
#self.algorithm.Plot('BB','MACDSell',self.price)
self.algorithm.Log(f"Sell {self.price} MACD {self.macd.Current.Value}")
if self.rsi.Current.Value>70:
#self.algorithm.Plot('BB','RSISell',self.price)
self.algorithm.Log(f"Sell {self.price} RSI {self.rsi.Current.Value}")
if price<float(str(self.bollinger.LowerBand.Current.Value)):
#self.algorithm.Plot('BB','BBSell',self.price)
self.algorithm.Log(f"Sell {self.price} BB {self.bollinger.LowerBand.Current.Value}")
def OnSymbolDataUpdate(self, sender, updated):
df2 = pd.DataFrame(np.array([self.macd.Current.Value]),columns=['macd'])
self.df=self.df.append(df2,ignore_index=True)
macdSignalLine=self.df.macd.ewm(span=9, adjust=False).mean()[-1:] # we take 9 days avarage
self.macdSignalLine = macdSignalLine.iloc[0]
#self.algorithm.Plot(str(self.symbol),'EMA13', self.ema13.Current.Value)
#self.algorithm.Plot(str(self.symbol),'EMA63', self.ema63.Current.Value)
#self.algorithm.Plot(str(self.symbol),'EMA150', self.ema150.Current.Value)
#self.algorithm.Plot(str(self.symbol),'Kama', self.kama.Current.Value)
self.algorithm.Plot('BB','Std', self.std.Current.Value)
self.algorithm.Plot('BB','MACD', self.macd.Current.Value)
self.algorithm.Plot('BB','RSI', self.rsi.Current.Value)
self.algorithm.Plot('BB','MacdLine', self.macdSignalLine)
self.algorithm.Plot('BB', 'BollingerUpperBand', self.bollinger.UpperBand.Current.Value)
self.algorithm.Plot('BB', 'BollingerMiddleBand', self.bollinger.MiddleBand.Current.Value)
self.algorithm.Plot('BB', 'BollingerLowerBand', self.bollinger.LowerBand.Current.Value)