Hi folks,

I'm currently trying to use an external csv file saved within DropBox, to trigger intraday trading. I've cut the dataset down, as well as the code, to try to identify the issues why the code is not triggering any trading activity.

The csv file contains two rows [cut down] and no headers. Col 1 = datetime to mark the minute-level stamp that attached to the trigger [set to =1] in Col2. Example = “10/0½019 ,  14:45:00” Where the comma separates the data.

I wish to use this timestamp in strftime format to trigger an intraday trade within the routine. Project attachedbut code reproduced below in case tat doesnt show. Since the csv file does contain the datestamp example above, I would expect the routine to create a link within OnData [since I have also subscribed to minutely bars]. But no such link is made and the OnData does nothing. Any ideas why this is not making the trade?

 

  1. #region imports
  2. from AlgorithmImports import *
  3. #endregion
  4. class MyAlgorithm(QCAlgorithm):
  5. def Initialize(self):
  6. self.SetStartDate(2019, 1, 9)
  7. self.SetEndDate(2019, 1, 11)
  8. self.SetCash(100000)
  9. self.snap = self.AddEquity("SNAP", Resolution.Minute).Symbol
  10. self.trade = self.AddData(TradeSignal, "trade_signal", Resolution.Minute).Symbol
  11. # self.Schedule.On(self.DateRules.EveryDay(self.snap),
  12. # self.TimeRules.BeforeMarketClose(self.snap, 15),
  13. # self.ExitPositions)
  14. def OnData(self, data):
  15. if self.trade in data:
  16. self.SetHoldings(self.snap, 1)
  17. # def ExitPositions(self):
  18. # self.Liquidate()
  19. class TradeSignal(PythonData):
  20. def GetSource(self, config, date, isLive):
  21. source = "https://www.dropbox.com/s/biu232j0ep33n9g/TickerUniverse.csv?dl=1"
  22. return SubscriptionDataSource(source, SubscriptionTransportMedium.RemoteFile);
  23. def Reader(self, config, line, date, isLive):
  24. data = line.split(',')
  25. signal = TradeSignal()
  26. try:
  27. signal.Symbol = config.Symbol
  28. signal.Time = datetime.strptime(data[0], "%d/%m/%Y %H:%M:%S")
  29. signal.Trade = data[1]
  30. except ValueError:
  31. return None
  32. return signal
+ Expand

Author

Alun Thomas

November 2022