Hi QuantConnect Community, 

I am building a simple equities trading algorithm that buys and sells SPY (or any specified equity) when Stochastic goes above and below certain values. 

I am fairly new and have previously made successful crypto algorithms using a similar algorithm, which is where I got the framework from. 

 

The backtest is returning no trades but no errors either. 

 

Please let me know what I am doing wrong and how to solve it?

 

Thank you in advanced!

class TradierEquitiesStochAlpha(QCAlgorithm):

    def Initialize(self):
        self.SetStartDate(2021, 1, 1)
        self.SetEndDate(2021, 2, 1)
        self.SetCash(1000)
        self.AddEquity("SPY", Resolution.Daily, Market.USA)
        self.SetBrokerageModel(BrokerageName.TradierBrokerage) 
        self.sto = self.STO("SPY", 14)
        
        self.sell_price = None
            
    def OnData(self, data):
        
        if not self.sto.IsReady: 
            return
    
        price = self.Securities["SPY"].Close
        if self.sto.Current.Value < 30 and self.Portfolio == 0:
            self.Debug("Daily SPY STO is < 30")
            
            self.MarketOrder("SPY", 1)
            self.Debug(f"Market order was placed for 95% of protfolio in SPY")
            self.sell_price = (1 + 0.05) * price
        
        if self.sell_price is not None and price >= self.sell_price:
            self.Debug("SPY sold at a 5% gain or more")
            self.MarketOrder("SPY", -self.Portfolio.CashBook["SPY"].Amount)
            self.sell_price = None