Overall Statistics
Total Trades
6
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
$6.00
Estimated Strategy Capacity
$2200000.00
Lowest Capacity Asset
UPST XKEDQOEEEPUT
# Ten Minutes EMA Portfolio
from AlgorithmImports import *

STOCKS = ["TSLA", "MSFT", "ADSK", "UPST" ]; EMA_5 = 5; EMA_13 = 13; BAR = 10;
        
class TenMinutesEmaPortfolio(QCAlgorithm):
   
    def Initialize(self):
        self.SetCash(25000)  
        self.SetStartDate(2022, 6, 17)
        self.SetEndDate(2022, 6, 17)
        res = Resolution.Minute
        self.ema_5 = {}; self.ema_13 = {}
        self.stocks =  [self.AddEquity(ticker, res).Symbol for ticker in STOCKS]        
        for sec in self.stocks:
            Consolidator = TradeBarConsolidator(timedelta(minutes = BAR))
            Consolidator.DataConsolidated += self.BarHandler
            self.SubscriptionManager.AddConsolidator(sec, Consolidator)
            self.ema_5[sec] = ExponentialMovingAverage(EMA_5)
            self.ema_13[sec] = ExponentialMovingAverage(EMA_13)
            self.RegisterIndicator(sec, self.ema_5[sec], Consolidator)
            self.RegisterIndicator(sec, self.ema_13[sec], Consolidator)
        self.consolidated = False
        self.SetWarmUp(5*BAR*EMA_13, res)  


    def BarHandler(self, sender, consolidated):   
        if not (self.Time.hour >= 10 and self.Time.hour < 16 ): return
        
        if self.IsWarmingUp: return
        self.consolidated = True 
        
        for sec in self.stocks:          
            if not (self.ema_5[sec].IsReady and self.ema_13[sec].IsReady): continue
            ema_5 = self.ema_5[sec].Current.Value
            ema_13 = self.ema_13[sec].Current.Value

            self.Plot(sec, "ema_5", ema_5)  
            self.Plot(sec, "ema_13", ema_13) 
        
            if not self.Portfolio[sec].Invested:
                if ema_5 >= ema_13*1.001:
                    self.SetHoldings(sec, 1/len(self.stocks), False, "EMA 5 above EMA 13")
            elif self.Portfolio[sec].Invested:            
                if ema_5 < ema_13*0.999: 
                    self.Liquidate(sec, "EMA 5 under EMA 13")                   
            else: continue