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
0
Tracking Error
0
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
class MyEMAMomentumUniverse(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2022, 1, 6)
        self.SetEndDate(2022, 1, 6)
        self.SetCash(100000)
        self.UniverseSettings.Resolution = Resolution.Hour
        self.AddUniverse(self.CoarseSelectionFunction) 
        self.averages = { }
    
    def CoarseSelectionFunction(self, coarse): 
        selectedStocks=[]
        selectedSymbols=[]
        #selectedStocks = sorted(coarse, key=lambda c: c.Price, reverse=True)  
        selectedStocks = [c for c in coarse if c.Price > 1000]
       
        for stock in selectedStocks: 
            symbol = stock.Symbol
            if symbol not in self.averages:
                
                # 1. Call history to get an array of 200 days of history data
                history = self.History(symbol, 200, Resolution.Daily)
                
                #2. Warming up averages indicators with history data
                self.averages[symbol] = SelectionData(history) 
                
                #3. Update Averages with latest price, time
                self.averages[symbol].update(self.Time, stock.AdjustedPrice)
            
            if  (
                self.averages[symbol].is_ready() and 
                self.averages[symbol].EMA20 > self.averages[symbol].EMA50 and
                self.averages[symbol].EMA50 > self.averages[symbol].EMA200 #and
                #stock.AdjustedPrice > self.averages[symbol].EMA20
                ):
                selectedSymbols.append(symbol)
                
        for x in selectedSymbols:
            self.Log(x)
                
        return selectedSymbols
            
class SelectionData():
    #3. Update the constructor to accept a history array
    def __init__(self, history):
        self.EMA200 = ExponentialMovingAverage(200)
        self.EMA50 = ExponentialMovingAverage(50)
        self.EMA20 = ExponentialMovingAverage(20)
        
        #4. Loop over the history data and update the indicators
        for bar in history.itertuples():
            self.EMA200.Update(bar.Index[1], bar.close)
            self.EMA50.Update(bar.Index[1], bar.close)
            self.EMA20.Update(bar.Index[1], bar.close)
    
    def is_ready(self):
        return self.EMA200.IsReady and self.EMA50.IsReady and self.EMA20.IsReady
    
    def update(self, time, price):
        self.EMA200.Update(time, price)
        self.EMA50.Update(time, price)
        self.EMA20.Update(time, price)
        
        
        
            #def FineSelectionFunction(self, fine):
        
        #selected = sorted(fine, key=lambda c: c.ValuationRatios.PERatio, reverse=False)  
        #Others can be used:
        #ValuationRatios.EVToEBITDA: lower is better
        #ValuationRatios.PricetoCashRatio: lower is better
        #ValuationRatios.TotalAssetPerShare: higher is better
        #ValuationRatios.ForwardEarningYield = higher is better (Estimated Earnings Per Share / Price)

        #selected = [
        #        c.Symbol for c in selected
        #   if 
        #       (
                    #c.MarketCap < 10000000000 and 
                    #c.MarketCap > 1000000 and
                    #c.OperationRatios.ROE.OneYear > 0 and 
                    #c.OperationRatios.ROA.OneYear > 0  
                    #c.Price < c.ValuationRatios.BookValuePerShare and
                    #c.ValuationRatios.ForwardROE > 0 and
                    #c.ValuationRatios.ForwardROA > 0
                    #Others can be used:
                    #Price < or > Max, Min Year, Qrt, Month, Week Price
                    #Price < or > MA20, 50, 200, VWAP
                    #AssetClassification.MorningstarSectorCode (101-104, 205-207, 308-311)

         #       )]
        #return selected[:10]