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

    def Initialize(self):
        # self.SetStartDate(2021, 1, 1)
        self.SetStartDate(2021, 7, 30)
        self.SetCash(10000) 
        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage)
        
        order_target_percent = 1
        
        # +
        symbol = self.AddEquity("NOW", Resolution.Minute).Symbol
        strat = StrategyNOW_TEST(qcalgo=self, symbol=symbol, order_target_percent=0)
        self.Schedule.On(self.DateRules.EveryDay(symbol), self.TimeRules.Every(TimeSpan.FromMinutes(10)), strat.trade)
        
        
class StrategyNOW_TEST:
    def __init__(self, qcalgo, symbol, order_target_percent):
        self.algo = qcalgo  # self - QCAlgorithm
        self.symbol = symbol
        self.order_target_percent = order_target_percent
        self.time_bought = None
    
    def entry(self):
        # Buy on day close
        if self.algo.LiveMode: self.algo.Log(f"{self.algo.Time} - StrategyNOW_TEST - {self.symbol} - entry()")
        
        if self.algo.LiveMode: self.algo.Log(f"{self.algo.Time} - StrategyNOW_TEST - self.symbol in self.algo.CurrentSlice.Bars: {self.symbol in self.algo.CurrentSlice.Bars}")
        if self.algo.LiveMode: self.algo.Log(f"{self.algo.Time} - StrategyNOW_TEST - self.algo.CurrentSlice.Bars.ContainsKey(self.symbol) : {self.algo.CurrentSlice.Bars.ContainsKey(self.symbol)}")
        
        if not self.algo.CurrentSlice.Bars.ContainsKey(self.symbol): return
        if self.symbol not in self.algo.CurrentSlice.Bars: return
        if self.algo.Portfolio[self.symbol].Invested: return
        
        history = self.algo.History(self.symbol, 2, Resolution.Daily)
        if 'close' not in history or history.dropna().shape[0] <= 1: return
        close, open_, low, high, volume = history.close.unstack(level=0), history.open.unstack(level=0), history.low.unstack(level=0), history.high.unstack(level=0), history.volume.unstack(level=0)
        
        close2 = close.copy()
        
        bar = self.algo.CurrentSlice.Bars[self.symbol]
        close.loc[bar.EndTime] = [bar.Close]
        
        if self.algo.LiveMode: self.algo.Log(f"{self.algo.Time} - StrategyNOW_TEST - {self.symbol} - close: {close}")
        
            
    def exit(self):
        # sell next day close
        if self.algo.LiveMode: self.algo.Log(f"{self.algo.Time} - StrategyNOW_TEST - {self.symbol} - exit()")
        if not self.algo.Portfolio[self.symbol].Invested: return
        if self.time_bought is None or (self.algo.Time - self.time_bought) < timedelta(hours=3): return
    
        self.algo.Liquidate(self.symbol)
        self.time_bought = None
        
        if self.algo.LiveMode: self.algo.Log(f"{self.algo.Time} - StrategyNOW - liquidation order created")
        
    def trade(self):
        self.entry()
        self.exit()