Hi,
I am just trying a very simple algorithm as shown in the code snippet below. When backtesting the algorithm will execute orders when I set the resolution to second but when I switch to tick resolution no order gets executed. Are there any limitations on tick data order execution? In the log output I can see the log statement but still the order does not get executed.
Thanks for any help.
import random
from datetime import timedelta
class BaseLine(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2020, 1, 28) # Set Start Date
self.SetEndDate(2020, 1, 29) # Set End Date
self.SetCash(100000) # Set Strategy Cash
#1. Subscribe to some stocks
self.stocks = ["AAPL", "MSFT", "FB"]
for stock in self.stocks:
self.AddEquity(stock, Resolution.Tick)
self.Securities[stock].SetDataNormalizationMode(DataNormalizationMode.Raw)
self.NextOrderTime = self.Time
def OnData(self, data):
if self.Time > self.NextOrderTime:
self.canInvest = False
stock = random.choice(self.stocks)
self.Log("{0}: Purchasing stock {1}".format(self.Time, stock))
# Create market order to buy 50 units of stock
self.MarketOrder(stock, 50)
self.StopMarketOrder(stock,-50,self.Securities[stock].Price*0.9)
self.LimitOrder(stock,-50,self.Securities[stock].Price*1.1)
def OnOrderEvent(self, orderEvent):
if orderEvent.Status == OrderStatus.Filled:
order = self.Transactions.GetOrderById(orderEvent.OrderId)
self.Log("{0}: {1}: {2}".format(self.Time, order.Type, orderEvent))
if order.Type == OrderType.Market:
stock = orderEvent.Symbol
self.Log("{0}: Setting upper and lower limits for stock {1}".format(self.Time, stock))
if order.Type == OrderType.StopMarket or order.Type == OrderType.StopLimit:
stock = orderEvent.Symbol
self.Log("{0}: Canceling all trades for stock {1}".format(self.Time, stock))
self.Transactions.CancelOpenOrders()
self.NextOrderTime = self.Time + timedelta(seconds = 10)