Overall Statistics |
Total Trades 20 Average Win 0% Average Loss -2.08% Compounding Annual Return -21.844% Drawdown 50.800% Expectancy -1 Net Profit -30.724% Sharpe Ratio -0.343 Loss Rate 100% Win Rate 0% Profit-Loss Ratio 0 Alpha -0.747 Beta 29.914 Annual Standard Deviation 0.439 Annual Variance 0.193 Information Ratio -0.389 Tracking Error 0.439 Treynor Ratio -0.005 Total Fees $20.00 |
class CandlestickAlgorithm(QCAlgorithm): def Initialize(self): self.SetStartDate(2018, 1, 1) self.SetEndDate(2019, 6, 30) self.SetCash(100000) self.MarkOrder = None self.SL = 0.95 self.TP = 1.10 self.aapl = self.AddEquity("AAPL", Resolution.Minute) 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); StopPrice = round(FillPrice * self.SL, 2); ProfitPrice = round(FillPrice * self.TP, 2); self.Log('>> SL >> FillPrice:{} StopPrice:{} ProfitPrice:{}'.format(FillPrice, StopPrice, ProfitPrice)); self.Log("ORDER NOTIFICATION >> {} >> Status: {} Symbol: {}. Quantity: " "{}. Direction: {}. Fill Price {}".format(str(Order.Tag), str(OrderEvent.Status), str(OrderEvent.Symbol), str(OrderEvent.FillQuantity), str(OrderEvent.Direction), str(OrderEvent.FillPrice))); if self.Portfolio.Invested: self.StopMarketOrder("AAPL", -100, StopPrice, 'Loss'); self.LimitOrder("AAPL", -50, ProfitPrice, 'Profit'); def OnData(self, data): if not (self.Window.IsReady): return if not self.Portfolio.Invested: if self.Window[1].Low < self.Window[2].Low and self.Window[0].Low < self.Window[1].Low and self.Securities["AAPL"].Open < self.Window[0].Low and self.Securities["AAPL"].Price > self.Window[0].Close: self.MarkOrder = self.MarketOrder("AAPL", 100); elif self.Window[2].Low < self.Window[3].Low and self.Window[1].Low < self.Window[2].Low and self.Window[0].Open < self.Window[1].Low and self.Window[0].Open < self.Window[1].Low and self.Securities["AAPL"].Price > self.Window[0].High: self.MarkOrder = self.MarketOrder("AAPL", 101);