dear cummunity, i have a very newbie question regarding the syntax of security.high and security.low. the API define the HIGH as the recent high, how do i understand the "recent"?
say if i start loading symbol data for today and now it is 11am, then i use security.high it will return the highest price during 9:30am to 11am?
many thanks
Rahul Chowdhury
Hey Henry,
Recent high in this case refers to the high of the last bar. The length of the bar depends on the resolution you are calling at. If you are using minute data, then the recent high at 11am is the high of the 10:59 - 11:00 bar. But, if you are using hourly data, then it is the high of the 10:00- 11:00 bar.
Henry Kwek
Dear Rahal, thanks for the explanation and it is quite clear to me. However, do you know if there is a simple way to capture the market opening price and highest high since market opens? or i have to do it by tracking each bar?
many thanks
H
Rahul Chowdhury
Hi Henry,
You can get the market open price by waiting until the first non fill forwarded bar is available for the relevant symbol and storing that bar's open price in a pointer. To keep track of the highest high since market open, you can use a pointer to store the latest daily high and update it as you observe new highs. We also need to reset our daily high pointer every day at market close; we accomplish this with OnEndOfDay.
class QuantumTransdimensionalContainmentField(QCAlgorithm): def Initialize(self): self.SetStartDate(2020, 1, 5) # Set Start Date self.SetCash(100000) # Set Strategy Cash self.AddEquity("AAPL") self.openPrice = -1 # Pointer to store opening price self.highestPrice = -1 # pointer to store latest daily high def OnData(self, data): bar = data["AAPL"] if not bar.IsFillForward and self.highestPrice < 0: self.openPrice = bar.Open self.highestPrice = bar.High if self.highestPrice < 0: return price = bar.High if price > self.highestPrice: # If we observe a new high self.highestPrice = price self.Debug(f"OPEN: {self.openPrice}, HIGH: {self.highestPrice}") def OnEndOfDay(self, symbol): self.highestPrice = -1
Henry Kwek
Dear Rahul,
thanks again for your help here. i think the logic is very simple and clear. actually, i tried the following codes to capture the open price. Idea is that to set inital Opening price 0 and wait to capture the open price when the time condition is met.
However, i run into a problem where security.open returns the recent value, meaning the price of last trade of previous day, NOT THE OPEN PRICE of CURRENT day.
Is there a quick fix?
if (DateTime.Compare(processingDay, data.Time.Date ) == 0)
{
for(int i = 0; i < EquitySymbols.Length; i ++)
{
if (Decimal.Equals(OpeningPrice[i],0m) && Securities[EquitySymbols[i]].Open > 0m)
OpeningPrice[i] = Securities[EquitySymbols[i]].Open;
}
}
many thanks
H
Alexandre Catarino
Hi Henry Kwek ,
Could you please share the whole code so that we can efficiently help you?
Looking at the snippet, it seems like the check for forwarded data is missing:
var bar = data[EquitySymbols[i]]; if (!bar.IsFillForward) continue;
Henry Kwek
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!