Overall Statistics
Total Trades
4
Average Win
0%
Average Loss
-0.13%
Compounding Annual Return
-0.059%
Drawdown
0.500%
Expectancy
-1
Net Profit
-0.269%
Sharpe Ratio
-0.227
Loss Rate
100%
Win Rate
0%
Profit-Loss Ratio
0
Alpha
0.001
Beta
-0.065
Annual Standard Deviation
0.003
Annual Variance
0
Information Ratio
-7.606
Tracking Error
0.003
Treynor Ratio
0.009
Total Fees
$4.00
class NewsReportAlgorithm(QCAlgorithm):
    
    def Initialize(self):
        self.SetStartDate(2015, 1, 1)
        self.SetEndDate(2019, 7, 30)
        self.SetCash(100000)
        self.AddEquity("AAPL", Resolution.Minute)
        self.Securities["AAPL"].SetDataNormalizationMode(DataNormalizationMode.Raw)
        self.Window = RollingWindow[TradeBar](5)
        self.Consolidate("AAPL", Resolution.Daily, self.TradeBarHandler);
        
    def TradeBarHandler(self, TradeBar):
        self.Window.Add(TradeBar);
    
    def OnOrderEvent(self, OrderEvent):
        if OrderEvent.FillQuantity == 0:
            return;
        
        Order = self.Transactions.GetOrderById(OrderEvent.OrderId)
        FillPrice = round(OrderEvent.FillPrice*1, 2)
        Profit = 0.97*FillPrice
        self.Log("ORDER NOTIFICATION >> {} >> Status: {} Symbol: {}. Quantity: "
                    "{}. Open: {}. Previous High: {}. High: {}. Fill Price {}".format(str(Order.Tag),
                                                   str(OrderEvent.Status),
                                                   str(OrderEvent.Symbol),
                                                   str(OrderEvent.FillQuantity),
                                                   self.Securities["AAPL"].Open,
                                                   self.Window[0].High,
                                                   self.Securities["AAPL"].High,
                                                   str(OrderEvent.FillPrice)));
                                                   
        if OrderEvent.Status == OrderStatus.Filled and Order.Type == OrderType.Market:
            self.StopMarketOrder("AAPL", 100, self.Securities["AAPL"].High + .20, 'Stop Loss');
            self.LimitOrder("AAPL", 100, Profit, 'Take Profit');
            
        if OrderEvent.Status == OrderStatus.Filled and Order.Type == OrderType.StopMarket:
            self.Transactions.CancelOpenOrders();
            
        if OrderEvent.Status == OrderStatus.Filled and Order.Type == OrderType.Limit:
            self.Transactions.CancelOpenOrders();
                                                   
    def OnData(self, data):
        if not (self.Window.IsReady): 
            return
        
        if self.Securities["AAPL"].Open > .40 + self.Window[0].High and self.Securities["AAPL"].Price < self.Window[0].High - .30:
            self.MarketOrder("AAPL", -100);
            #elif self.Securities["AAPL"].Price < self.Window[0].Low - .40:
                #self.LimitOrder("AAPL", 100, self.Window[0].Low + .10);
                #self.StopMarketOrder("AAPL", -100, self.Window[0].Low - .10)
                #self.StopMarketOrder("AAPL", 100, self.Window[0].Low + .30);