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
-12.965
Tracking Error
0.137
Treynor Ratio
0
Total Fees
$0.00
class CryingOrangeRhinoceros(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2020, 8, 11) 
        self.SetEndDate(2020, 8, 16)
        
        self.symbol = self.AddEquity("SPY", Resolution.Second).Symbol
        self.fast_ema = ExponentialMovingAverage(5)
        self.slow_ema = ExponentialMovingAverage(30)

        # Warm up emas:
        history = self.History(self.symbol, 30, Resolution.Minute).loc[self.symbol]
        for time, row in history.iterrows():
            self.fast_ema.Update(time, row.close)
            self.slow_ema.Update(time, row.close)
            
        self.Log(f"before ComputeNextValue: {self.slow_ema.Current.Value}")
        self.Log(f"ComputeNextValue: {self.slow_ema.ComputeNextValue(IndicatorDataPoint(datetime.now(), 1000))}")
        self.Log(f"after ComputeNextValue: {self.slow_ema.Current.Value}")
        
        self.Consolidate("SPY", timedelta(minutes=1), self.consolidation_handler)

    def consolidation_handler(self, consolidated):
        time = consolidated.EndTime
        close = consolidated.Close
        self.fast_ema.Update(time, close)
        self.slow_ema.Update(time, close)


    def OnData(self, data):
        if not (data.ContainsKey(self.symbol) and data[self.symbol] is not None):
            return 
        
        # Check what the value of the EMAs would be currently, before the next minute-bar update
        close = data[self.symbol].Close
        slow = self.slow_ema.ComputeNextValue(IndicatorDataPoint(data.Time, close))
        fast = self.fast_ema.ComputeNextValue(IndicatorDataPoint(data.Time, close))