Overall Statistics
Total Trades
159
Average Win
4.35%
Average Loss
-3.68%
Compounding Annual Return
7.254%
Drawdown
58.500%
Expectancy
0.437
Net Profit
217.761%
Sharpe Ratio
0.496
Probabilistic Sharpe Ratio
2.058%
Loss Rate
34%
Win Rate
66%
Profit-Loss Ratio
1.18
Alpha
-0.016
Beta
0.932
Annual Standard Deviation
0.171
Annual Variance
0.029
Information Ratio
-0.46
Tracking Error
0.05
Treynor Ratio
0.091
Total Fees
$864.82
class VerticalQuantumAtmosphericScrubbers(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2003, 6, 29)  # Set Start Date
        self.SetCash(100000)  # Set Strategy Cash
        self.dict = {}
        self.AddEquity("SPY", Resolution.Daily)
        #define our bb indicator for SPY
        self.bb = self.BB("SPY", 14, 2, Resolution.Daily)
        #tradelock keeps track of whether our entry conditions have been met
        # if trade lock is true, entry conditions are not yet met, we cannot enter a trade
        # if trade lock is false, entry conditions have been met and we can now enter a trade 
        # when available
        self.tradeLock = True
    
    
    def OnData(self, data):
        #make sure our indicator is ready
        if not self.bb.IsReady:
            return
        
        price = self.Securities["SPY"].Price
        
        #if the price is below 0% BB
        if price < self.bb.LowerBand.Current.Value:
            #if we are already in a long position, we liquidate and cut our losses
            if self.Portfolio["SPY"].Invested:
                self.Liquidate()
            #we set trade lock to false, allowing us to enter a trade next time price crosses above 0% BB
            self.tradeLock = False
            
        #if the price is above 0% BB and also trade lock is false 
        if price > self.bb.LowerBand.Current.Value and self.tradeLock is False:
            #we enter a long position
            self.SetHoldings("SPY", 1)
            #set trade lock to true, prohibiting further trades
            self.tradeLock = True
            
        if price > self.bb.UpperBand.Current.Value and self.Portfolio["SPY"].Invested:
            #if the price crosses the upperband and we have a long position 
            #we liquidate for profit
            self.Liquidate()