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.041
Tracking Error
0.103
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
class MovingAverageCrossAlgorithm(QCAlgorithm):

    def Initialize(self):
        #algo basics
        self.risk = 1.01
        self.takeProfit = 1.04
        self.ticker = "XPEV"
        self.cash = 10000
        self.SetStartDate(2021, 1, 1)
        self.SetEndDate(2021, 11, 12)
        self.SetCash(self.cash)
        self.AddEquity(self.ticker, Resolution.Minute)

        #indicator setup
        self.trigger = self.EMA(self.ticker, 7)
        self.trigger.Updated += self.EmaUpdated
        self.emaWinA = RollingWindow[IndicatorDataPoint](5)
        
        self.fast = self.EMA(self.ticker, 12)
        self.fast.Updated += self.EmaUpdated
        self.emaWinB = RollingWindow[IndicatorDataPoint](5)
        
        self.medium = self.EMA(self.ticker, 50)
        self.medium.Updated += self.EmaUpdated
        self.emaWinC = RollingWindow[IndicatorDataPoint](5)
        
        self.slow = self.EMA(self.ticker, 200)
        self.slow.Updated += self.EmaUpdated
        self.emaWinD = RollingWindow[IndicatorDataPoint](5)

        self.SetWarmUp(200)
        self.previous = None


    def OnData(self, data):

        # wait for our slow ema to fully initialize
        if not self.slow.IsReady:
            return
        
        A1 = self.emaWinA[0]
        A2 = self.emaWinA[1]
        
        B1 = self.emaWinB[0]
        B2 = self.emaWinB[1]
        
        C1 = self.emaWinC[0]
        C2 = self.emaWinC[1]
        
        D1 = self.emaWinD[0]
        D2 = self.emaWinD[1]
        
        if (A1.Value - D1.Value) > 0 or (A2.Value - D2.Value) > 0:
            halfCurr = (A1.Value - C1.Value)/(A1.Value - D1.Value)
            halfPrev = (A2.Value - C2.Value)/(A2.Value - D2.Value)        
        
        if not self.Portfolio.Invested and (A1.Value - D1.Value) > 0 and (A2.Value - D2.Value) > 0 and halfCurr.Value < 0.5 and halfPrev.Value > 0.5:
            self.SetHoldings(self.ticker, -0.8)
            
        if self.Securities[self.ticker].Price > (self.Portfolio[self.ticker].Price * self.risk) or self.Securities[self.ticker].Price < (self.Portfolio[self.ticker].Price * self.takeProfit):
            self.Liquidate()

        self.previous = self.Time
        
    def EmaUpdated(self, sender, updated):
        self.emaWinA.Add(updated)
        self.emaWinB.Add(updated)
        self.emaWinC.Add(updated)
        self.emaWinD.Add(updated)