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
-1.95
Tracking Error
0.104
Treynor Ratio
0
Total Fees
$0.00
Estimated Strategy Capacity
$0
Lowest Capacity Asset
class FatBrownBison(QCAlgorithm):

    def Initialize(self):
        self.cash = 100000
        self.ticker = "TSLA"
        self.tp = 0.02
        self.risk = 0.01
        
        self.SetStartDate(2021, 1, 1)
        self.SetEndDate(2021, 11, 1)
        self.SetCash(self.cash)
        self.AddEquity(self.ticker, Resolution.Minute)

        #indicators and rolling windows
        self.emaFast = self.EMA(self.ticker, 12)
        self.emaFast.Updated += self.SmaUpdated
        self.fastWin = RollingWindow[IndicatorDataPoint](5)
        
        self.emaSlow = self.EMA(self.ticker, 26)
        self.emaSlow.Updated += self.SmaUpdated
        self.slowWin = RollingWindow[IndicatorDataPoint](5)
        
        self.SetWarmUp(26)
        
        #self.SetRiskManagement(MaximumDrawdownPercentPerSecurity(0.005))
    
    def OnData(self, data):

            currSlowEMA = self.slowWin[0]
            prevSlowEMA = self.slowWin[1]
    
            currFastEMA = self.fastWin[0]
            prevFastEMA = self.fastWin[1]
            
            if not self.Portfolio.Invested:
            #short logic w/ stop loss
                if prevFastEMA.Value > prevSlowEMA.Value and currFastEMA.Value < currSlowEMA.Value:
                    self.SetHoldings(self.ticker, -1)
                    self.StopMarketOrder(self.ticker, self.Portfolio[self.ticker].Quantity, self.Portfolio[self.ticker].Price * (1 - self.tp))
        
            #long logic w/ stop loss
                elif prevFastEMA.Value < prevSlowEMA.Value and currFastEMA.Value > currSlowEMA.Value:
                    self.SetHoldings(self.ticker, 1)
                    self.StopMarketOrder(self.ticker, -self.Portfolio[self.ticker].Quantity, self.Portfolio[self.ticker].Price * (1 + self.tp))
        
            #short take profit logic
            elif self.Portfolio[self.ticker].IsShort:
                if self.Securties[self.ticker].Price <= (self.Portfolio[self.ticker].Price (1 - self.tp)):
                    self.Transactions.CancelOpenOrders()
                    self.Liquidate()
            
            #long take profit logic
            elif self.Portfolio[self.ticker].IsLong:
                if self.Securties[self.ticker].Price >= (self.Portfolio[self.ticker].Price * (1 + self.tp)):
                    self.Transactions.CancelOpenOrders()
                    self.Liquidate()
        
    def SmaUpdated(self, sender, updated):
        self.slowWin.Add(updated)
        self.fastWin.Add(updated)