Hi everyone
I'm very new to coding and have little to no experience with Quantconnect, but I've set myself the challenge, that I want to get good at C#.
But I'm having a lot of trouble with the History method in C#. I just can't get it to do, what I've seen people do with it in Python.
What I want to do is request the Close prices of a given timeframe to then do some calculations.
Here is what I've seen done with python
close = self.History(self.Symbol, 31, Resolution.Daily)["close"]
Please help me. I've gotten nowhere after searching the Documentation for hours.
Thanks in advance:)
Conor Flynn
Hi Bertram,
Essentially what the history method does is it returns a list of TradeBars, which you can then use to access the historical data. Typically, the way I access the bars the give is through a foreach loop. Here's an example below:
// define history variable to contain historical data // History(TICKER, PERIOD, RESOLUTION); var history = History("SPY", 10, Resolution.Daily); // loop through to utilize bar data foreach(var bar in history) { // print close values for each bar Debug("Close for SPY at " + bar.Time + ": " + bar.Close); }
Hopefully that helps :)
-Conor
Bertram Petersen
Thank you so much!
Bertram Petersen
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!