| Overall Statistics |
|
Total Trades 1 Average Win 0% Average Loss 0% Compounding Annual Return 2.283% Drawdown 8.400% Expectancy 0 Net Profit 3.419% Sharpe Ratio 0.462 Loss Rate 0% Win Rate 0% Profit-Loss Ratio 0 Alpha 0.065 Beta -2.083 Annual Standard Deviation 0.052 Annual Variance 0.003 Information Ratio 0.076 Tracking Error 0.052 Treynor Ratio -0.011 Total Fees $1.00 |
class CandlestickAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2018, 1, 1)
self.SetEndDate(2019, 6, 30)
self.SetCash(100000)
self.Equities = ["AAPL"]
self.MarkOrder = None
self.SL_Order = None
self.TP_Order = None
self.SL = 0.95
self.TP = 1.10
for Equity in self.Equities:
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 = self.Transactions.GetOrderById(OrderEvent.FillPrice)
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)));
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);
#if self.Securities["AAPL"].Price == StopLevel:
#self.Liquidate("AAPL");
#if self.Securities["AAPL"].Price == ProfitLevel:
#self.SL_Order = self.StopMarketOrder("AAPL", -50, self.Securities["AAPL"].Price);
#self.LimitOrder("AAPL", -101, self.SL*self.Fill_Price);
#self.LimitOrder("AAPL", -51, self.TP*self.Fill_Price);
#if self.Portfolio.Invested:
#if self.Securities["AAPL"].Price == OrderEvent.FillPrice * self.SL:
#self.Liquidate("AAPL");
# if self.Securities["AAPL"].Price == OrderEvent.FillPrice * self.TP:
# self.MarketOrder("AAPL", -50);