Hi!
I have just created a backtest that holds MSFT for a certain period. BUt I cannot see `on_data` would have ever been called.
my data is in the below format:
20260209 00:00:00,404.85001,414.89001,400.87,413.60001,45339600
20260206 00:00:00,399.17001,401.79001,392.92001,401.14001,53515300
20260205 00:00:00,407.44,408.29999,392.32001,393.67001,66289200
20260204 00:00:00,411.0,419.79999,409.23999,414.19,45012400
I cannot see any data request fails, but there are not trace of any purchase attempts.
I cannot see “"=== OnData called at {self.time} ==="” in the. is this a limitation of the free tier maybe?
The funny part is when I change `self.msft = self.add_data(TwelveDataCustom, "MSFT", Resolution.DAILY).symbol` to `self.add_equity("IBM", Resolution.DAILY)` it works fine provided I buy IBM in the on_data method.
Any help would be appreciated :)
# region imports
from AlgorithmImports import *
from datetime import datetime
# endregion
class TwelveDataCustom(PythonData):
def GetSource(self, config, date, isLiveMode):
return SubscriptionDataSource(f"{Globals.DataFolder}/custom/msft.csv", SubscriptionTransportMedium.LocalFile)
def Reader(self, config, line, date, isLiveMode):
if not (line.strip() and line[0].isdigit()):
return None
data = line.split(',')
custom = TwelveDataCustom()
custom.Symbol = config.Symbol
custom.Time = datetime.strptime(data[0], '%Y%m%d %H:%M:%S')
custom.Value = float(data[4]) # Close price
custom["Open"] = float(data[1])
custom["High"] = float(data[2])
custom["Low"] = float(data[3])
custom["Close"] = float(data[4])
custom["Volume"] = float(data[5])
return custom
class Sandbox(QCAlgorithm):
def initialize(self): # snake_case
self.set_start_date(2013, 10, 7)
self.set_end_date(2013, 10, 11)
self.set_cash(100000)
self.debug("=== INITIALIZATION STARTED ===")
self.msft = self.add_data(TwelveDataCustom, "MSFT", Resolution.DAILY).symbol
# self.add_equity("IBM", Resolution.DAILY)
self.debug("=== INITIALIZATION COMPLETE ===")
def on_data(self, data): # snake_case
self.debug(f"=== OnData called at {self.time} ===")
self.debug(f"Data.Count: {len(data)}")
if not self.portfolio.invested:
self.debug("Attempting to buy...")
self.set_holdings("MSFT", 1)
self.debug("Purchased Stock")
Balázs Koncz
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!