Back

Getting current data in scheduled event

I am trying to get current price in scheduled event handler:

    def Initialize(self):

        self.Schedule.On(self.DateRules.EveryDay(), self.TimeRules.AfterMarketOpen("SPY", 30), self.Trade)

    def Trade(self):

        self.CurrentSlice[symbol].Open

The "Open" value seems to repeat the "Open" value from the previous day.

How do I get the current price here?

Update Backtest







0

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.


Hi Valery

The simplest method is to use as follows:

self.Securities[symbol].Price

You also need to make sure that when adding data you include an appropriate resolution (e.g. Resolution.Minute)

Hope this helps

0

Hi Valery,

To get "current price," as Flame has pointed out, you first need to make sure that you've asked for the data in your algorithm. You can use Resolution.Minute or Resolution.Tick based on your need and data availability.

Then, you can use self.Securities[symbol].Price to access current price. Or, you can also use self.CurrentSlice[symbol].Close which gives you the close price of last data slice pushed into your algorithm. The two methods return the same value.

I've attached a backtest. Please check out the implementation details and the logs to see how the two methods work.

0

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.


Update Backtest





0

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.


Loading...

This discussion is closed