Hello. I've searched everywhere and could not find how to operate with ticks.
I'd like to know how to get current tick data (I need Ask and Bid price) called and debugged to console each time an event is triggered (each hour for example)
1) Do I need to set the resolution of my security to Tick?
2) If I set it for an hour - I will get ticks for an hour or not?
3) Should there be an event Ondata(self, slice)?
I'm sorry for too many questions but the tick topic is not covered in any tutorials or bootcamps. Just a quick walkthrough.
Ivan Baev
class QuantumResistanceRadiator(QCAlgorithm): def Initialize(self): self.SetStartDate(2019, 6, 18) # Set Start Date self.SetCash(100000) # Set Strategy Cash # self.AddEquity("SPY", Resolution.Minute) self.AddForex("USDCAD", Resolution.Tick, Market.FXCM ) def OnData(self, slice): if self.Time.Hour == 12: self.Debug("Tick ASK:"+ tick.AskPrice ) '''OnData event is the primary entry point for your algorithm. Each new data point will be pumped in here. Arguments: data: Slice object keyed by symbol containing the stock data ''' def OnOrderEvent(self, event): return # if not self.Portfolio.Invested: # self.SetHoldings("SPY", 1) def OnSecuritiesChanged(self, securities): self.SetHoldings("USDCAD", 1) self.Debug(self.Securities("USDCAD").CurrentPrice)
Ivan Baev
Okay. If anyone encounters this issue,
1) In Initialize you need to introduce a Consolidator
2) Resolution Should be tick. Your Security resolution does not have to be a tick. It can be hour or else.
self.Consolidate("USDCAD", Resolution.Tick, TickType.Trade, self.OnDataConsolidated)
3) Then in OnDataConsolidated def (Self, BAR!!!), you should assing the data to your consolidator bar
def OnDataConsolidated(self, bar): self.tickbar = bar #tickbar is any name for your bar variable return
4) Then you can access your Ask or Bid prices using the Ask.Open, Bid.Close its parameters
self.Debug(str(self.tickbar.Bid.Close))
5) Don't forget to introduce your variable before Initialize and set it to none. Also it is a good thing to check if it is not None before doing anything.
6) If you wonder what kind of data does your bar store - just debug or log your bar.
I hope it helps someone like me next time. Case closed!
Ivan Baev
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!