| 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 -1.829 Tracking Error 0.108 Treynor Ratio 0 Total Fees $0.00 Estimated Strategy Capacity $0 Lowest Capacity Asset Portfolio Turnover 0% |
#region imports
from AlgorithmImports import *
#endregion
import numpy as np
import pandas as pd
class BasicTemplateAlgorithm(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2021, 1, 1)
self.SetEndDate(2022, 1, 1)
self.SetCash(100000)
self.AddEquity("AAPL", Resolution.Daily, dataNormalizationMode=DataNormalizationMode.SplitAdjusted)
self.previous_close = None
self.current_high = None
self.orderTicket = None
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen("AAPL", 0), self.Trade)
self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.BeforeMarketClose("AAPL", 1), self.CancelOrder)
def Trade(self):
self.current_high = None
history = self.History(["AAPL"], 2, Resolution.Daily)
high_prices = history.high.unstack(level=0)["AAPL"]
# get the high of the previous day
self.current_high = round(float(high_prices[-1]), 2)
# buy at the high of the previous day
self.orderTicket = self.StopMarketOrder("AAPL", 100, self.current_high + 0.05)
self.previous_close = self.current_high
def CancelOrder(self):
if self.orderTicket is not None and self.orderTicket.Status != OrderStatus.Filled:
self.Debug(f"Cancelling order: {self.orderTicket}")
self.orderTicket.Cancel()